Files
HiveGrid-Wireframes/hivegrid-cloud/apps/web/app/routes/admin/notifications/channels.test.tsx
T

53 lines
1.6 KiB
TypeScript

// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { ActionFunctionArgs } from "react-router";
vi.mock("~/utils/helpers/.server/PermissionsService", () => ({
verifyUserHasPermission: vi.fn(),
}));
vi.mock("~/utils/session.server", () => ({
getUserInfo: vi.fn(async () => ({ userId: "user_123" })),
validateCSRFToken: vi.fn(async () => undefined),
}));
vi.mock("~/utils/db/users.db.server", () => ({
getUser: vi.fn(async () => ({ id: "user_123", email: "user@example.com" })),
}));
vi.mock("~/modules/notifications/services/.server/NotificationService", () => ({
default: {
deleteNotificationTemplate: vi.fn(async () => null),
getNotificationTemplates: vi.fn(async () => null),
send: vi.fn(async () => null),
},
}));
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
import { action } from "./channels";
function callAction() {
const form = new FormData();
form.set("action", "create");
return action({
request: new Request("https://admin.example.test/notifications/channels", {
method: "POST",
body: form,
}),
params: {},
context: {},
} as ActionFunctionArgs);
}
describe("admin notification channels action", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(verifyUserHasPermission).mockResolvedValue(undefined as never);
});
it("requires manage permission for mutations", async () => {
await callAction();
expect(verifyUserHasPermission).toHaveBeenCalledWith(expect.any(Request), "admin.notifications.manage");
});
});