Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
28 lines
975 B
TypeScript
28 lines
975 B
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({ apiGet: vi.fn() }));
|
|
vi.mock("@/app/lib/clientApi", () => ({ apiGet: mocks.apiGet }));
|
|
|
|
import { getEmail, listEmails } from "./adminEmails";
|
|
|
|
beforeEach(() => {
|
|
mocks.apiGet.mockReset();
|
|
});
|
|
|
|
describe("listEmails", () => {
|
|
it("sends only the given filters with a 0-based page", async () => {
|
|
mocks.apiGet.mockResolvedValue({ content: [{ id: 7 }], totalElements: 12 });
|
|
const out = await listEmails({ recipient: "sales1", from: "2026-11-01", page: 2, pageSize: 10 });
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/emails?recipient=sales1&from=2026-11-01&page=1&size=10");
|
|
expect(out).toEqual({ items: [{ id: 7 }], total: 12 });
|
|
});
|
|
});
|
|
|
|
describe("getEmail", () => {
|
|
it("GETs one email by id", async () => {
|
|
mocks.apiGet.mockResolvedValue({ id: 7 });
|
|
await getEmail(7);
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/emails/7");
|
|
});
|
|
});
|