Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
77 lines
3.5 KiB
TypeScript
77 lines
3.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn(), apiPut: vi.fn(), apiDownload: vi.fn() }));
|
|
vi.mock("@/app/lib/clientApi", () => mocks);
|
|
|
|
import { listAdminUsers } from "./adminUsers";
|
|
import { listAdminEvents, listSalespersonOptions } from "./adminEvents";
|
|
import { exportLeads, listLeads } from "./adminLeads";
|
|
import { exportEventLeads, listEventLeadEvents, listEventLeads, matchLead } from "./adminEventLeads";
|
|
import { listEmails } from "./adminEmails";
|
|
import { searchAuditLog } from "./auditLog";
|
|
import { listAudit, listLocked, unlock } from "./loginSecurity";
|
|
|
|
const url = (m: { mock: { calls: unknown[][] } }) => String(m.mock.calls.at(-1)?.[0]);
|
|
|
|
beforeEach(() => {
|
|
for (const m of Object.values(mocks)) m.mockReset().mockResolvedValue({ content: [], totalElements: 0, items: [], total: 0 });
|
|
});
|
|
|
|
describe("companyId on list and export queries", () => {
|
|
it("adds it to the users list only when set", async () => {
|
|
await listAdminUsers({ page: 1, pageSize: 20, companyId: 2 });
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await listAdminUsers({ page: 1, pageSize: 20 });
|
|
expect(url(mocks.apiGet)).not.toContain("companyId");
|
|
});
|
|
|
|
it("adds it to events list and salesperson options", async () => {
|
|
await listAdminEvents({ page: 1, pageSize: 20, companyId: 2 });
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await listSalespersonOptions(3);
|
|
expect(mocks.apiGet).toHaveBeenLastCalledWith("/api/events/salesperson-options?companyId=3");
|
|
await listSalespersonOptions();
|
|
expect(mocks.apiGet).toHaveBeenLastCalledWith("/api/events/salesperson-options");
|
|
});
|
|
|
|
it("adds it to leads list and export", async () => {
|
|
await listLeads({ page: 1, pageSize: 20, companyId: 2 });
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await exportLeads({ q: "x", companyId: 2 });
|
|
expect(url(mocks.apiDownload)).toContain("companyId=2");
|
|
await exportLeads({});
|
|
expect(url(mocks.apiDownload)).not.toContain("companyId");
|
|
});
|
|
|
|
it("adds it to event-lead events, leads and export", async () => {
|
|
await listEventLeadEvents(2);
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await listEventLeadEvents();
|
|
expect(url(mocks.apiGet)).not.toContain("companyId");
|
|
await listEventLeads("e1", { page: 1, pageSize: 20, companyId: 2 });
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await exportEventLeads("e1", {}, 2);
|
|
expect(url(mocks.apiDownload)).toContain("companyId=2");
|
|
});
|
|
|
|
it("adds it to emails, audit log, login history, locked list and unlock", async () => {
|
|
await listEmails({ page: 1, pageSize: 20, companyId: 2 });
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await searchAuditLog({ page: 1, pageSize: 20, companyId: 2 });
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await listAudit({ page: 1, pageSize: 20, companyId: 2 });
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await listLocked(2);
|
|
expect(url(mocks.apiGet)).toContain("companyId=2");
|
|
await unlock("jane", 2);
|
|
expect(url(mocks.apiPost)).toContain("companyId=2");
|
|
});
|
|
|
|
it("puts companyId in the lead match body only when given", async () => {
|
|
await matchLead("e1", { mobile: "1", email: null }, 2);
|
|
expect(mocks.apiPost).toHaveBeenLastCalledWith(expect.any(String), { mobile: "1", email: null, companyId: 2 });
|
|
await matchLead("e1", { mobile: "1", email: null });
|
|
expect(mocks.apiPost.mock.calls.at(-1)?.[1]).toEqual({ mobile: "1", email: null });
|
|
});
|
|
});
|