import { describe, it, expect, vi, beforeEach } from "vitest"; const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() })); vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi })); vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken })); import { GET } from "./route"; beforeEach(() => { mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: [{ param: "NO_OTHER_LANGUAGE", value: null }] }); mocks.getToken.mockReset().mockResolvedValue("tok"); }); describe("GET /api/password-rules", () => { it("is 401 without a session", async () => { mocks.getToken.mockResolvedValue(null); expect((await GET()).status).toBe(401); expect(mocks.callMobileApi).not.toHaveBeenCalled(); }); it("returns the active rules from the admin endpoint", async () => { const res = await GET(); expect(await res.json()).toEqual([{ param: "NO_OTHER_LANGUAGE", value: null }]); expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/password-rules/active", { token: "tok" }); }); });