42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
/**
|
|
* Overridable AuthContext mock.
|
|
*
|
|
* tests/setup.ts stubs @/src/contexts/AuthContext with this factory so a test
|
|
* can flip the signed-in shape. Auth is otherwise out of scope for these tests:
|
|
* the real provider would drag in secure-store, the tRPC login flow and redirect
|
|
* handling.
|
|
*
|
|
* Set `authMock.userDetails` in a beforeEach and reset it with resetAuthMock().
|
|
* NextOrderGlimpse (rendered by the home page) returns null unless it is set.
|
|
*/
|
|
|
|
import type { ReactNode } from 'react'
|
|
|
|
export interface AuthMockState {
|
|
user: unknown
|
|
userDetails: unknown
|
|
}
|
|
|
|
export const authMock: AuthMockState = {
|
|
user: null,
|
|
userDetails: null,
|
|
}
|
|
|
|
export function resetAuthMock() {
|
|
authMock.user = null
|
|
authMock.userDetails = null
|
|
}
|
|
|
|
export function authContextMock() {
|
|
return {
|
|
AuthProvider: ({ children }: { children?: ReactNode }) => children ?? null,
|
|
useAuth: () => ({
|
|
user: authMock.user,
|
|
userDetails: authMock.userDetails,
|
|
isAuthenticated: !!authMock.user,
|
|
isLoading: false,
|
|
token: null,
|
|
}),
|
|
useUserDetails: () => authMock.userDetails,
|
|
}
|
|
}
|