@@ -251,6 +251,47 @@ describe('Webhooks', () => {
251251 )
252252 } )
253253
254+ it ( 'will emit destination bucket in ObjectCreated:Move payload for cross-bucket moves' , async ( ) => {
255+ const obj = await createObject ( pg , 'bucket6' )
256+ const destinationKey = `${ obj . name } -moved-${ randomUUID ( ) } `
257+
258+ const authorization = `Bearer ${ await serviceKeyAsync } `
259+ const response = await appInstance . inject ( {
260+ method : 'POST' ,
261+ url : `/object/move` ,
262+ headers : {
263+ authorization,
264+ } ,
265+ payload : {
266+ bucketId : 'bucket6' ,
267+ sourceKey : obj . name ,
268+ destinationBucket : 'bucket2' ,
269+ destinationKey,
270+ } ,
271+ } )
272+
273+ expect ( response . statusCode ) . toBe ( 200 )
274+ expect ( sendSpy ) . toBeCalledTimes ( 3 )
275+ expect ( sendSpy ) . toHaveBeenNthCalledWith (
276+ 3 ,
277+ expect . objectContaining ( {
278+ data : expect . objectContaining ( {
279+ event : expect . objectContaining ( {
280+ type : 'ObjectCreated:Move' ,
281+ payload : expect . objectContaining ( {
282+ bucketId : 'bucket2' ,
283+ name : destinationKey ,
284+ oldObject : expect . objectContaining ( {
285+ bucketId : 'bucket6' ,
286+ name : obj . name ,
287+ } ) ,
288+ } ) ,
289+ } ) ,
290+ } ) ,
291+ } )
292+ )
293+ } )
294+
254295 it ( 'will emit a webhook upon object copied' , async ( ) => {
255296 const obj = await createObject ( pg , 'bucket6' )
256297
@@ -310,6 +351,42 @@ describe('Webhooks', () => {
310351 } )
311352 )
312353 } )
354+
355+ it ( 'will emit destination bucket in ObjectCreated:Copy payload for cross-bucket copies' , async ( ) => {
356+ const obj = await createObject ( pg , 'bucket6' )
357+ const destinationKey = `${ obj . name } -copied-${ randomUUID ( ) } `
358+
359+ const authorization = `Bearer ${ await serviceKeyAsync } `
360+ const response = await appInstance . inject ( {
361+ method : 'POST' ,
362+ url : `/object/copy` ,
363+ headers : {
364+ authorization,
365+ } ,
366+ payload : {
367+ bucketId : 'bucket6' ,
368+ sourceKey : obj . name ,
369+ destinationBucket : 'bucket2' ,
370+ destinationKey,
371+ } ,
372+ } )
373+
374+ expect ( response . statusCode ) . toBe ( 200 )
375+ expect ( sendSpy ) . toBeCalledTimes ( 1 )
376+ expect ( sendSpy ) . toHaveBeenCalledWith (
377+ expect . objectContaining ( {
378+ data : expect . objectContaining ( {
379+ event : expect . objectContaining ( {
380+ type : 'ObjectCreated:Copy' ,
381+ payload : expect . objectContaining ( {
382+ bucketId : 'bucket2' ,
383+ name : destinationKey ,
384+ } ) ,
385+ } ) ,
386+ } ) ,
387+ } )
388+ )
389+ } )
313390} )
314391
315392async function createObject ( pg : TenantConnection , bucketId : string ) {
0 commit comments