Skip to content

Commit 758fbc8

Browse files
committed
Fix test code and add a new test.
1 parent aad3532 commit 758fbc8

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

packages/firestore/test/unit/local/document_overlay_cache.test.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,67 @@ function genericDocumentOverlayCacheTests(): void {
170170
it('can delete overlays repeatedly', async () => {
171171
const m = patchMutation('coll/doc1', { 'foo': 'bar' });
172172
await saveOverlaysForMutations(2, m);
173-
await overlayCache.removeOverlaysForBatchId(2);
173+
await overlayCache.removeOverlaysForBatchId(
174+
documentKeySet(key('coll/doc1')),
175+
2
176+
);
174177
expect(await overlayCache.getOverlay(key('coll/doc1'))).to.equal(null);
175178

176179
// Repeat
177-
await overlayCache.removeOverlaysForBatchId(2);
180+
await overlayCache.removeOverlaysForBatchId(
181+
documentKeySet(key('coll/doc1')),
182+
2
183+
);
178184
expect(await overlayCache.getOverlay(key('coll/doc1'))).to.equal(null);
179185
});
180186

187+
it('can delete overlays', async () => {
188+
const m1 = patchMutation('coll1/doc1', { 'a': 'b' });
189+
const m2 = patchMutation('coll1/doc2', { 'a': 'b' });
190+
const m3 = patchMutation('coll1/doc3', { 'a': 'b' });
191+
const m4 = patchMutation('coll1/doc4', { 'a': 'b' });
192+
const m5 = patchMutation('coll2/doc1/coll3/doc1', { 'a': 'b' });
193+
const m6 = patchMutation('coll2/doc2/coll3/doc2', { 'a': 'b' });
194+
await saveOverlaysForMutations(2, m1, m2);
195+
await saveOverlaysForMutations(3, m3);
196+
await saveOverlaysForMutations(4, m4);
197+
await saveOverlaysForMutations(2, m5, m6);
198+
199+
// Remove documents with batch id 2.
200+
const set1 = documentKeySet(
201+
key('coll1/doc1'),
202+
key('coll1/doc2'),
203+
key('coll2/doc1/coll3/doc1'),
204+
key('coll2/doc2/coll3/doc2')
205+
);
206+
await overlayCache.removeOverlaysForBatchId(set1, 2);
207+
expect(await overlayCache.getOverlay(key('coll1/doc1'))).to.equal(null);
208+
expect(await overlayCache.getOverlay(key('coll1/doc2'))).to.equal(null);
209+
expect(
210+
await overlayCache.getOverlay(key('coll2/doc1/coll3/doc1'))
211+
).to.equal(null);
212+
expect(
213+
await overlayCache.getOverlay(key('coll2/doc2/coll3/doc2'))
214+
).to.equal(null);
215+
expect(await overlayCache.getOverlay(key('coll1/doc3'))).to.not.equal(null);
216+
expect(await overlayCache.getOverlay(key('coll1/doc4'))).to.not.equal(null);
217+
218+
// Remove documents with batch id 3.
219+
await overlayCache.removeOverlaysForBatchId(
220+
documentKeySet(key('coll1/doc3')),
221+
3
222+
);
223+
expect(await overlayCache.getOverlay(key('coll1/doc3'))).to.equal(null);
224+
expect(await overlayCache.getOverlay(key('coll1/doc4'))).to.not.equal(null);
225+
226+
// Remove documents with batch id 4.
227+
await overlayCache.removeOverlaysForBatchId(
228+
documentKeySet(key('coll1/doc4')),
229+
4
230+
);
231+
expect(await overlayCache.getOverlay(key('coll1/doc4'))).to.equal(null);
232+
});
233+
181234
it('can get all overlays for collection', async () => {
182235
const m1 = patchMutation('coll/doc1', { 'foo': 'bar' });
183236
const m2 = setMutation('coll/doc2', { 'foo': 'bar' });

packages/firestore/test/unit/local/test_document_overlay_cache.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { DocumentOverlayCache } from '../../../src/local/document_overlay_cache';
1919
import { Persistence } from '../../../src/local/persistence';
20+
import { DocumentKeySet } from '../../../src/model/collections';
2021
import { DocumentKey } from '../../../src/model/document_key';
2122
import { Mutation } from '../../../src/model/mutation';
2223
import { Overlay } from '../../../src/model/overlay';
@@ -89,12 +90,15 @@ export class TestDocumentOverlayCache {
8990
);
9091
}
9192

92-
removeOverlaysForBatchId(batchId: number): Promise<void> {
93+
removeOverlaysForBatchId(
94+
documentKeys: DocumentKeySet,
95+
batchId: number
96+
): Promise<void> {
9397
return this.persistence.runTransaction(
9498
'removeOverlaysForBatchId',
9599
'readwrite-primary',
96100
txn => {
97-
return this.cache.removeOverlaysForBatchId(txn, batchId);
101+
return this.cache.removeOverlaysForBatchId(txn, documentKeys, batchId);
98102
}
99103
);
100104
}

0 commit comments

Comments
 (0)