-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery-client.test.ts
More file actions
81 lines (68 loc) · 3.02 KB
/
query-client.test.ts
File metadata and controls
81 lines (68 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/** biome-ignore-all lint/suspicious/noExplicitAny: any is used to allow for flexibility in the type */
import { expect, test } from 'bun:test'
import { createApi } from '@devup-api/fetch'
import { DevupQueryClient, getQueryKey } from '../query-client'
test('DevupQueryClient constructor', () => {
const api = createApi({ baseUrl: 'https://api.example.com' })
const queryClient = new DevupQueryClient(api)
expect(queryClient).toBeInstanceOf(DevupQueryClient)
})
test('DevupQueryClient useQuery method exists', () => {
const api = createApi({ baseUrl: 'https://api.example.com' })
const queryClient = new DevupQueryClient(api)
expect(typeof queryClient.useQuery).toBe('function')
})
test('DevupQueryClient useMutation method exists', () => {
const api = createApi({ baseUrl: 'https://api.example.com' })
const queryClient = new DevupQueryClient(api)
expect(typeof queryClient.useMutation).toBe('function')
})
test('DevupQueryClient useSuspenseQuery method exists', () => {
const api = createApi({ baseUrl: 'https://api.example.com' })
const queryClient = new DevupQueryClient(api)
expect(typeof queryClient.useSuspenseQuery).toBe('function')
})
test('DevupQueryClient useInfiniteQuery method exists', () => {
const api = createApi({ baseUrl: 'https://api.example.com' })
const queryClient = new DevupQueryClient(api)
expect(typeof queryClient.useInfiniteQuery).toBe('function')
})
test('DevupQueryClient useQueries method exists', () => {
const api = createApi({ baseUrl: 'https://api.example.com' })
const queryClient = new DevupQueryClient(api)
expect(typeof queryClient.useQueries).toBe('function')
})
test('getQueryKey returns correct key without options', () => {
const result = getQueryKey('get', '/test', undefined)
expect(result).toEqual(['get', '/test'])
})
test('getQueryKey returns correct key with options', () => {
const options = { params: { id: '123' } }
const result = getQueryKey('get', '/test', options)
expect(result).toEqual(['get', '/test', options])
})
test('getQueryKey handles different methods', () => {
const methods = ['get', 'post', 'put', 'delete', 'patch'] as const
for (const method of methods) {
const result = getQueryKey(method, '/test', undefined)
expect(result).toEqual([method, '/test'])
}
})
test('getQueryKey handles different paths', () => {
const paths = ['/test', '/users', '/users/{id}'] as const
for (const path of paths) {
const result = getQueryKey('get', path, undefined)
expect(result).toEqual(['get', path])
}
})
test('getQueryKey handles different option types', () => {
const options1 = { params: { id: '123' } }
const result1 = getQueryKey('get', '/test', options1)
expect(result1).toEqual(['get', '/test', options1])
const options2 = { query: { page: 1 } }
const result2 = getQueryKey('get', '/test', options2)
expect(result2).toEqual(['get', '/test', options2])
const options3 = { params: { id: '123' }, query: { page: 1 } }
const result3 = getQueryKey('get', '/test', options3)
expect(result3).toEqual(['get', '/test', options3])
})