wip
This commit is contained in:
@@ -45,8 +45,8 @@ vi.mock('../../../apps/website/lib/auth/AuthContext', () => {
|
||||
refreshSession: async () => {},
|
||||
});
|
||||
|
||||
const AuthProvider = ({ value, children }: { value: any; children: React.ReactNode }) => (
|
||||
<AuthContext.Provider value={value}>{children}</AuthContext.Provider>
|
||||
const AuthProvider = ({ initialSession, children }: { initialSession?: any; children: React.ReactNode }) => (
|
||||
<AuthContext.Provider value={{ session: initialSession, loading: false, login: () => {}, logout: async () => {}, refreshSession: async () => {} }}>{children}</AuthContext.Provider>
|
||||
);
|
||||
|
||||
const useAuth = () => React.useContext(AuthContext);
|
||||
@@ -65,13 +65,7 @@ describe('AlphaNav', () => {
|
||||
it('hides Dashboard link and uses Home when unauthenticated', () => {
|
||||
render(
|
||||
<AuthProvider
|
||||
value={{
|
||||
session: null,
|
||||
loading: false,
|
||||
login: () => {},
|
||||
logout: async () => {},
|
||||
refreshSession: async () => {},
|
||||
}}
|
||||
initialSession={null}
|
||||
>
|
||||
<AlphaNav />
|
||||
</AuthProvider>,
|
||||
@@ -87,14 +81,11 @@ describe('AlphaNav', () => {
|
||||
it('shows Dashboard link and hides Home when authenticated', () => {
|
||||
render(
|
||||
<AuthProvider
|
||||
value={{
|
||||
session: {
|
||||
user: { id: 'user-1' },
|
||||
},
|
||||
loading: false,
|
||||
login: () => {},
|
||||
logout: async () => {},
|
||||
refreshSession: async () => {},
|
||||
initialSession={{
|
||||
user: { id: 'user-1', displayName: 'Test User' },
|
||||
issuedAt: Date.now(),
|
||||
expiresAt: Date.now() + 3600000,
|
||||
token: 'fake-token',
|
||||
}}
|
||||
>
|
||||
<AlphaNav />
|
||||
|
||||
@@ -35,7 +35,9 @@ describe('iRacing auth route handlers', () => {
|
||||
expect(location).toMatch(/state=/);
|
||||
|
||||
expect(cookieStore.set).toHaveBeenCalled();
|
||||
const [name] = cookieStore.set.mock.calls[0];
|
||||
const call = cookieStore.set.mock.calls[0];
|
||||
expect(call).toBeDefined();
|
||||
const [name] = call as [string, string];
|
||||
expect(name).toBe('gp_demo_auth_state');
|
||||
});
|
||||
|
||||
@@ -58,7 +60,9 @@ describe('iRacing auth route handlers', () => {
|
||||
expect(location).toBe('http://localhost/dashboard');
|
||||
|
||||
expect(cookieStore.set).toHaveBeenCalled();
|
||||
const [sessionName, sessionValue] = cookieStore.set.mock.calls[0];
|
||||
const call = cookieStore.set.mock.calls[0];
|
||||
expect(call).toBeDefined();
|
||||
const [sessionName, sessionValue] = call as [string, string];
|
||||
expect(sessionName).toBe('gp_demo_session');
|
||||
expect(typeof sessionValue).toBe('string');
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('getAppMode', () => {
|
||||
it('falls back to "pre-launch" and logs when NEXT_PUBLIC_GRIDPILOT_MODE is invalid in production', () => {
|
||||
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'invalid-mode';
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'invalid-mode' as any;
|
||||
|
||||
const mode = getAppMode();
|
||||
|
||||
@@ -56,7 +56,7 @@ describe('getAppMode', () => {
|
||||
|
||||
it('throws in development when NEXT_PUBLIC_GRIDPILOT_MODE is invalid', () => {
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'invalid-mode';
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'invalid-mode' as any;
|
||||
|
||||
expect(() => getAppMode()).toThrowError(/Invalid NEXT_PUBLIC_GRIDPILOT_MODE/);
|
||||
});
|
||||
|
||||
@@ -103,7 +103,9 @@ describe('CreateLeaguePage - URL-bound wizard steps', () => {
|
||||
fireEvent.click(backButton);
|
||||
|
||||
expect(routerInstance.push).toHaveBeenCalledTimes(1);
|
||||
const callArg = routerInstance.push.mock.calls[0][0] as string;
|
||||
const call = routerInstance.push.mock.calls[0];
|
||||
expect(call).toBeDefined();
|
||||
const callArg = (call as [string])[0];
|
||||
expect(callArg).toContain('/leagues/create');
|
||||
expect(callArg).toContain('step=structure');
|
||||
});
|
||||
|
||||
@@ -6,12 +6,12 @@ type RateLimitResult = {
|
||||
resetAt: number;
|
||||
};
|
||||
|
||||
const mockCheckRateLimit = vi.fn<[], Promise<RateLimitResult>>();
|
||||
const mockGetClientIp = vi.fn<[], string>();
|
||||
const mockCheckRateLimit = vi.fn(() => Promise.resolve({ allowed: true, remaining: 4, resetAt: 0 }));
|
||||
const mockGetClientIp = vi.fn(() => '127.0.0.1');
|
||||
|
||||
vi.mock('../../../apps/website/lib/rate-limit', () => ({
|
||||
checkRateLimit: (...args: unknown[]) => mockCheckRateLimit(...(args as [])),
|
||||
getClientIp: (..._args: unknown[]) => mockGetClientIp(),
|
||||
checkRateLimit: mockCheckRateLimit,
|
||||
getClientIp: mockGetClientIp,
|
||||
}));
|
||||
|
||||
async function getPostHandler() {
|
||||
|
||||
Reference in New Issue
Block a user