Files
community-rule/tests/pages/shared-rule.test.ts
T
adilallo 0fe2624002 Show Share initials, a readable link, and a copy confirmation.
Filled avatars used white ink on yellow, the link field was a dimmed disabled input, and Copy failed silently when the clipboard API was denied.
2026-11-21 11:42:49 -07:00

42 lines
1.2 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const getReadablePublishedRuleMock = vi.fn();
const getSessionUserMock = vi.fn();
const notFoundMock = vi.fn(() => {
throw new Error("NEXT_NOT_FOUND");
});
vi.mock("next/navigation", () => ({
notFound: () => notFoundMock(),
}));
vi.mock("../../lib/server/publishedRules", () => ({
getReadablePublishedRule: (...args: unknown[]) =>
getReadablePublishedRuleMock(...args),
}));
vi.mock("../../lib/server/session", () => ({
getSessionUser: () => getSessionUserMock(),
}));
import { generateMetadata } from "../../app/(marketing)/r/[shareSlug]/page";
describe("shared Rule page", () => {
beforeEach(() => {
getReadablePublishedRuleMock.mockReset();
getSessionUserMock.mockReset();
notFoundMock.mockClear();
getSessionUserMock.mockResolvedValue(null);
});
it("returns 404 when the share link is off or unknown", async () => {
getReadablePublishedRuleMock.mockResolvedValue(null);
await expect(
generateMetadata({
params: Promise.resolve({ shareSlug: "k7f2-9qxm" }),
}),
).rejects.toThrow("NEXT_NOT_FOUND");
expect(notFoundMock).toHaveBeenCalled();
});
});