mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
test: add comprehensive unit tests for apiClient, RouteGuards, and useAuth hook functionality
This commit is contained in:
@@ -2,31 +2,27 @@ import { HttpResponse, http } from "msw";
|
||||
import { setupServer } from "msw/node";
|
||||
import { mockUser } from "../fixtures/user.fixture";
|
||||
|
||||
const apiServerHost = "http://piku-server";
|
||||
const API_URL = "http://piku-server";
|
||||
|
||||
export const successHandlers = [
|
||||
http.post(`http://${apiServerHost}/api/auth/login/`, () =>
|
||||
http.post(`${API_URL}/api/auth/login/`, () =>
|
||||
HttpResponse.json({ access: "mock-access-token" }),
|
||||
),
|
||||
http.post(`http://${apiServerHost}/api/auth/refresh/`, () =>
|
||||
http.post(`${API_URL}/api/auth/refresh/`, () =>
|
||||
HttpResponse.json({ access: "new-access-token" }),
|
||||
),
|
||||
http.get(`http://${apiServerHost}/api/auth/me/`, () =>
|
||||
HttpResponse.json(mockUser),
|
||||
),
|
||||
http.post(`http://${apiServerHost}/api/auth/logout/`, () =>
|
||||
HttpResponse.json({}),
|
||||
),
|
||||
http.get(`${API_URL}/api/auth/me/`, () => HttpResponse.json(mockUser)),
|
||||
http.post(`${API_URL}/api/auth/logout/`, () => HttpResponse.json({})),
|
||||
];
|
||||
|
||||
export const errorHandlers = [
|
||||
http.post(`http://${apiServerHost}/api/auth/login/`, () =>
|
||||
http.post(`${API_URL}/api/auth/login/`, () =>
|
||||
HttpResponse.json({ error: "Invalid credentials" }, { status: 400 }),
|
||||
),
|
||||
http.post(`http://${apiServerHost}/api/auth/refresh/`, () =>
|
||||
http.post(`${API_URL}/api/auth/refresh/`, () =>
|
||||
HttpResponse.json({ error: "Invalid Token" }, { status: 401 }),
|
||||
),
|
||||
http.get(`http://${apiServerHost}/api/auth/me/`, () =>
|
||||
http.get(`${API_URL}/api/auth/me/`, () =>
|
||||
HttpResponse.json({ error: "Invalid Token" }, { status: 401 }),
|
||||
),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user