-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.js
More file actions
157 lines (142 loc) · 3.29 KB
/
jest.setup.js
File metadata and controls
157 lines (142 loc) · 3.29 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import '@testing-library/jest-dom'
// Mock Next.js Request and Response
global.Request = class {
constructor(url, options = {}) {
this.url = url
this.method = options.method || 'GET'
this.headers = options.headers || new Map()
this.json = async () => options.body ? JSON.parse(options.body) : null
}
}
global.Response = class {
constructor(body, options = {}) {
this.body = body
this.status = options.status || 200
this.headers = options.headers || new Map()
}
async json() {
return this.body
}
static json(body, options = {}) {
return new global.Response(body, {
status: options.status || 200,
headers: options.headers || new Map()
})
}
}
global.NextResponse = class {
static json(body, options = {}) {
return new global.Response(body, {
status: options.status || 200,
headers: options.headers || new Map()
})
}
}
// Mock Next.js router
jest.mock('next/navigation', () => ({
useRouter() {
return {
push: jest.fn(),
pathname: '/',
query: {},
}
},
usePathname() {
return '/'
},
useSearchParams() {
return new URLSearchParams()
},
}))
// Mock NextAuth
jest.mock('next-auth/react', () => ({
useSession: jest.fn(() => ({
data: null,
status: 'unauthenticated',
})),
signIn: jest.fn(),
signOut: jest.fn(),
getSession: jest.fn(),
}))
// Mock localStorage
Object.defineProperty(window, 'localStorage', {
value: {
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
},
writable: true,
})
// Mock Prisma
jest.mock('@/lib/prisma', () => ({
prisma: {
user: {
findUnique: jest.fn(),
create: jest.fn(),
update: jest.fn(),
},
account: {
findUnique: jest.fn(),
create: jest.fn(),
},
session: {
findUnique: jest.fn(),
create: jest.fn(),
},
watchlist: {
findMany: jest.fn(),
create: jest.fn(),
delete: jest.fn(),
},
},
}))
// Mock Chart.js
jest.mock('chart.js', () => ({
Chart: {
register: jest.fn(),
},
}))
// Mock Recharts
jest.mock('recharts', () => ({
LineChart: jest.fn(() => null),
Line: jest.fn(() => null),
XAxis: jest.fn(() => null),
YAxis: jest.fn(() => null),
CartesianGrid: jest.fn(() => null),
Tooltip: jest.fn(() => null),
Legend: jest.fn(() => null),
ResponsiveContainer: jest.fn(({ children }) => children),
BarChart: jest.fn(() => null),
Bar: jest.fn(() => null),
AreaChart: jest.fn(() => null),
Area: jest.fn(() => null),
ComposedChart: jest.fn(() => null),
ReferenceLine: jest.fn(() => null),
}))
// Mock react-chartjs-2
jest.mock('react-chartjs-2', () => ({
Line: jest.fn(() => null),
Bar: jest.fn(() => null),
}))
// Mock financial APIs
jest.mock('yahoo-finance2', () => ({
quote: jest.fn(),
quoteSummary: jest.fn(),
chart: jest.fn(),
options: jest.fn(),
search: jest.fn(),
}))
jest.mock('alphavantage', () => {
const mockAlphaVantage = jest.fn()
mockAlphaVantage.quote = jest.fn()
mockAlphaVantage.fundamental = jest.fn()
mockAlphaVantage.crypto = jest.fn()
mockAlphaVantage.news_sentiment = jest.fn()
return mockAlphaVantage
})
// Mock bcrypt
jest.mock('bcryptjs', () => ({
compare: jest.fn().mockResolvedValue(true),
hash: jest.fn().mockResolvedValue('hashed_password'),
}))