Skip to content

Commit e40bc36

Browse files
Update mock API endpoints to use port 8099
1 parent 3c49f91 commit e40bc36

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

client/src/test/contexts/AuthContext.test.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('AuthContext', () => {
9797
it('should handle login failure', async () => {
9898
// Override the default login handler to return an error
9999
server.use(
100-
http.post('http://localhost:3000/api/auth/login', () => {
100+
http.post('http://localhost:8099/api/auth/login', () => {
101101
return HttpResponse.json(
102102
{ error: 'Invalid credentials' },
103103
{ status: 401 }
@@ -143,7 +143,7 @@ describe('AuthContext', () => {
143143
it('should handle registration failure for existing user', async () => {
144144
// Override the default register handler to return an error
145145
server.use(
146-
http.post('http://localhost:3000/api/auth/register', () => {
146+
http.post('http://localhost:8099/api/auth/register', () => {
147147
return HttpResponse.json(
148148
{ error: 'Username already exists' },
149149
{ status: 409 }
@@ -229,7 +229,7 @@ describe('AuthContext', () => {
229229

230230
// Override the me endpoint to return 401
231231
server.use(
232-
http.get('http://localhost:3000/api/auth/me', () => {
232+
http.get('http://localhost:8099/api/auth/me', () => {
233233
return HttpResponse.json(
234234
{ error: 'Unauthorized' },
235235
{ status: 401 }
@@ -254,7 +254,7 @@ describe('AuthContext', () => {
254254

255255
// Mock a delayed response
256256
server.use(
257-
http.post('http://localhost:3000/api/auth/login', async () => {
257+
http.post('http://localhost:8099/api/auth/login', async () => {
258258
await new Promise(resolve => setTimeout(resolve, 100))
259259
return HttpResponse.json({
260260
token: 'mock-jwt-token',
@@ -279,7 +279,7 @@ describe('AuthContext', () => {
279279
it('should handle network errors gracefully', async () => {
280280
// Mock network error
281281
server.use(
282-
http.post('http://localhost:3000/api/auth/login', () => {
282+
http.post('http://localhost:8099/api/auth/login', () => {
283283
return HttpResponse.error()
284284
})
285285
)
@@ -300,6 +300,16 @@ describe('AuthContext', () => {
300300
})
301301

302302
it('should handle concurrent login attempts', async () => {
303+
// Mock successful login for this test
304+
server.use(
305+
http.post('http://localhost:8099/api/auth/login', () => {
306+
return HttpResponse.json({
307+
token: 'mock-jwt-token',
308+
user: { id: 1, username: 'testuser', email: 'test@example.com' },
309+
})
310+
})
311+
)
312+
303313
const user = userEvent.setup()
304314
render(<TestComponent />, { wrapper: TestWrapper })
305315

client/src/test/mocks/handlers.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const mockDocuments = [
8484

8585
export const handlers = [
8686
// Auth endpoints
87-
http.post('http://localhost:3000/api/auth/login', async ({ request }) => {
87+
http.post('http://localhost:8099/api/auth/login', async ({ request }) => {
8888
const body = await request.json() as { username: string; password: string }
8989

9090
if (body.username === 'testuser' && body.password === 'password') {
@@ -102,7 +102,7 @@ export const handlers = [
102102
)
103103
}),
104104

105-
http.post('http://localhost:3000/api/auth/register', async ({ request }) => {
105+
http.post('http://localhost:8099/api/auth/register', async ({ request }) => {
106106
const body = await request.json() as { username: string; email: string; password: string }
107107

108108
if (body.username === 'existinguser') {
@@ -124,11 +124,11 @@ export const handlers = [
124124
})
125125
}),
126126

127-
http.post('http://localhost:3000/api/auth/logout', () => {
127+
http.post('http://localhost:8099/api/auth/logout', () => {
128128
return HttpResponse.json({ message: 'Logged out successfully' })
129129
}),
130130

131-
http.get('http://localhost:3000/api/auth/me', ({ request }) => {
131+
http.get('http://localhost:8099/api/auth/me', ({ request }) => {
132132
const auth = checkAuth(request)
133133
if (!auth.authorized) {
134134
return auth.error
@@ -138,7 +138,7 @@ export const handlers = [
138138
}),
139139

140140
// Document endpoints
141-
http.get('http://localhost:3000/api/documents', ({ request }) => {
141+
http.get('http://localhost:8099/api/documents', ({ request }) => {
142142
const auth = checkAuth(request)
143143
if (!auth.authorized) {
144144
return auth.error
@@ -147,7 +147,7 @@ export const handlers = [
147147
return HttpResponse.json({ documents: mockDocuments })
148148
}),
149149

150-
http.post('http://localhost:3000/api/documents/upload', async ({ request }) => {
150+
http.post('http://localhost:8099/api/documents/upload', async ({ request }) => {
151151
const auth = checkAuth(request)
152152
if (!auth.authorized) {
153153
return auth.error
@@ -201,7 +201,7 @@ export const handlers = [
201201
}
202202
}),
203203

204-
http.get('http://localhost:3000/api/documents/:id/content', ({ params, request }) => {
204+
http.get('http://localhost:8099/api/documents/:id/content', ({ params, request }) => {
205205
const auth = checkAuth(request)
206206
if (!auth.authorized) {
207207
return auth.error
@@ -225,7 +225,7 @@ export const handlers = [
225225
})
226226
}),
227227

228-
http.delete('http://localhost:3000/api/documents/:id', ({ params, request }) => {
228+
http.delete('http://localhost:8099/api/documents/:id', ({ params, request }) => {
229229
const auth = checkAuth(request)
230230
if (!auth.authorized) {
231231
return auth.error
@@ -245,7 +245,7 @@ export const handlers = [
245245
}),
246246

247247
// GenAI endpoints
248-
http.post('http://localhost:3000/api/genai/chat/sessions', async ({ request }) => {
248+
http.post('http://localhost:8099/api/genai/chat/sessions', async ({ request }) => {
249249
const auth = checkAuth(request)
250250
if (!auth.authorized) {
251251
return auth.error
@@ -260,7 +260,7 @@ export const handlers = [
260260
})
261261
}),
262262

263-
http.post('http://localhost:3000/api/genai/chat/sessions/:sessionId/messages', async ({ request, params }) => {
263+
http.post('http://localhost:8099/api/genai/chat/sessions/:sessionId/messages', async ({ request, params }) => {
264264
const auth = checkAuth(request)
265265
if (!auth.authorized) {
266266
return auth.error
@@ -283,7 +283,7 @@ export const handlers = [
283283
})
284284
}),
285285

286-
http.post('http://localhost:3000/api/genai/summary', async ({ request }) => {
286+
http.post('http://localhost:8099/api/genai/summary', async ({ request }) => {
287287
const auth = checkAuth(request)
288288
if (!auth.authorized) {
289289
return auth.error
@@ -296,7 +296,7 @@ export const handlers = [
296296
})
297297
}),
298298

299-
http.get('http://localhost:3000/api/genai/quiz/documents/:documentId', async ({ request, params }) => {
299+
http.get('http://localhost:8099/api/genai/quiz/documents/:documentId', async ({ request, params }) => {
300300
const auth = checkAuth(request)
301301
if (!auth.authorized) {
302302
return auth.error
@@ -325,7 +325,7 @@ export const handlers = [
325325
})
326326
}),
327327

328-
http.get('http://localhost:3000/api/genai/flashcards/documents/:documentId', async ({ request, params }) => {
328+
http.get('http://localhost:8099/api/genai/flashcards/documents/:documentId', async ({ request, params }) => {
329329
const auth = checkAuth(request)
330330
if (!auth.authorized) {
331331
return auth.error

0 commit comments

Comments
 (0)