@@ -1216,7 +1216,8 @@ describe('testing copy object', () => {
1216
1216
} )
1217
1217
expect ( response . statusCode ) . toBe ( 200 )
1218
1218
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` )
1220
1221
} )
1221
1222
1222
1223
test ( 'can copy objects across buckets' , async ( ) => {
@@ -1235,7 +1236,9 @@ describe('testing copy object', () => {
1235
1236
} )
1236
1237
expect ( response . statusCode ) . toBe ( 200 )
1237
1238
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` )
1239
1242
} )
1240
1243
1241
1244
test ( 'can copy objects keeping their metadata' , async ( ) => {
@@ -1255,7 +1258,8 @@ describe('testing copy object', () => {
1255
1258
} )
1256
1259
expect ( response . statusCode ) . toBe ( 200 )
1257
1260
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 } ` )
1259
1263
1260
1264
const conn = await getSuperuserPostgrestClient ( )
1261
1265
const object = await conn
@@ -1271,6 +1275,65 @@ describe('testing copy object', () => {
1271
1275
} )
1272
1276
} )
1273
1277
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
+
1274
1337
test ( 'can copy objects excluding their metadata' , async ( ) => {
1275
1338
const copiedKey = 'casestudy-2450.png'
1276
1339
const response = await app ( ) . inject ( {
@@ -1288,7 +1351,8 @@ describe('testing copy object', () => {
1288
1351
} )
1289
1352
expect ( response . statusCode ) . toBe ( 200 )
1290
1353
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 } ` )
1292
1356
1293
1357
const conn = await getSuperuserPostgrestClient ( )
1294
1358
const object = await conn
0 commit comments