import { describe, it, expect } from "vitest"; import { errorResponse } from "./apiRoute"; describe("errorResponse", () => { it("returns 403 with the phoneVerificationRequired flag", async () => { const res = errorResponse({ ok: false, status: 403, error: "Phone verification required.", phoneVerificationRequired: true, }); expect(res.status).toBe(403); expect(await res.json()).toEqual({ error: "Phone verification required.", phoneVerificationRequired: true, }); }); it("returns 401 for an expired session", async () => { const res = errorResponse({ ok: false, status: 401, error: "Session expired", expired: true }); expect(res.status).toBe(401); }); it("returns 400 for any other failure, without the flag", async () => { const res = errorResponse({ ok: false, status: 500, error: "boom" }); expect(res.status).toBe(400); expect(await res.json()).toEqual({ error: "boom" }); }); });