Files
co-lite/solvway-admin-portal/app/lib/services/adminLeads.test.ts
T
ngqileandClaude Opus 5.5 82b6943474 feat(admin-portal): leads listing and lead detail
Lead Listing with search and server paging, lead detail with event
history, shared-contact warning and an edit form under BO_LEADS_EDIT,
and a View lead link from the event lead edit page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-27 16:53:44 +08:00

38 lines
1.5 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPut: vi.fn() }));
vi.mock("@/app/lib/clientApi", () => mocks);
import { getLead, listLeads, updateLead } from "./adminLeads";
beforeEach(() => {
mocks.apiGet.mockReset();
mocks.apiPut.mockReset();
});
describe("adminLeads", () => {
it("lists with a 0-based page and q", async () => {
mocks.apiGet.mockResolvedValue({ content: [{ leadUuid: "1" }], totalElements: 41 });
const out = await listLeads({ q: "ann", page: 3, pageSize: 20 });
expect(mocks.apiGet).toHaveBeenCalledWith("/api/leads?q=ann&page=2&size=20");
expect(out).toEqual({ items: [{ leadUuid: "1" }], total: 41 });
});
it("omits a blank q and tolerates an empty body", async () => {
mocks.apiGet.mockResolvedValue(null);
const out = await listLeads({ q: "", page: 1, pageSize: 10 });
expect(mocks.apiGet).toHaveBeenCalledWith("/api/leads?page=0&size=10");
expect(out).toEqual({ items: [], total: 0 });
});
it("gets and updates one lead", async () => {
mocks.apiGet.mockResolvedValue({ leadUuid: "l-1" });
mocks.apiPut.mockResolvedValue({ leadUuid: "l-1" });
await getLead("l-1");
const payload = { name: "A", mobile: null, email: "a@x.com", companyName: null, jobTitle: null, notes: null };
await updateLead("l-1", payload);
expect(mocks.apiGet).toHaveBeenCalledWith("/api/leads/l-1");
expect(mocks.apiPut).toHaveBeenCalledWith("/api/leads/l-1", payload);
});
});