-
Notifications
You must be signed in to change notification settings - Fork 25
/
jest.setup.ts
40 lines (37 loc) · 1.41 KB
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
process.env.WORKOS_API_KEY = 'sk_test_1234567890';
process.env.WORKOS_CLIENT_ID = 'client_1234567890';
process.env.WORKOS_COOKIE_PASSWORD = 'kR620keEzOIzPThfnMEAba8XYgKdQ5vg';
process.env.NEXT_PUBLIC_WORKOS_REDIRECT_URI = 'http://localhost:3000/callback';
process.env.WORKOS_COOKIE_DOMAIN = 'example.com';
// Mock the next/headers module
jest.mock('next/headers', () => {
const cookieStore = new Map();
const headersStore = new Map();
return {
headers: async () => ({
delete: jest.fn((name: string) => headersStore.delete(name)),
get: jest.fn((name: string) => headersStore.get(name)),
set: jest.fn((name: string, value: string) => headersStore.set(name, value)),
_reset: () => {
headersStore.clear();
},
}),
cookies: async () => ({
delete: jest.fn((nameOrObject: string | { name: string; [key: string]: unknown }) => {
const cookieName = typeof nameOrObject === 'string' ? nameOrObject : nameOrObject.name;
cookieStore.delete(cookieName);
}),
get: jest.fn((name: string) => cookieStore.get(name)),
getAll: jest.fn(() => Array.from(cookieStore.entries())),
set: jest.fn((name: string, value: string | { [key: string]: string | number | boolean }) =>
cookieStore.set(name, value),
),
_reset: () => {
cookieStore.clear();
},
}),
};
});
jest.mock('next/navigation', () => ({
redirect: jest.fn(),
}));