Files
frontend/src/test/handlers.ts
T
codex-bot 668f2ef70e
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 10s
Frontend verify / verify (push) Failing after 7m7s
fix: align audit findings for Events, currency and auth (WealthLedger/frontend#155)
2026-11-05 07:23:07 +03:00

86 lines
2.2 KiB
TypeScript

import { http, HttpResponse } from "msw";
import { resource } from "@/test/resource";
const authentication = {
accessToken: "test-token",
user: { email: "user@example.com", id: "user-1" },
};
const handlers = [
http.post("*/api/v1/auth/register", () => HttpResponse.json(authentication)),
http.post("*/api/v1/auth/login", () => HttpResponse.json(authentication)),
http.post("*/api/v1/auth/refresh", () =>
HttpResponse.json({ code: "UNAUTHORIZED" }, { status: 401 }),
),
http.post(
"*/api/v1/auth/logout",
() => new HttpResponse(null, { status: 204 }),
),
http.get("*/api/v1/auth/me", () => HttpResponse.json(authentication.user)),
http.get("*/api/v1/tbank-connection", () =>
HttpResponse.json(
{ connected: false, connectedAt: null },
),
),
http.put("*/api/v1/tbank-connection", () =>
HttpResponse.json({ connected: true, connectedAt: "2026-08-14T00:00:00Z" }),
),
http.delete(
"*/api/v1/tbank-connection",
() => new HttpResponse(null, { status: 204 }),
),
http.get("*/api/v1/brokerage-accounts", () =>
HttpResponse.json(resource([])),
),
http.get("*/api/v1/brokerage-accounts/:accountId/portfolio", () =>
HttpResponse.json(
resource({
cashBalances: [],
isStale: false,
lastSuccessfulAt: "2026-08-14T00:00:00Z",
positions: [],
structure: { currencies: [], unvaluedCategories: [] },
totalsByCurrency: [],
}),
),
),
http.get("*/api/v1/brokerage-accounts/:accountId/operations", () =>
HttpResponse.json(
resource(
{
accountId: "account-1",
hasNext: false,
items: [],
nextCursor: null,
observedAt: "2026-08-14T00:00:00Z",
},
),
),
),
http.get("*/api/v1/brokerage-accounts/:accountId/events", () =>
HttpResponse.json(
resource({
accountId: "account-1",
calculatedAt: "2026-08-14T00:00:00Z",
events: [],
window: { from: "2026-08-14", to: "2026-09-13" },
}),
),
),
http.get("*/api/v1/brokerage-accounts/:accountId/income-summary", () =>
HttpResponse.json(
resource({
accountId: "account-1",
calculatedAt: "2026-08-14T00:00:00Z",
period: { from: "2026-01-01", to: "2026-08-14" },
totalsByCurrency: [],
}),
),
),
];
export { handlers };