-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
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 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,56 @@ | ||
import React from 'react'; | ||
import { createAPIMockingUtility } from '@lifeomic/one-query/test-utils'; | ||
import { setupServer } from 'msw/node'; | ||
import { renderHook } from '@testing-library/react-native'; | ||
import { QueryClientProvider, QueryClient } from '@tanstack/react-query'; | ||
import { useAppsAPIMutation } from './apps-api'; | ||
import { AppsAPIEndpoints } from '../types/apps-rest-types'; | ||
|
||
const server = setupServer(); | ||
server.listen({ onUnhandledRequest: 'error' }); | ||
|
||
const adoptAppsAPIMocking = createAPIMockingUtility<AppsAPIEndpoints>({ | ||
server, | ||
baseUrl: 'https://apps.us.lifeomic.com', | ||
}); | ||
|
||
const renderHookInContext = () => { | ||
return renderHook(() => useAppsAPIMutation('POST /auth/v1/api/signup'), { | ||
wrapper: ({ children }) => ( | ||
<QueryClientProvider client={new QueryClient()}> | ||
{children} | ||
</QueryClientProvider> | ||
), | ||
}); | ||
}; | ||
|
||
const api = adoptAppsAPIMocking(); | ||
|
||
test('makes mutation request', async () => { | ||
const credentials = { | ||
userConfirmed: true, | ||
tokenType: 'Bearer', | ||
accessToken: 'access-token', | ||
identityToken: 'identity-token', | ||
refreshToken: 'refresh-token', | ||
expiresIn: 3600, | ||
originalUrl: 'myapp://evc-signup', | ||
} as const; | ||
|
||
api.mock('POST /auth/v1/api/signup', { | ||
status: 200, | ||
data: credentials, | ||
}); | ||
|
||
const { result } = renderHookInContext(); | ||
|
||
const response = await result.current.mutateAsync({ | ||
evc: 'evc-code', | ||
inviteId: 'invite-id', | ||
originalUrl: 'myapp://evc-signup', | ||
clientId: 'client-id', | ||
email: 'bat.man@thecave.com', | ||
}); | ||
|
||
expect(response).toEqual(credentials); | ||
}); |
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,20 @@ | ||
import { createAPIHooks } from '@lifeomic/one-query'; | ||
import axios from 'axios'; | ||
|
||
import { AppsAPIEndpoints } from '../types/apps-rest-types'; | ||
import { useDeveloperConfig } from './useDeveloperConfig'; | ||
|
||
export const defaultBaseURL = 'https://apps.us.lifeomic.com'; | ||
|
||
const hooks = createAPIHooks<AppsAPIEndpoints>({ | ||
name: 'lifeomic-apps-react-native-sdk', | ||
client: () => { | ||
// hook will be used according to rules of hooks | ||
// https://github.com/lifeomic/one-query?tab=readme-ov-file#createapihooks | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const { appsAPIBaseURL = defaultBaseURL } = useDeveloperConfig(); | ||
return axios.create({ baseURL: appsAPIBaseURL }); | ||
}, | ||
}); | ||
|
||
export const useAppsAPIMutation = hooks.useAPIMutation; |
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,50 @@ | ||
/** | ||
* While performing authorization through an external user-agent (browser) | ||
* is recommended and the only way to be OAuth 2.0 compliant, there are | ||
* publicly available endpoints that can be used to build a fully native | ||
* experience. | ||
*/ | ||
export type AppsAPIEndpoints = { | ||
'POST /auth/v1/api/invite-validations': { | ||
Request: { | ||
inviteId: string; | ||
evc: string; | ||
}; | ||
Response: { | ||
userState: { | ||
isExistingUser: boolean; | ||
}; | ||
invitation: { | ||
email: string; | ||
group: string; | ||
project: string; | ||
}; | ||
}; | ||
}; | ||
'POST /auth/v1/api/signup': { | ||
Request: { | ||
clientId: string; | ||
email: string; | ||
/** | ||
* evc, originalUrl, inviteId are not technically required, but it | ||
* is the only way we currently support signup through POST /signup | ||
*/ | ||
originalUrl: string; | ||
evc: string; | ||
inviteId: string; | ||
}; | ||
Response: | ||
| { | ||
userConfirmed?: false; | ||
} | ||
| { | ||
userConfirmed: true; | ||
accessToken: string; | ||
refreshToken: string; | ||
identityToken: string; | ||
expiresIn: number; | ||
tokenType: 'Bearer'; | ||
originalUrl: string; | ||
}; | ||
}; | ||
}; |