Files
buzz-sheet/app/api/healthz/route.test.ts
T
gunshiz f5b432a496
CI / Verify (push) Successful in 1m45s
CI / Build immutable images and deploy (push) Successful in 2m24s
fix : correct api healthz
2026-10-02 18:57:43 +07:00

47 lines
1.6 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const execute = vi.fn();
const ping = vi.fn();
const checkSlip2Go = vi.fn();
const checkDiscordBot = vi.fn();
const checkLunaris = vi.fn();
vi.mock("next/server", () => ({ connection: vi.fn() }));
vi.mock("@/db/client", () => ({ getDb: () => ({ execute }) }));
vi.mock("@/lib/redis/client", () => ({ getRedisClient: async () => ({ ping }) }));
vi.mock("@/lib/health/services", () => ({ checkSlip2Go, checkDiscordBot, checkLunaris }));
const { GET } = await import("./route");
describe("healthz endpoint", () => {
beforeEach(() => {
vi.clearAllMocks();
execute.mockResolvedValue(undefined);
ping.mockResolvedValue("PONG");
checkSlip2Go.mockResolvedValue(undefined);
checkDiscordBot.mockResolvedValue(undefined);
checkLunaris.mockResolvedValue(undefined);
});
it("checks all five dependencies", async () => {
const response = await GET();
expect(response.status).toBe(200);
expect(response.headers.get("Cache-Control")).toBe("no-store");
expect(await response.json()).toMatchObject({
status: "ready",
checks: { database: "ok", redis: "ok", slip2go: "ok", discordBot: "ok", lunaris: "ok" },
});
});
it("returns 503 and identifies a failed dependency", async () => {
checkDiscordBot.mockRejectedValueOnce(new Error("offline"));
const response = await GET();
expect(response.status).toBe(503);
expect(await response.json()).toMatchObject({
status: "not-ready",
checks: { database: "ok", redis: "ok", slip2go: "ok", discordBot: "failed", lunaris: "ok" },
});
});
});