-
Notifications
You must be signed in to change notification settings - Fork 6
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
2 changed files
with
69 additions
and
27 deletions.
There are no files selected for viewing
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,69 @@ | ||
import keycloak from '@src/utils/keycloak'; | ||
import { act, renderHook } from '@testing-library/react'; | ||
import { AuthProvider } from 'react-oidc-context'; | ||
import { RecoilRoot } from 'recoil'; | ||
import useAuth from './use-auth'; | ||
|
||
interface ContextWrapperProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
describe('useAuth', () => { | ||
const OLD_ENV = process.env; | ||
beforeEach(() => { | ||
process.env = { ...OLD_ENV }; | ||
}); | ||
|
||
const contextWrapper = ({ children }: ContextWrapperProps) => ( | ||
<AuthProvider {...keycloak}> | ||
<RecoilRoot>{children}</RecoilRoot> | ||
</AuthProvider> | ||
); | ||
|
||
test('should call signIn successfully', () => { | ||
const { result } = renderHook(() => useAuth(), { | ||
wrapper: contextWrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.signIn(false); | ||
}); | ||
expect(result.current.signIn).toBeTruthy(); | ||
}); | ||
|
||
test('should call signIn with SSO and no configs', () => { | ||
const { result } = renderHook(() => useAuth(), { | ||
wrapper: contextWrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.signIn(true); | ||
}); | ||
expect(result.current.signIn).toBeTruthy(); | ||
}); | ||
|
||
test('should call signIn with SSO and available configs', () => { | ||
process.env.SSO_AUTHORITY = 'http://localhost'; | ||
process.env.SSO_CLIENT_ID = 'dev-client'; | ||
|
||
const { result } = renderHook(() => useAuth(), { | ||
wrapper: contextWrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.signIn(true); | ||
}); | ||
expect(result.current.signIn).toBeTruthy(); | ||
}); | ||
|
||
test('should call signOut successfully', () => { | ||
const { result } = renderHook(() => useAuth(), { | ||
wrapper: contextWrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.signOut(); | ||
}); | ||
expect(result.current.signOut).toBeTruthy(); | ||
}); | ||
}); |