@@ -485,6 +485,47 @@ describe('replication-firestore.test.ts', function () {
485485 const docsOnServer = await getAllDocsOfFirestore ( firestoreState , where ( 'owner' , '==' , ownerUid ) ) ;
486486 assert . strictEqual ( docsOnServer . length , 2 ) ;
487487 } ) ;
488+ it ( '#7371 documents moving outside replication scope' , async ( ) => {
489+ const firestoreState = await getFirestoreState ( ) ;
490+ const collection = await humansCollection . create ( 0 ) ;
488491
492+ const firstDocRef =
493+ await addDoc ( firestoreState . collection , makeFirestoreHumanDocument ( schemaObjects . humanData ( 'abc' , 35 , 'replicated' ) ) ) ;
494+ await addDoc ( firestoreState . collection , makeFirestoreHumanDocument ( schemaObjects . humanData ( 'def' , 22 , 'replicated' ) ) ) ;
495+ await addDoc ( firestoreState . collection , makeFirestoreHumanDocument ( schemaObjects . humanData ( 'fgh' , 34 , 'replicated' ) ) ) ;
496+
497+ const replicationState = replicateFirestore < HumanDocumentType > ( {
498+ replicationIdentifier : firestoreState . projectId ,
499+ firestore : firestoreState as any ,
500+ collection : collection ,
501+ pull : {
502+ filter : where ( 'firstName' , '==' , 'replicated' )
503+ } ,
504+ push : { } ,
505+ live : true ,
506+ autoStart : true
507+ } ) ;
508+ ensureReplicationHasNoErrors ( replicationState ) ;
509+ await replicationState . awaitInitialReplication ( ) ;
510+
511+ let allLocalDocs = await collection . find ( ) . exec ( ) ;
512+
513+ assert . strictEqual ( allLocalDocs . length , 3 ) ;
514+
515+ /** update document to fall out of replication scope **/
516+ await updateDoc ( doc ( firestoreState . collection , firstDocRef . id ) , {
517+ firstName : 'not-replicated'
518+ } ) ;
519+
520+ await replicationState . awaitInSync ( ) ;
521+
522+ allLocalDocs = await collection . find ( ) . exec ( ) ;
523+ const docsOnServer = await getAllDocsOfFirestore ( firestoreState , where ( 'firstName' , '==' , 'replicated' ) ) ;
524+
525+ assert . strictEqual ( allLocalDocs . length , docsOnServer . length ) ;
526+
527+ collection . close ( ) ;
528+ collection . database . close ( ) ;
529+ } ) ;
489530 } ) ;
490531} ) ;
0 commit comments