import { describe, it, expect, vi, beforeEach } from "vitest"; const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn() })); vi.mock("@/app/lib/clientApi", () => mocks); import { listAdminLocations, uploadInvoiceHeaderImage } from "./adminLocations"; beforeEach(() => { mocks.apiGet.mockReset(); mocks.apiPost.mockReset(); }); describe("listAdminLocations", () => { it("GETs the flat location node list from /api/locations", async () => { mocks.apiGet.mockResolvedValue([ { id: 1, code: "GLOBAL", name: "Global", type: "G", status: "Y", parent: null }, ]); const result = await listAdminLocations(); expect(mocks.apiGet).toHaveBeenCalledWith("/api/locations"); expect(result).toHaveLength(1); }); }); describe("uploadInvoiceHeaderImage", () => { it("POSTs the file payload to /api/locations/invoice-header and returns the url", async () => { mocks.apiPost.mockResolvedValue({ url: "https://cdn/pub/bucket/header.png" }); const input = { fileName: "header.png", fileType: "image/png", base: "QUJD" }; const result = await uploadInvoiceHeaderImage(input); expect(mocks.apiPost).toHaveBeenCalledWith("/api/locations/invoice-header", input); expect(result).toEqual({ url: "https://cdn/pub/bucket/header.png" }); }); });