import { describe, it, expect, vi, beforeEach } from "vitest"; const mocks = vi.hoisted(() => ({ apiGet: vi.fn() })); vi.mock("@/app/lib/clientApi", () => mocks); import { getLeadDashboard } from "./adminDashboard"; beforeEach(() => mocks.apiGet.mockReset().mockResolvedValue({})); describe("adminDashboard", () => { it("sends no query string when no params are given", async () => { await getLeadDashboard({}); expect(mocks.apiGet).toHaveBeenCalledWith("/api/dashboard/leads"); }); it("sends only the given params", async () => { await getLeadDashboard({ from: "2026-11-01", to: "2026-11-30", companyId: 2 }); expect(mocks.apiGet).toHaveBeenCalledWith("/api/dashboard/leads?from=2026-11-01&to=2026-11-30&companyId=2"); await getLeadDashboard({ companyId: 3 }); expect(mocks.apiGet).toHaveBeenLastCalledWith("/api/dashboard/leads?companyId=3"); }); });