@@ -402,4 +402,61 @@ bucket_definitions:
402402
403403 expect ( data ) . toMatchObject ( [ ] ) ;
404404 } ) ;
405+
406+ test ( 'postImages - new collection with postImages enabled' , async ( ) => {
407+ await using context = await ChangeStreamTestContext . open ( factory , { postImages : 'autoConfigure' } ) ;
408+ const { db } = context ;
409+ await context . updateSyncRules ( `
410+ bucket_definitions:
411+ global:
412+ data:
413+ - SELECT _id as id, description FROM "test_%"` ) ;
414+
415+ await context . replicateSnapshot ( ) ;
416+
417+ await db . createCollection ( 'test_data' , {
418+ // enabled: true here - everything should work
419+ changeStreamPreAndPostImages : { enabled : true }
420+ } ) ;
421+ const collection = db . collection ( 'test_data' ) ;
422+ const result = await collection . insertOne ( { description : 'test1' } ) ;
423+ const test_id = result . insertedId ;
424+ await collection . updateOne ( { _id : test_id } , { $set : { description : 'test2' } } ) ;
425+
426+ context . startStreaming ( ) ;
427+
428+ const data = await context . getBucketData ( 'global[]' ) ;
429+ expect ( data ) . toMatchObject ( [
430+ putOp ( 'test_data' , { id : test_id ! . toHexString ( ) , description : 'test1' } ) ,
431+ putOp ( 'test_data' , { id : test_id ! . toHexString ( ) , description : 'test2' } )
432+ ] ) ;
433+ } ) ;
434+
435+ test . only ( 'postImages - new collection with postImages disabled' , async ( ) => {
436+ await using context = await ChangeStreamTestContext . open ( factory , { postImages : 'autoConfigure' } ) ;
437+ const { db } = context ;
438+ await context . updateSyncRules ( `
439+ bucket_definitions:
440+ global:
441+ data:
442+ - SELECT _id as id, description FROM "test_data%"` ) ;
443+
444+ await context . replicateSnapshot ( ) ;
445+
446+ await db . createCollection ( 'test_data' , {
447+ // enabled: false here, but autoConfigure will enable it.
448+ // Unfortunately, that is too late, and replication must be restarted.
449+ changeStreamPreAndPostImages : { enabled : false }
450+ } ) ;
451+ const collection = db . collection ( 'test_data' ) ;
452+ const result = await collection . insertOne ( { description : 'test1' } ) ;
453+ const test_id = result . insertedId ;
454+ await collection . updateOne ( { _id : test_id } , { $set : { description : 'test2' } } ) ;
455+
456+ context . startStreaming ( ) ;
457+
458+ await expect ( ( ) => context . getBucketData ( 'global[]' ) ) . rejects . toMatchObject ( {
459+ message : expect . stringContaining ( 'stream was configured to require a post-image for all update events' )
460+ } ) ;
461+ } ) ;
405462}
0 commit comments