@@ -1216,7 +1216,8 @@ describe('testing copy object', () => {
12161216 } )
12171217 expect ( response . statusCode ) . toBe ( 200 )
12181218 expect ( S3Backend . prototype . copyObject ) . toBeCalled ( )
1219- expect ( response . body ) . toBe ( `{"Key":"bucket2/authenticated/casestudy11.png"}` )
1219+ const jsonResponse = await response . json ( )
1220+ expect ( jsonResponse . Key ) . toBe ( `bucket2/authenticated/casestudy11.png` )
12201221 } )
12211222
12221223 test ( 'can copy objects across buckets' , async ( ) => {
@@ -1235,7 +1236,9 @@ describe('testing copy object', () => {
12351236 } )
12361237 expect ( response . statusCode ) . toBe ( 200 )
12371238 expect ( S3Backend . prototype . copyObject ) . toBeCalled ( )
1238- expect ( response . body ) . toBe ( `{"Key":"bucket3/authenticated/casestudy11.png"}` )
1239+ const jsonResponse = await response . json ( )
1240+
1241+ expect ( jsonResponse . Key ) . toBe ( `bucket3/authenticated/casestudy11.png` )
12391242 } )
12401243
12411244 test ( 'can copy objects keeping their metadata' , async ( ) => {
@@ -1255,7 +1258,8 @@ describe('testing copy object', () => {
12551258 } )
12561259 expect ( response . statusCode ) . toBe ( 200 )
12571260 expect ( S3Backend . prototype . copyObject ) . toBeCalled ( )
1258- expect ( response . body ) . toBe ( `{"Key":"bucket2/authenticated/${ copiedKey } "}` )
1261+ const jsonResponse = response . json ( )
1262+ expect ( jsonResponse . Key ) . toBe ( `bucket2/authenticated/${ copiedKey } ` )
12591263
12601264 const conn = await getSuperuserPostgrestClient ( )
12611265 const object = await conn
@@ -1271,6 +1275,65 @@ describe('testing copy object', () => {
12711275 } )
12721276 } )
12731277
1278+ test ( 'can copy objects to itself overwriting their metadata' , async ( ) => {
1279+ const copiedKey = 'casestudy-2349.png'
1280+ const response = await app ( ) . inject ( {
1281+ method : 'POST' ,
1282+ url : '/object/copy' ,
1283+ headers : {
1284+ authorization : `Bearer ${ process . env . AUTHENTICATED_KEY } ` ,
1285+ 'x-upsert' : 'true' ,
1286+ 'x-metadata' : Buffer . from (
1287+ JSON . stringify ( {
1288+ newMetadata : 'test1' ,
1289+ } )
1290+ ) . toString ( 'base64' ) ,
1291+ } ,
1292+ payload : {
1293+ bucketId : 'bucket2' ,
1294+ sourceKey : `authenticated/${ copiedKey } ` ,
1295+ destinationKey : `authenticated/${ copiedKey } ` ,
1296+ metadata : {
1297+ cacheControl : 'max-age=999' ,
1298+ mimetype : 'image/gif' ,
1299+ } ,
1300+ copyMetadata : false ,
1301+ } ,
1302+ } )
1303+ expect ( response . statusCode ) . toBe ( 200 )
1304+ expect ( S3Backend . prototype . copyObject ) . toBeCalled ( )
1305+ const parsedBody = JSON . parse ( response . body )
1306+
1307+ expect ( parsedBody . Key ) . toBe ( `bucket2/authenticated/${ copiedKey } ` )
1308+ expect ( parsedBody . name ) . toBe ( `authenticated/${ copiedKey } ` )
1309+ expect ( parsedBody . bucket_id ) . toBe ( `bucket2` )
1310+ expect ( parsedBody . metadata ) . toEqual (
1311+ expect . objectContaining ( {
1312+ cacheControl : 'max-age=999' ,
1313+ mimetype : 'image/gif' ,
1314+ } )
1315+ )
1316+
1317+ const conn = await getSuperuserPostgrestClient ( )
1318+ const object = await conn
1319+ . table ( 'objects' )
1320+ . select ( '*' )
1321+ . where ( 'bucket_id' , 'bucket2' )
1322+ . where ( 'name' , `authenticated/${ copiedKey } ` )
1323+ . first ( )
1324+
1325+ expect ( object ) . not . toBeFalsy ( )
1326+ expect ( object . user_metadata ) . toEqual ( {
1327+ newMetadata : 'test1' ,
1328+ } )
1329+ expect ( object . metadata ) . toEqual (
1330+ expect . objectContaining ( {
1331+ cacheControl : 'max-age=999' ,
1332+ mimetype : 'image/gif' ,
1333+ } )
1334+ )
1335+ } )
1336+
12741337 test ( 'can copy objects excluding their metadata' , async ( ) => {
12751338 const copiedKey = 'casestudy-2450.png'
12761339 const response = await app ( ) . inject ( {
@@ -1288,7 +1351,8 @@ describe('testing copy object', () => {
12881351 } )
12891352 expect ( response . statusCode ) . toBe ( 200 )
12901353 expect ( S3Backend . prototype . copyObject ) . toBeCalled ( )
1291- expect ( response . body ) . toBe ( `{"Key":"bucket2/authenticated/${ copiedKey } "}` )
1354+ const jsonResponse = response . json ( )
1355+ expect ( jsonResponse . Key ) . toBe ( `bucket2/authenticated/${ copiedKey } ` )
12921356
12931357 const conn = await getSuperuserPostgrestClient ( )
12941358 const object = await conn
0 commit comments