Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

cursor-pagination.test.ts

30 lines1.2 KB

1// Ordinary robustness tests for the opaque cursor pager: very large backend
2// pages and a repeated continuation cursor. The opaque cursor law (every window
3// equals the full-relation slice) is owned by cursor-pagination.oracle.test.ts.
4import { describe, expect, it } from 'vitest'
5import { createCursorPager } from './cursor-pagination/pager.js'
6​
7describe(`opaque cursor adapter`, () => {
8 it(`accepts large backend pages without spreading rows into arguments`, async () => {
9 const rows = Array.from({ length: 150_000 }, (_, id) => id)
10 const pager = createCursorPager(() =>
11 Promise.resolve({ rows, nextCursor: null }),
12 )
13 expect(await pager.read({ offset: 149_997, limit: undefined })).toEqual(
14 rows.slice(149_997),
15 )
16 expect(await pager.read({ offset: 0, limit: 2 })).toEqual(rows.slice(0, 2))
17 })
18​
19 it(`rejects a repeated opaque cursor without looping`, async () => {
20 let calls = 0
21 const pager = createCursorPager(() => {
22 calls++
23 return Promise.resolve({ rows: [], nextCursor: `same` })
24 })
25 await expect(pager.read({ offset: 0, limit: 1 })).rejects.toThrow(
26 `repeated`,
27 )
28 expect(calls).toBe(2)
29 })
30})