import { describe, expect, it } from "vitest"; import { BusinessError } from "@watchman/api"; import { healthFailureView, healthSuccessView } from "./health"; describe("health view mapping", () => { it("maps success payload", () => { const view = healthSuccessView({ status: "ok", app: "watchman", version: "0.1.0", }); expect(view).toEqual({ state: "success", detail: "watchman 0.1.0", }); }); it("maps BusinessError failure", () => { const view = healthFailureView( new BusinessError({ code: 50000, message: "Service error", status: 500, requestId: "req-1", }), ); expect(view.state).toBe("failure"); expect(view.detail).toContain("50000"); expect(view.detail).toContain("Service error"); }); it("maps unknown failure", () => { const view = healthFailureView(new Error("network down")); expect(view).toEqual({ state: "failure", detail: "Error: network down", }); }); });