import { revalidatePath } from "next/cache"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { requirePermissionRateLimited } from "@/lib/admin/guard"; import { disbandGuild } from "./admin-guilds"; 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", () => ({ requirePermissionRateLimited: vi.fn() })); vi.mock("@/lib/permissions", () => ({ PERMS: { USERS_EDIT: "admin.users.edit" }, })); vi.mock("next/cache", () => ({ revalidatePath: vi.fn() })); const staff = { id: 1, rank: 7, username: "admin" }; const form = (data: Record) => ({ get: (key: string) => data[key] ?? null }) as FormData; beforeEach(() => { vi.clearAllMocks(); vi.mocked(requirePermissionRateLimited).mockResolvedValue(staff as never); execute.mockResolvedValue({ ok: true, data: { before: { id: 1 }, after: null }, correlationId: "guild", }); }); describe("disbandGuild legacy wrapper", () => { it("keeps rate-limited ACL, service input, and ASE revalidation", async () => { await disbandGuild(form({ id: "9" })); expect(execute).toHaveBeenCalledWith(expect.anything(), "guild.disband", { guildId: 9, }); expect(revalidatePath).toHaveBeenCalledWith("/ase/people/community/guilds"); }); it("keeps invalid IDs as a no-op", async () => { await disbandGuild(form({ id: "0" })); expect(execute).not.toHaveBeenCalled(); expect(revalidatePath).not.toHaveBeenCalled(); }); });