mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 15:56:56 +00:00
feat: implement esting suite using Vitest and add to ci
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
export const mockUser = {
|
||||
public_id: "123e4567-e89b-12d3-a456-426614174000",
|
||||
email: "test@example.com",
|
||||
full_name: "Test User",
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import { HttpResponse, http } from "msw";
|
||||
import { setupServer } from "msw/node";
|
||||
import { mockUser } from "../fixtures/user.fixture";
|
||||
|
||||
const apiServerHost = "http://piku-server";
|
||||
|
||||
export const successHandlers = [
|
||||
http.post(`http://${apiServerHost}/api/auth/login/`, () =>
|
||||
HttpResponse.json({ access: "mock-access-token" }),
|
||||
),
|
||||
http.post(`http://${apiServerHost}/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({}),
|
||||
),
|
||||
];
|
||||
|
||||
export const errorHandlers = [
|
||||
http.post(`http://${apiServerHost}/api/auth/login/`, () =>
|
||||
HttpResponse.json({ error: "Invalid credentials" }, { status: 400 }),
|
||||
),
|
||||
http.post(`http://${apiServerHost}/api/auth/refresh/`, () =>
|
||||
HttpResponse.json({ error: "Invalid Token" }, { status: 401 }),
|
||||
),
|
||||
http.get(`http://${apiServerHost}/api/auth/me/`, () =>
|
||||
HttpResponse.json({ error: "Invalid Token" }, { status: 401 }),
|
||||
),
|
||||
];
|
||||
|
||||
export const server = setupServer(...successHandlers);
|
||||
@@ -0,0 +1,17 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { IDBFactory } from "fake-indexeddb";
|
||||
import { afterAll, afterEach, beforeAll } from "vitest";
|
||||
import { server } from "./mocks/server";
|
||||
|
||||
/**
|
||||
* faking indexeddb in memory for testing crypto key storage
|
||||
*/
|
||||
Object.defineProperty(globalThis, "indexedDB", {
|
||||
value: new IDBFactory(),
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
beforeAll(() => server.listen({ onUnhandledRequest: "warn" }));
|
||||
afterEach(() => server.resetHandlers());
|
||||
afterAll(() => server.close());
|
||||
Reference in New Issue
Block a user