fix : correct api healthz
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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" },
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user