Lists, adds, renames, orders and activates/deactivates interests, gated by BO_INTERESTS. API errors map to field messages under Name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn(), apiPut: vi.fn() }));
|
|
vi.mock("@/app/lib/clientApi", () => mocks);
|
|
|
|
import { listAdminInterests, saveAdminInterest } from "./adminInterests";
|
|
|
|
beforeEach(() => {
|
|
mocks.apiGet.mockReset();
|
|
mocks.apiPost.mockReset();
|
|
mocks.apiPut.mockReset();
|
|
});
|
|
|
|
describe("listAdminInterests", () => {
|
|
it("GETs /api/interests", async () => {
|
|
mocks.apiGet.mockResolvedValue([{ id: 1, name: "Workshop", active: true, sortOrder: 1 }]);
|
|
const result = await listAdminInterests();
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/interests");
|
|
expect(result).toEqual([{ id: 1, name: "Workshop", active: true, sortOrder: 1 }]);
|
|
});
|
|
});
|
|
|
|
describe("saveAdminInterest", () => {
|
|
it("POSTs when id is absent", async () => {
|
|
mocks.apiPost.mockResolvedValue({ id: 1, name: "New Interest" });
|
|
await saveAdminInterest({ name: "New Interest", active: true, sortOrder: 5 });
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/interests", { name: "New Interest", active: true, sortOrder: 5 });
|
|
});
|
|
|
|
it("PUTs to /api/interests/{id} when id is present", async () => {
|
|
mocks.apiPut.mockResolvedValue({ id: 200, name: "Edited Interest", active: false, sortOrder: 10 });
|
|
await saveAdminInterest({ id: 200, name: "Edited Interest", active: false, sortOrder: 10 });
|
|
expect(mocks.apiPut).toHaveBeenCalledWith("/api/interests/200", { id: 200, name: "Edited Interest", active: false, sortOrder: 10 });
|
|
});
|
|
});
|