Files
Epicnabbo-Catalogus-Updated…/src/actions/admin-teams.test.ts
T

62 lines
1.7 KiB
TypeScript

import { revalidatePath } from "next/cache";
import { beforeEach, expect, it, vi } from "vitest";
import { requirePermission } from "@/lib/admin/guard";
import { createTeam, deleteTeam } from "./admin-teams";
const { execute } = vi.hoisted(() => ({ execute: vi.fn() }));
vi.mock("@/features/housekeeping/domains/people/services/mutations", () => ({
createPeopleMutationInvocation: vi.fn((staff, correlationId) => ({
expectedActorId: staff.id,
correlationId,
legacy: true,
})),
peopleMutationService: { execute },
}));
vi.mock("@/lib/admin/guard", () => ({ requirePermission: vi.fn() }));
vi.mock("@/lib/permissions", () => ({
PERMS: { USERS_EDIT: "admin.users.edit" },
}));
vi.mock("next/cache", () => ({ revalidatePath: vi.fn() }));
const form = (data: Record<string, string>) =>
({ get: (key: string) => data[key] ?? null }) as FormData;
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(requirePermission).mockResolvedValue({
id: 1,
rank: 7,
username: "admin",
});
execute.mockResolvedValue({
ok: true,
data: { before: null, after: {} },
correlationId: "team",
});
});
it("preserves create and delete team payloads plus /admin revalidation", async () => {
await createTeam(form({ rankName: "Moderator" }));
await deleteTeam(form({ id: "42" }));
expect(execute.mock.calls.map((call) => [call[1], call[2]])).toEqual([
[
"team.change",
{
action: "create",
rankName: "Moderator",
badge: "",
jobDescription: "",
staffColor: "#327fa8",
hiddenRank: false,
},
],
["team.change", { action: "delete", teamId: 42 }],
]);
expect(revalidatePath).toHaveBeenCalledTimes(2);
});
it("preserves empty rank name as a no-op", async () => {
await createTeam(form({ rankName: "" }));
expect(execute).not.toHaveBeenCalled();
});