42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
// @vitest-environment node
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { LoaderFunctionArgs } from "react-router";
|
|
|
|
vi.mock("~/locale/i18next.server", () => ({
|
|
getTranslations: vi.fn(async () => ({ t: (key: string) => key })),
|
|
}));
|
|
|
|
vi.mock("~/utils/helpers/.server/PermissionsService", () => ({
|
|
verifyUserHasPermission: vi.fn(),
|
|
}));
|
|
|
|
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
|
import { loader } from "./notifications";
|
|
|
|
function callLoader() {
|
|
return loader({
|
|
request: new Request("https://admin.example.test/notifications"),
|
|
params: {},
|
|
context: {},
|
|
unstable_pattern: "admin/notifications",
|
|
} as LoaderFunctionArgs);
|
|
}
|
|
|
|
describe("admin notifications route", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.stubEnv("APP_NAME", "HiveGrid");
|
|
vi.stubEnv("NOTIFICATIONS_NOVU_API_KEY", "");
|
|
vi.mocked(verifyUserHasPermission).mockResolvedValue(undefined as never);
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
it("does not require the optional external notification provider key", async () => {
|
|
await expect(callLoader()).resolves.toEqual({ title: "notifications.title | HiveGrid" });
|
|
expect(verifyUserHasPermission).toHaveBeenCalledWith(expect.any(Request), "admin.notifications.view");
|
|
});
|
|
});
|