Skip to content

Commit d073c5c

Browse files
authored
Merge ec03960 into c69c689
2 parents c69c689 + ec03960 commit d073c5c

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

packages/firestore/src/core/query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ export function queryToTarget(query: Query): Target {
315315

316316
// We need to swap the cursors to match the now-flipped query ordering.
317317
const startAt = queryImpl.endAt
318-
? new Bound(queryImpl.endAt.position, !queryImpl.endAt.inclusive)
318+
? new Bound(queryImpl.endAt.position, queryImpl.endAt.inclusive)
319319
: null;
320320
const endAt = queryImpl.startAt
321-
? new Bound(queryImpl.startAt.position, !queryImpl.startAt.inclusive)
321+
? new Bound(queryImpl.startAt.position, queryImpl.startAt.inclusive)
322322
: null;
323323

324324
// Now return as a LimitType.First query.

packages/firestore/test/integration/api/query.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,57 @@ apiDescribe('Queries', (persistence: boolean) => {
242242
});
243243
});
244244

245+
it('can issue limitToLast queries with cursors', () => {
246+
const testDocs = {
247+
a: { k: 'a', sort: 0 },
248+
b: { k: 'b', sort: 1 },
249+
c: { k: 'c', sort: 1 },
250+
d: { k: 'd', sort: 2 }
251+
};
252+
return withTestCollection(persistence, testDocs, async collection => {
253+
let docs = await getDocs(
254+
query(collection, orderBy('sort'), endBefore(2), limitToLast(3))
255+
);
256+
expect(toDataArray(docs)).to.deep.equal([
257+
{ k: 'a', sort: 0 },
258+
{ k: 'b', sort: 1 },
259+
{ k: 'c', sort: 1 }
260+
]);
261+
262+
docs = await getDocs(
263+
query(collection, orderBy('sort'), endAt(1), limitToLast(3))
264+
);
265+
expect(toDataArray(docs)).to.deep.equal([
266+
{ k: 'a', sort: 0 },
267+
{ k: 'b', sort: 1 },
268+
{ k: 'c', sort: 1 }
269+
]);
270+
271+
docs = await getDocs(
272+
query(collection, orderBy('sort'), startAt(2), limitToLast(3))
273+
);
274+
expect(toDataArray(docs)).to.deep.equal([{ k: 'd', sort: 2 }]);
275+
276+
docs = await getDocs(
277+
query(collection, orderBy('sort'), startAfter(0), limitToLast(3))
278+
);
279+
expect(toDataArray(docs)).to.deep.equal([
280+
{ k: 'b', sort: 1 },
281+
{ k: 'c', sort: 1 },
282+
{ k: 'd', sort: 2 }
283+
]);
284+
285+
docs = await getDocs(
286+
query(collection, orderBy('sort'), startAfter(-1), limitToLast(3))
287+
);
288+
expect(toDataArray(docs)).to.deep.equal([
289+
{ k: 'b', sort: 1 },
290+
{ k: 'c', sort: 1 },
291+
{ k: 'd', sort: 2 }
292+
]);
293+
});
294+
});
295+
245296
it('key order is descending for descending inequality', () => {
246297
const testDocs = {
247298
a: {

0 commit comments

Comments
 (0)