Files
EpicNext-Cms/src/actions/admin-photos.test.ts
T
openhands e5ff7ec9e5
CI / check (push) Successful in 33s
CI / release (push) Skipped
CI / deploy (push) Successful in 1m25s
chore: clean up biome lint warnings — all non- intentional resolved
- 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
2026-07-31 15:26:39 +02:00

38 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 { prisma } from "@/lib/prisma";
import { deletePhoto } from "./admin-photos";
vi.mock("@/lib/admin/guard", () => ({ requirePermission: vi.fn() }));
vi.mock("@/lib/permissions", () => ({ PERMS: { PAGES_EDIT: "pages.edit" } }));
vi.mock("@/lib/prisma", () => ({ prisma: { cameraWeb: { delete: 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("deletePhoto", () => {
it("deletes a photo and revalidates", async () => {
await deletePhoto(fakeForm({ id: "42" }) as unknown as FormData);
expect(prisma.cameraWeb.delete).toHaveBeenCalledWith({ where: { id: 42 } });
expect(revalidatePath).toHaveBeenCalledWith("/admin/photos");
});
it("returns early when id is not positive", async () => {
await deletePhoto(fakeForm({ id: "0" }) as unknown as FormData);
expect(prisma.cameraWeb.delete).not.toHaveBeenCalled();
});
});