Skip to content

Commit 1723723

Browse files
committed
address feedback and add missing tests.
1 parent 4f728b0 commit 1723723

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

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

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ function genericLocalStoreTests(
13981398
);
13991399
});
14001400

1401-
it('holds back only non-idempotent transforms', () => {
1401+
it('holds back transforms', () => {
14021402
const query1 = query('foo');
14031403
return (
14041404
expectLocalStore()
@@ -1439,9 +1439,8 @@ function genericLocalStoreTests(
14391439
arrayUnion: ['foo']
14401440
}).setHasLocalMutations()
14411441
)
1442-
// The sum transform is not idempotent and the backend's updated value
1443-
// is ignored. The ArrayUnion transform is recomputed and includes the
1444-
// backend value.
1442+
// The sum transform and array union transform make the SDK ignore the
1443+
// backend's updated value.
14451444
.afterRemoteEvent(
14461445
docUpdateRemoteEvent(
14471446
doc('foo/bar', 2, { sum: 1337, arrayUnion: ['bar'] }),
@@ -1454,6 +1453,8 @@ function genericLocalStoreTests(
14541453
arrayUnion: ['foo']
14551454
}).setHasLocalMutations()
14561455
)
1456+
// With a field transform acknowledgement, the overlay is recalculated
1457+
// with the remaining local mutations.
14571458
.afterAcknowledgingMutation({
14581459
documentVersion: 3,
14591460
transformResults: [{ integerValue: 1338 }]
@@ -1890,6 +1891,73 @@ function genericLocalStoreTests(
18901891
.finish();
18911892
});
18921893

1894+
it('can handle multiple field patches in one batch on remote docs', () => {
1895+
const query1 = query('foo');
1896+
return expectLocalStore()
1897+
.afterAllocatingQuery(query1)
1898+
.toReturnTargetId(2)
1899+
.afterRemoteEvent(
1900+
docAddedRemoteEvent(
1901+
[doc('foo/bar', 1, { 'likes': 0, 'stars': 0 })],
1902+
[2],
1903+
[]
1904+
)
1905+
)
1906+
.toReturnChanged(doc('foo/bar', 1, { 'likes': 0, 'stars': 0 }))
1907+
.toContain(doc('foo/bar', 1, { 'likes': 0, 'stars': 0 }))
1908+
.afterMutations([
1909+
patchMutation('foo/bar', { 'likes': 1 }),
1910+
patchMutation('foo/bar', { 'stars': 1 })
1911+
])
1912+
.toReturnChanged(
1913+
doc('foo/bar', 1, { 'likes': 1, 'stars': 1 }).setHasLocalMutations()
1914+
)
1915+
.toContain(
1916+
doc('foo/bar', 1, { 'likes': 1, 'stars': 1 }).setHasLocalMutations()
1917+
)
1918+
.after(patchMutation('foo/bar', { 'stars': 2 }))
1919+
.toReturnChanged(
1920+
doc('foo/bar', 1, { 'likes': 1, 'stars': 2 }).setHasLocalMutations()
1921+
)
1922+
.toContain(
1923+
doc('foo/bar', 1, { 'likes': 1, 'stars': 2 }).setHasLocalMutations()
1924+
)
1925+
.finish();
1926+
});
1927+
1928+
it('can handle multiple field patches on local docs', () => {
1929+
return expectLocalStore()
1930+
.after(setMutation('foo/bar', { 'likes': 0, 'stars': 0 }))
1931+
.toReturnChanged(
1932+
doc('foo/bar', 1, { 'likes': 0, 'stars': 0 }).setHasLocalMutations()
1933+
)
1934+
.toContain(
1935+
doc('foo/bar', 1, { 'likes': 0, 'stars': 0 }).setHasLocalMutations()
1936+
)
1937+
.after(patchMutation('foo/bar', { 'likes': 1 }))
1938+
.toReturnChanged(
1939+
doc('foo/bar', 1, { 'likes': 1, 'stars': 0 }).setHasLocalMutations()
1940+
)
1941+
.toContain(
1942+
doc('foo/bar', 1, { 'likes': 1, 'stars': 0 }).setHasLocalMutations()
1943+
)
1944+
.after(patchMutation('foo/bar', { 'stars': 1 }))
1945+
.toReturnChanged(
1946+
doc('foo/bar', 1, { 'likes': 1, 'stars': 1 }).setHasLocalMutations()
1947+
)
1948+
.toContain(
1949+
doc('foo/bar', 1, { 'likes': 1, 'stars': 1 }).setHasLocalMutations()
1950+
)
1951+
.after(patchMutation('foo/bar', { 'stars': 2 }))
1952+
.toReturnChanged(
1953+
doc('foo/bar', 1, { 'likes': 1, 'stars': 2 }).setHasLocalMutations()
1954+
)
1955+
.toContain(
1956+
doc('foo/bar', 1, { 'likes': 1, 'stars': 2 }).setHasLocalMutations()
1957+
)
1958+
.finish();
1959+
});
1960+
18931961
it('uses target mapping to execute queries', () => {
18941962
if (gcIsEager) {
18951963
return;

0 commit comments

Comments
 (0)