- Remove 25 unused imports across 14 test files - Remove 1 unused variable (rename with _ prefix) - Fix 2 noBannedTypes (Function → (...args: unknown[]) => unknown) - Fix 1 useTemplate lint (string concat → template literal in merge-config.cjs) - Fix 1 useNodejsImportProtocol (merge-config.cjs) - Fix 2 noTemplateCurlyInString (generate-drizzle-schema.mjs generator code) - Auto-fix formatting + import sorting across modified files - 221 remaining warnings: intentional noExplicitAny in prisma-facade.ts (Prisma compat layer) - 0 tsc errors, 583 tests passing
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
// @ts-nocheck
|
|
import { revalidatePath } from "next/cache";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { requirePermission } from "@/lib/admin/guard";
|
|
import { rcon } from "@/lib/services/rcon";
|
|
import { sendHotelAlert } from "./admin-alerts";
|
|
|
|
vi.mock("@/lib/admin/guard", () => ({ requirePermission: vi.fn() }));
|
|
vi.mock("@/lib/permissions", () => ({
|
|
PERMS: { NOTIFICATIONS_EDIT: "notifications.edit" },
|
|
}));
|
|
vi.mock("@/lib/services/rcon", () => ({ rcon: { send: vi.fn() } }));
|
|
vi.mock("next/cache", () => ({ revalidatePath: vi.fn() }));
|
|
|
|
const fakeForm = (data: Record<string, string>) => ({
|
|
get: (key: string) => data[key] ?? null,
|
|
});
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.mocked(requirePermission).mockResolvedValue({
|
|
id: 1,
|
|
rank: 7,
|
|
username: "admin",
|
|
} as never);
|
|
});
|
|
|
|
describe("sendHotelAlert", () => {
|
|
it("sends hotel alert and revalidates", async () => {
|
|
await sendHotelAlert(
|
|
fakeForm({ message: "Hello!" }) as unknown as FormData,
|
|
);
|
|
expect(rcon.send).toHaveBeenCalledWith("hotelalert", { message: "Hello!" });
|
|
expect(revalidatePath).toHaveBeenCalledWith("/admin/alerts");
|
|
});
|
|
|
|
it("returns early when message is empty", async () => {
|
|
await sendHotelAlert(fakeForm({ message: "" }) as unknown as FormData);
|
|
expect(rcon.send).not.toHaveBeenCalled();
|
|
});
|
|
});
|