Skip to content

Commit c2504df

Browse files
Add test for ordering
1 parent e94a26d commit c2504df

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

packages/firestore/test/unit/specs/limit_spec.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ describeSpec('Limits:', [], () => {
185185
});
186186

187187
specTest(
188-
'Initial snapshots for limit queries are re-filled from cache',
188+
'Initial snapshots for limit queries are re-filled from cache (with removal)',
189189
[],
190190
() => {
191191
// Verify that views for limit queries are re-filled even if the initial
@@ -217,6 +217,38 @@ describeSpec('Limits:', [], () => {
217217
}
218218
);
219219

220+
specTest(
221+
'Initial snapshots for limit queries are re-filled from cache (with order change)',
222+
[],
223+
() => {
224+
// Verify that views for limit queries contain the correct set of documents
225+
// even if a previously matching document is updated to sort below an older
226+
// document.
227+
const fullQuery = Query.atPath(path('collection'));
228+
const limitQuery = Query.atPath(path('collection'))
229+
.addOrderBy(orderBy('pos'))
230+
.withLimit(2);
231+
const doc1 = doc('collection/a', 1001, { pos: 1 });
232+
const doc2 = doc('collection/b', 1002, { pos: 2 });
233+
const doc3 = doc('collection/c', 1003, { pos: 3 });
234+
return spec()
235+
.withGCEnabled(false)
236+
.userListens(fullQuery)
237+
.watchAcksFull(fullQuery, 1003, doc1, doc2, doc3)
238+
.expectEvents(fullQuery, { added: [doc1, doc2, doc3] })
239+
.userUnlistens(fullQuery)
240+
.userListens(limitQuery)
241+
.expectEvents(limitQuery, { added: [doc1, doc2], fromCache: true })
242+
.watchAcksFull(limitQuery, 1004, doc1, doc2)
243+
.expectEvents(limitQuery, {})
244+
.userUnlistens(limitQuery)
245+
.watchRemoves(limitQuery)
246+
.userSets('collection/a', { pos: 4 })
247+
.userListens(limitQuery, 'resume-token-1004')
248+
.expectEvents(limitQuery, { added: [doc2, doc3], fromCache: true });
249+
}
250+
);
251+
220252
specTest(
221253
'Resumed limit queries exclude deleted documents ',
222254
['durable-persistence'],

0 commit comments

Comments
 (0)