Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion test/replication-firestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ import {
orderBy,
limit,
getDoc,
QueryConstraint
QueryConstraint,
addDoc,
updateDoc
} from 'firebase/firestore';
import {
FirestoreOptions,
Expand Down Expand Up @@ -485,6 +487,47 @@ describe('replication-firestore.test.ts', function () {
const docsOnServer = await getAllDocsOfFirestore(firestoreState, where('owner', '==', ownerUid));
assert.strictEqual(docsOnServer.length, 2);
});
it('#7371 documents moving outside replication scope', async () => {
const firestoreState = await getFirestoreState();
const collection = await humansCollection.create(0);

const firstDocRef =
await addDoc(firestoreState.collection, makeFirestoreHumanDocument(schemaObjects.humanData('abc', 35, 'replicated')));
await addDoc(firestoreState.collection, makeFirestoreHumanDocument(schemaObjects.humanData('def', 22, 'replicated')));
await addDoc(firestoreState.collection, makeFirestoreHumanDocument(schemaObjects.humanData('fgh', 34, 'replicated')));

const replicationState = replicateFirestore<HumanDocumentType>({
replicationIdentifier: firestoreState.projectId,
firestore: firestoreState as any,
collection: collection,
pull: {
filter: where('firstName', '==', 'replicated')
},
push: {},
live: true,
autoStart: true
});
ensureReplicationHasNoErrors(replicationState);
await replicationState.awaitInitialReplication();

let allLocalDocs = await collection.find().exec();

assert.strictEqual(allLocalDocs.length, 3);

/** update document to fall out of replication scope **/
await updateDoc(DocRef(firestoreState.collection, firstDocRef.id), {
firstName: 'not-replicated'
});

await replicationState.awaitInSync();

allLocalDocs = await collection.find().exec();
const docsOnServer = await getAllDocsOfFirestore(firestoreState, where('firstName', '==', 'replicated'));

assert.strictEqual(allLocalDocs.length, docsOnServer.length);

collection.close();
collection.database.close();
});
});
});
Loading