|
| 1 | +/** biome-ignore-all lint/suspicious/noExplicitAny: any is used to allow for flexibility in the type */ |
| 2 | +import { expect, test } from 'bun:test' |
| 3 | +import { createApi } from '@devup-api/fetch' |
| 4 | +import { createQueryClient } from '../create-query-client' |
| 5 | +import { DevupQueryClient } from '../query-client' |
| 6 | + |
| 7 | +test.each([ |
| 8 | + ['https://api.example.com'], |
| 9 | + ['https://api.example.com/'], |
| 10 | + ['http://localhost:3000'], |
| 11 | + ['http://localhost:3000/'], |
| 12 | +] as const)('createQueryClient returns DevupQueryClient instance: %s', (baseUrl) => { |
| 13 | + const api = createApi({ baseUrl }) |
| 14 | + const queryClient = createQueryClient(api) |
| 15 | + expect(queryClient).toBeInstanceOf(DevupQueryClient) |
| 16 | +}) |
| 17 | + |
| 18 | +test.each([ |
| 19 | + ['https://api.example.com', undefined], |
| 20 | + ['https://api.example.com', {}], |
| 21 | + ['https://api.example.com', { headers: { Authorization: 'Bearer token' } }], |
| 22 | +] as const)('createQueryClient accepts api with defaultOptions: %s', (baseUrl, defaultOptions) => { |
| 23 | + const api = createApi({ baseUrl, ...defaultOptions }) |
| 24 | + const queryClient = createQueryClient(api) |
| 25 | + expect(queryClient).toBeInstanceOf(DevupQueryClient) |
| 26 | +}) |
| 27 | + |
| 28 | +test.each([ |
| 29 | + ['openapi.json'], |
| 30 | + ['openapi2.json'], |
| 31 | +] as const)('createQueryClient accepts api with serverName: %s', (serverName) => { |
| 32 | + const api = createApi({ |
| 33 | + baseUrl: 'https://api.example.com', |
| 34 | + serverName: serverName as any, |
| 35 | + }) |
| 36 | + const queryClient = createQueryClient(api) |
| 37 | + expect(queryClient).toBeInstanceOf(DevupQueryClient) |
| 38 | +}) |
| 39 | + |
| 40 | +test('createQueryClient uses default serverName when not provided', () => { |
| 41 | + const api = createApi({ baseUrl: 'https://api.example.com' }) |
| 42 | + const queryClient = createQueryClient(api) |
| 43 | + expect(queryClient).toBeInstanceOf(DevupQueryClient) |
| 44 | +}) |
| 45 | + |
| 46 | +test('createQueryClient uses empty baseUrl when not provided', () => { |
| 47 | + const api = createApi({}) |
| 48 | + const queryClient = createQueryClient(api) |
| 49 | + expect(queryClient).toBeInstanceOf(DevupQueryClient) |
| 50 | +}) |
0 commit comments