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

backend.test.ts

54 lines2.0 KB

1/**
2 * Fixed scenarios against the real local backend: a mirror beyond its row bound
3 * rejects without publishing a partial result. The provider-boundary law and its
4 * receiving histories are owned by backend-oracle.test.ts. These fixed tests
5 * compare with written values and have no oracle owner (tracked in #2264).
6 */
7import { createCollection } from '@tanstack/db'
8import { ConvexClient } from 'convex/browser'
9import { ConvexReactClient } from 'convex/react'
10import { makeFunctionReference } from 'convex/server'
11import { describe, expect, inject, it } from 'vitest'
12import { convexPaginatedCollectionOptions } from '../src/index'
13import { withTestCleanup } from '../tests/helpers'
14import { seed } from './backend-support'
15import type { Task } from './backend-support'
16import type { PaginationOptions, PaginationResult } from 'convex/server'
17​
18const url = inject(`convexUrl`)
19​
20describe.each([`javascript`, `react`] as const)(
21 `real backend with %s client`,
22 (kind) => {
23 it(`rejects a mirror beyond its row bound without publishing a partial result`, async () => {
24 const client =
25 kind === `javascript`
26 ? new ConvexClient(url, { unsavedChangesWarning: false })
27 : new ConvexReactClient(url, { unsavedChangesWarning: false })
28 const collection = createCollection(
29 convexPaginatedCollectionOptions({
30 client,
31 query: makeFunctionReference<
32 `query`,
33 { paginationOpts: PaginationOptions },
34 PaginationResult<Task>
35 >(`tasks:list`),
36 queryArgs: {},
37 pageSize: 4,
38 maxRows: 5,
39 getKey: (task) => task.clientId,
40 gcTime: 0,
41 }),
42 )
43 await withTestCleanup(
44 async () => {
45 await client.mutation(seed, { count: 23 })
46 await expect(collection.preload()).rejects.toBeInstanceOf(RangeError)
47 expect([...collection.values()]).toEqual([])
48 },
49 () => collection.cleanup(),
50 () => client.close(),
51 )
52 })
53 },