-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
100 lines (94 loc) · 2.9 KB
/
jest.setup.js
File metadata and controls
100 lines (94 loc) · 2.9 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import '@testing-library/jest-dom'
// Set mock environment variables BEFORE importing anything else
process.env.NEXT_PUBLIC_SUPABASE_URL = 'http://localhost:54321'
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY = 'mock-key'
process.env.NEXT_PUBLIC_DAILY_CO_API_KEY = 'mock-daily-key'
process.env.PAYRAM_API_KEY = 'mock-payram-key'
process.env.PAYRAM_MERCHANT_ID = 'mock-payram-merchant'
process.env.VERIFF_API_KEY = 'mock-veriff-key'
process.env.VERIFF_SECRET_KEY = 'mock-veriff-secret'
process.env.PAYRAM_WEBHOOK_SECRET = 'mock-webhook-secret'
process.env.DAILY_API_KEY = 'mock-daily-key'
process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY = 'pk_test_mock'
process.env.STRIPE_SECRET_KEY = 'sk_test_mock'
process.env.STRIPE_WEBHOOK_SECRET = 'whsec_mock'
// Mock next/navigation
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
}),
usePathname: () => '/',
}))
// Mock @supabase/supabase-js at module level
jest.mock('@supabase/supabase-js', () => ({
createClient: jest.fn(() => ({
auth: {
getSession: jest.fn(),
signInWithPassword: jest.fn(),
signUp: jest.fn(),
signOut: jest.fn(),
onAuthStateChange: jest.fn(() => ({ data: { subscription: null } })),
},
from: jest.fn(() => ({
select: jest.fn().mockReturnThis(),
eq: jest.fn().mockReturnThis(),
single: jest.fn(),
update: jest.fn().mockReturnThis(),
})),
})),
}))
// lightweight shims for Request and Headers (needed by next/server classes)
if (typeof global.Request === 'undefined') {
global.Request = class {
constructor(input, init) {
this.input = input;
this.init = init;
}
};
}
if (typeof global.Headers === 'undefined') {
global.Headers = class {
constructor(init = {}) {
Object.assign(this, init);
}
};
}
if (typeof global.Response === 'undefined') {
global.Response = class {
constructor(body, init) {
this.body = body;
this.init = init;
}
static json(body, init) {
// mimic fetch Response.json static helper
return new global.Response(JSON.stringify(body), init);
}
// optionally provide text() for completeness
text() {
return Promise.resolve(this.body);
}
};
}
// simple fetch stub; tests will spy on or mock it further as needed
if (typeof global.fetch === 'undefined') {
global.fetch = jest.fn(() => Promise.resolve({ ok: true, json: async () => ({}) }));
}
// Mock @/lib/supabase/client
jest.mock('@/lib/supabase/client', () => ({
createClient: jest.fn(() => ({
auth: {
getSession: jest.fn(),
signInWithPassword: jest.fn(),
signUp: jest.fn(),
signOut: jest.fn(),
onAuthStateChange: jest.fn(() => ({ data: { subscription: null } })),
},
from: jest.fn(() => ({
select: jest.fn().mockReturnThis(),
eq: jest.fn().mockReturnThis(),
single: jest.fn(),
update: jest.fn().mockReturnThis(),
})),
})),
}))