import { describe, expect, it } from "vitest"; import { fail, ok } from "@/lib/response"; describe("lib/response", () => { it("ok 返回 code=0、message=ok、data", async () => { const res = ok({ quote_id: "Q001" }); const body = await res.json(); expect(res.status).toBe(200); expect(body).toEqual({ code: 0, message: "ok", data: { quote_id: "Q001" }, }); expect(res.headers.get("Cache-Control")).toBe("no-store"); }); it("fail 返回 error code、message、data=null 及 HTTP 状态码", async () => { const res = fail("VALIDATION_FAILED", "请填写重量", 400); const body = await res.json(); expect(res.status).toBe(400); expect(body).toEqual({ code: "VALIDATION_FAILED", message: "请填写重量", data: null, }); expect(res.headers.get("Cache-Control")).toBe("no-store"); }); });