Skip to content

Commit fc6836b

Browse files
committed
Update LocalStore tests.
1 parent c05b58c commit fc6836b

File tree

1 file changed

+74
-56
lines changed

1 file changed

+74
-56
lines changed

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

Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,19 @@ class LocalStoreTester {
241241

242242
afterAcknowledgingMutation(options: {
243243
documentVersion: TestSnapshotVersion;
244-
transformResult?: api.Value;
244+
transformResults?: api.Value[];
245245
}): LocalStoreTester {
246246
this.prepareNextStep();
247247

248248
this.promiseChain = this.promiseChain
249249
.then(() => {
250250
const batch = this.batches.shift()!;
251-
expect(batch.mutations.length).to.equal(
252-
1,
253-
'Acknowledging more than one mutation not supported.'
254-
);
255251
const ver = version(options.documentVersion);
256-
const mutationResults = [
257-
new MutationResult(
258-
ver,
259-
options.transformResult ? [options.transformResult] : []
260-
)
261-
];
252+
const mutationResults = options.transformResults
253+
? options.transformResults.map(
254+
value => new MutationResult(ver, [value])
255+
)
256+
: [new MutationResult(ver, [])];
262257
const write = MutationBatchResult.from(batch, ver, mutationResults);
263258

264259
return localStoreAcknowledgeBatch(this.localStore, write);
@@ -801,7 +796,7 @@ function genericLocalStoreTests(
801796
return expectLocalStore()
802797
.after(deleteMutation('foo/bar'))
803798
.toReturnRemoved('foo/bar')
804-
.toContain(deletedDoc('foo/bar', 0))
799+
.toContain(deletedDoc('foo/bar', 0).setHasLocalMutations())
805800
.afterAcknowledgingMutation({ documentVersion: 1 })
806801
.toReturnRemoved('foo/bar')
807802
.toNotContainIfEager(deletedDoc('foo/bar', 1).setHasCommittedMutations())
@@ -819,7 +814,7 @@ function genericLocalStoreTests(
819814
.toContain(doc('foo/bar', 1, { it: 'base' }))
820815
.after(deleteMutation('foo/bar'))
821816
.toReturnRemoved('foo/bar')
822-
.toContain(deletedDoc('foo/bar', 0))
817+
.toContain(deletedDoc('foo/bar', 0).setHasLocalMutations())
823818
// remove the mutation so only the mutation is pinning the doc
824819
.afterReleasingTarget(2)
825820
.afterAcknowledgingMutation({ documentVersion: 2 })
@@ -839,10 +834,10 @@ function genericLocalStoreTests(
839834
.toReturnTargetId(2)
840835
.after(deleteMutation('foo/bar'))
841836
.toReturnRemoved('foo/bar')
842-
.toContain(deletedDoc('foo/bar', 0))
837+
.toContain(deletedDoc('foo/bar', 0).setHasLocalMutations())
843838
.after(docUpdateRemoteEvent(doc('foo/bar', 1, { it: 'base' }), [2]))
844839
.toReturnRemoved('foo/bar')
845-
.toContain(deletedDoc('foo/bar', 0))
840+
.toContain(deletedDoc('foo/bar', 0).setHasLocalMutations())
846841
// Don't need to keep doc pinned anymore
847842
.afterReleasingTarget(2)
848843
.afterAcknowledgingMutation({ documentVersion: 2 })
@@ -948,10 +943,10 @@ function genericLocalStoreTests(
948943
return expectLocalStore()
949944
.after(deleteMutation('foo/bar'))
950945
.toReturnRemoved('foo/bar')
951-
.toContain(deletedDoc('foo/bar', 0))
946+
.toContain(deletedDoc('foo/bar', 0).setHasLocalMutations())
952947
.after(patchMutation('foo/bar', { foo: 'bar' }))
953948
.toReturnRemoved('foo/bar')
954-
.toContain(deletedDoc('foo/bar', 0))
949+
.toContain(deletedDoc('foo/bar', 0).setHasLocalMutations())
955950
.afterAcknowledgingMutation({ documentVersion: 2 }) // delete mutation
956951
.toReturnRemoved('foo/bar')
957952
.toContain(deletedDoc('foo/bar', 2).setHasCommittedMutations())
@@ -1007,15 +1002,15 @@ function genericLocalStoreTests(
10071002
.after(deleteMutation('foo/baz'))
10081003
.toContain(doc('foo/bar', 1, { foo: 'bar' }).setHasLocalMutations())
10091004
.toContain(doc('foo/bah', 0, { foo: 'bah' }).setHasLocalMutations())
1010-
.toContain(deletedDoc('foo/baz', 0))
1005+
.toContain(deletedDoc('foo/baz', 0).setHasLocalMutations())
10111006
.afterAcknowledgingMutation({ documentVersion: 3 })
10121007
.toNotContain('foo/bar')
10131008
.toContain(doc('foo/bah', 0, { foo: 'bah' }).setHasLocalMutations())
1014-
.toContain(deletedDoc('foo/baz', 0))
1009+
.toContain(deletedDoc('foo/baz', 0).setHasLocalMutations())
10151010
.afterAcknowledgingMutation({ documentVersion: 4 })
10161011
.toNotContain('foo/bar')
10171012
.toNotContain('foo/bah')
1018-
.toContain(deletedDoc('foo/baz', 0))
1013+
.toContain(deletedDoc('foo/baz', 0).setHasLocalMutations())
10191014
.afterAcknowledgingMutation({ documentVersion: 5 })
10201015
.toNotContain('foo/bar')
10211016
.toNotContain('foo/bah')
@@ -1041,15 +1036,15 @@ function genericLocalStoreTests(
10411036
.after(deleteMutation('foo/baz'))
10421037
.toContain(doc('foo/bar', 1, { foo: 'bar' }).setHasLocalMutations())
10431038
.toContain(doc('foo/bah', 0, { foo: 'bah' }).setHasLocalMutations())
1044-
.toContain(deletedDoc('foo/baz', 0))
1039+
.toContain(deletedDoc('foo/baz', 0).setHasLocalMutations())
10451040
.afterRejectingMutation() // patch mutation
10461041
.toNotContain('foo/bar')
10471042
.toContain(doc('foo/bah', 0, { foo: 'bah' }).setHasLocalMutations())
1048-
.toContain(deletedDoc('foo/baz', 0))
1043+
.toContain(deletedDoc('foo/baz', 0).setHasLocalMutations())
10491044
.afterRejectingMutation() // set mutation
10501045
.toNotContain('foo/bar')
10511046
.toNotContain('foo/bah')
1052-
.toContain(deletedDoc('foo/baz', 0))
1047+
.toContain(deletedDoc('foo/baz', 0).setHasLocalMutations())
10531048
.afterRejectingMutation() // delete mutation
10541049
.toNotContain('foo/bar')
10551050
.toNotContain('foo/bah')
@@ -1181,36 +1176,40 @@ function genericLocalStoreTests(
11811176
const firstQuery = query('foo');
11821177
const secondQuery = query('foo', filter('matches', '==', true));
11831178

1184-
return expectLocalStore()
1185-
.afterAllocatingQuery(firstQuery)
1186-
.toReturnTargetId(2)
1187-
.after(
1188-
docAddedRemoteEvent(
1189-
[
1190-
doc('foo/bar', 10, { matches: true }),
1191-
doc('foo/baz', 20, { matches: true })
1192-
],
1193-
[2]
1179+
return (
1180+
expectLocalStore()
1181+
.afterAllocatingQuery(firstQuery)
1182+
.toReturnTargetId(2)
1183+
.after(
1184+
docAddedRemoteEvent(
1185+
[
1186+
doc('foo/bar', 10, { matches: true }),
1187+
doc('foo/baz', 20, { matches: true })
1188+
],
1189+
[2]
1190+
)
11941191
)
1195-
)
1196-
.toReturnChanged(
1197-
doc('foo/bar', 10, { matches: true }),
1198-
doc('foo/baz', 20, { matches: true })
1199-
)
1200-
.after(setMutation('foo/bonk', { matches: true }))
1201-
.toReturnChanged(
1202-
doc('foo/bonk', 0, { matches: true }).setHasLocalMutations()
1203-
)
1204-
.afterAllocatingQuery(secondQuery)
1205-
.toReturnTargetId(4)
1206-
.afterExecutingQuery(secondQuery)
1207-
.toReturnChanged(
1208-
doc('foo/bar', 10, { matches: true }),
1209-
doc('foo/baz', 20, { matches: true }),
1210-
doc('foo/bonk', 0, { matches: true }).setHasLocalMutations()
1211-
)
1212-
.toHaveRead({ documentsByCollection: 2, mutationsByCollection: 1 })
1213-
.finish();
1192+
.toReturnChanged(
1193+
doc('foo/bar', 10, { matches: true }),
1194+
doc('foo/baz', 20, { matches: true })
1195+
)
1196+
.after(setMutation('foo/bonk', { matches: true }))
1197+
.toReturnChanged(
1198+
doc('foo/bonk', 0, { matches: true }).setHasLocalMutations()
1199+
)
1200+
.afterAllocatingQuery(secondQuery)
1201+
.toReturnTargetId(4)
1202+
.afterExecutingQuery(secondQuery)
1203+
.toReturnChanged(
1204+
doc('foo/bar', 10, { matches: true }),
1205+
doc('foo/baz', 20, { matches: true }),
1206+
doc('foo/bonk', 0, { matches: true }).setHasLocalMutations()
1207+
)
1208+
// TODO(overlays): implement overlaysReadByKey and overlaysReadByCollection
1209+
// No mutations are read because only overlay is needed.
1210+
.toHaveRead({ documentsByCollection: 2, mutationsByCollection: 0 })
1211+
.finish()
1212+
);
12141213
});
12151214

12161215
// eslint-disable-next-line no-restricted-properties
@@ -1340,7 +1339,7 @@ function genericLocalStoreTests(
13401339
.toContain(doc('foo/bar', 1, { sum: 1 }).setHasLocalMutations())
13411340
.afterAcknowledgingMutation({
13421341
documentVersion: 2,
1343-
transformResult: { integerValue: 1 }
1342+
transformResults: [{ integerValue: 1 }]
13441343
})
13451344
.toReturnChanged(
13461345
doc('foo/bar', 2, { sum: 1 }).setHasCommittedMutations()
@@ -1385,13 +1384,13 @@ function genericLocalStoreTests(
13851384
.toContain(doc('foo/bar', 2, { sum: 3 }).setHasLocalMutations())
13861385
.afterAcknowledgingMutation({
13871386
documentVersion: 3,
1388-
transformResult: { integerValue: 1 }
1387+
transformResults: [{ integerValue: 1 }]
13891388
})
13901389
.toReturnChanged(doc('foo/bar', 3, { sum: 3 }).setHasLocalMutations())
13911390
.toContain(doc('foo/bar', 3, { sum: 3 }).setHasLocalMutations())
13921391
.afterAcknowledgingMutation({
13931392
documentVersion: 4,
1394-
transformResult: { integerValue: 1339 }
1393+
transformResults: [{ integerValue: 1339 }]
13951394
})
13961395
.toReturnChanged(
13971396
doc('foo/bar', 4, { sum: 1339 }).setHasCommittedMutations()
@@ -1452,9 +1451,28 @@ function genericLocalStoreTests(
14521451
.toReturnChanged(
14531452
doc('foo/bar', 2, {
14541453
sum: 1,
1455-
arrayUnion: ['bar', 'foo']
1454+
arrayUnion: ['foo']
14561455
}).setHasLocalMutations()
14571456
)
1457+
.afterAcknowledgingMutation({
1458+
documentVersion: 3,
1459+
transformResults: [
1460+
{ integerValue: 1338 },
1461+
{
1462+
arrayValue: {
1463+
values: [{ stringValue: 'bar' }, { stringValue: 'foo' }]
1464+
}
1465+
}
1466+
]
1467+
})
1468+
.toReturnChanged(
1469+
doc('foo/bar', 3, {
1470+
sum: 1338,
1471+
arrayUnion: ['bar', 'foo']
1472+
})
1473+
.setReadTime(SnapshotVersion.fromTimestamp(new Timestamp(0, 3000)))
1474+
.setHasCommittedMutations()
1475+
)
14581476
.finish()
14591477
);
14601478
});

0 commit comments

Comments
 (0)