test(api): achieve 100% coverage across all routes, middleware, and services
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 1m3s
CI / Lint, Build & Test (pull_request) Successful in 1m8s

- Add full test suite for frontend.ts (POST /log and POST /error)
- Add error-path tests to all route handlers to cover catch blocks
  triggered by Prisma rejections
- Add non-Error throw tests to cover the `new Error(String(error))`
  ternary false branch in middleware, services, and route catch handlers
- Suppress unreachable outer catch in about.ts with v8 ignore (fetchReleases
  swallows all errors internally, making the outer catch genuinely dead code)
This commit is contained in:
2026-03-09 19:52:27 -07:00
committed by Naomi Carrigan
parent 2a0a3511b4
commit d48b53eecd
15 changed files with 394 additions and 0 deletions
+24
View File
@@ -93,6 +93,18 @@ describe("prestige route", () => {
expect(body.runestones).toBeGreaterThanOrEqual(0);
});
it("returns 500 when the database throws during prestige", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await post("");
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during prestige", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await post("");
expect(res.status).toBe(500);
});
it("updates daily challenge progress when dailyChallenges are set", async () => {
const state = makeState({
dailyChallenges: {
@@ -152,5 +164,17 @@ describe("prestige route", () => {
expect(body.runestonesRemaining).toBe(90); // 100 - 10
expect(body.purchasedUpgradeIds).toContain("income_1");
});
it("returns 500 when the database throws during buy-upgrade", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await post("/buy-upgrade", { upgradeId: "income_1" });
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during buy-upgrade", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await post("/buy-upgrade", { upgradeId: "income_1" });
expect(res.status).toBe(500);
});
});
});