-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration for react-query and swr
- Loading branch information
1 parent
edb39a6
commit f3501d7
Showing
4 changed files
with
130 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {jest} from '@jest/globals' | ||
import createReactQuery from 'openapi-react-query' | ||
import {createQueryHook} from 'swr-openapi' | ||
import initOpenIntSDK from './index.js' | ||
|
||
jest.setTimeout(70 * 15 * 1000) // In case of cold start | ||
|
||
const openint = initOpenIntSDK({headers: {}}) | ||
|
||
test('healthcheck with default init', async () => { | ||
expect(await openint['/health'].GET().then((r) => r.data)).toBeTruthy() | ||
expect(await openint.GET('/health').then((r) => r.data)).toBeTruthy() | ||
}) | ||
|
||
test('openapi-react-query integration works', () => { | ||
const $api = createReactQuery(openint.fetchClient) | ||
|
||
const MyComponent = () => { | ||
const {data, error, isLoading} = $api.useQuery( | ||
'get', | ||
'/core/connection/{id}', | ||
{params: {path: {id: 'my-connection-id'}}}, | ||
) | ||
|
||
if (isLoading || !data) return 'Loading...' | ||
|
||
if (error) return `An error occured: ${error.message}` | ||
|
||
return data.displayName | ||
} | ||
|
||
expect(MyComponent).toBeTruthy() | ||
}) | ||
|
||
test('swr-openapi integration does not work yet', () => { | ||
const useQuery = createQueryHook(openint.fetchClient, 'openint-api') | ||
|
||
const MyComponent = () => { | ||
const {data, error, isLoading} = useQuery('/core/connection/{id}') | ||
|
||
if (isLoading || !data) return 'Loading...' | ||
|
||
if (error) return `An error occured: ${error}` | ||
|
||
// @ts-expect-error | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return data.displayName | ||
} | ||
|
||
expect(MyComponent).toBeTruthy() | ||
}) |