@@ -242,6 +242,57 @@ apiDescribe('Queries', (persistence: boolean) => {
242
242
} ) ;
243
243
} ) ;
244
244
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
+
245
296
it ( 'key order is descending for descending inequality' , ( ) => {
246
297
const testDocs = {
247
298
a : {
0 commit comments