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"; function getReq(url = "http://localhost/api/admin/kyc/export") { return new Request(url) as unknown as Parameters[0]; } beforeEach(() => { mocks.callMobileApi.mockReset(); mocks.getToken.mockReset(); }); describe("GET /api/admin/kyc/export", () => { it("returns 401 without a session", async () => { mocks.getToken.mockResolvedValue(null); const res = await GET(getReq()); expect(res.status).toBe(401); }); it("forwards query params (minus page/size) to mobile-api", async () => { mocks.getToken.mockResolvedValue("jwt-abc"); mocks.callMobileApi.mockResolvedValue({ ok: true, data: [] }); await GET(getReq("http://localhost/api/admin/kyc/export?status=P&q=ahmad&from=2025-01-01&to=2025-12-31&channel=MEMBER&page=0&size=10")); // page/size should be absent from the export call const [path] = mocks.callMobileApi.mock.calls[0]; expect(path).toContain("status=P"); expect(path).toContain("q=ahmad"); expect(path).not.toContain("page="); expect(path).not.toContain("size="); }); });