Hold /privacy behind a flag until counsel reads it, and fix leftover legal and email copy.

This commit is contained in:
adilallo committed 2026-11-20 15:36:06 -07:00
1 parent ead6c8f716
commit 072e5362f5
43 files changed
+548 -191

No files matched your search

+11 -1
View File
@@ -118,7 +118,7 @@ describe("Footer (behavioral tests)", () => {
});
it("renders legal links to privacy and terms pages", () => {
render(<Footer />);
render(<Footer privacyEnabled />);
expect(
screen.getAllByRole("link", { name: "Privacy Policy" })[0],
).toHaveAttribute("href", "/privacy");
@@ -129,4 +129,14 @@ describe("Footer (behavioral tests)", () => {
screen.queryByRole("link", { name: "Cookies Settings" }),
).not.toBeInTheDocument();
});
it("omits the privacy link when the policy is off", () => {
render(<Footer privacyEnabled={false} />);
expect(
screen.queryByRole("link", { name: "Privacy Policy" }),
).not.toBeInTheDocument();
expect(
screen.getAllByRole("link", { name: "Terms of Service" })[0],
).toHaveAttribute("href", "/terms");
});
});
+15 -1
View File
@@ -78,7 +78,11 @@ describe("LoginForm", () => {
});
it("links terms and privacy to the legal pages", () => {
renderLoginForm();
renderWithProviders(
<Suspense fallback={null}>
<LoginForm privacyEnabled />
</Suspense>,
);
expect(
screen.getByRole("link", { name: "Terms of Service" }),
).toHaveAttribute("href", "/terms");
@@ -87,6 +91,16 @@ describe("LoginForm", () => {
).toHaveAttribute("href", "/privacy");
});
it("links terms only when the privacy policy is off", () => {
renderLoginForm();
expect(
screen.getByRole("link", { name: "Terms of Service" }),
).toHaveAttribute("href", "/terms");
expect(
screen.queryByRole("link", { name: "Privacy Policy" }),
).not.toBeInTheDocument();
});
it("shows validation error when email is invalid", async () => {
const user = userEvent.setup();
renderLoginForm();
+3
View File
@@ -17,4 +17,7 @@ vi.mock("next/navigation", () => ({
useRouter: () => testRouter,
usePathname: () => testPathname(),
useSearchParams: vi.fn(() => new URLSearchParams()),
notFound: () => {
throw new Error("NEXT_NOT_FOUND");
},
}));
+52 -8
View File
@@ -2,10 +2,14 @@ import { describe, expect, test, vi } from "vitest";
import { screen } from "@testing-library/react";
import { renderWithProviders as render } from "../utils/test-utils";
import PrivacyPage from "../../app/(marketing)/privacy/page";
import TermsPage from "../../app/(marketing)/terms/page";
import CookiesPage from "../../app/(marketing)/cookies/page";
import LegalDocumentPage from "../../app/(marketing)/_components/LegalDocumentPage";
import { legalPathForSlug } from "../../lib/legalSyntheticPost";
import messages from "../../messages/en/index";
vi.mock("../../lib/requestSiteOrigin", () => ({
getRequestSiteOrigin: async () => "https://communityrule.info",
}));
vi.mock("../../app/components/sections/ContentBanner", () => ({
default: ({ post, variant, updatedLabel }) => (
<section data-testid="content-banner" data-variant={variant}>
@@ -21,6 +25,18 @@ vi.mock("../../app/components/sections/ContentBanner", () => ({
),
}));
async function renderLegalPage(
slug: "privacy" | "terms" | "cookies",
page: (typeof messages.pages)[typeof slug],
) {
const ui = await LegalDocumentPage({
slug,
path: legalPathForSlug(slug),
page,
});
return render(ui);
}
describe("legal document pages", () => {
test("privacy copy names Umami and cookieless counts", () => {
const collect = messages.pages.privacy.sections.find(
@@ -30,8 +46,32 @@ describe("legal document pages", () => {
expect(collect?.paragraphs.join(" ")).toMatch(/sets no cookies/);
});
test("privacy page covers hosting, recommendations, and campus privacy", () => {
render(<PrivacyPage />);
test("privacy copy does not say stakeholder or wizard", () => {
const text = JSON.stringify(messages.pages.privacy);
expect(text).not.toMatch(/stakeholder/i);
expect(text).not.toMatch(/wizard/i);
});
test("privacy page 404s while the flag is off", () => {
const previous = process.env.ENABLE_PRIVACY_POLICY;
const previousPublic = process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
delete process.env.ENABLE_PRIVACY_POLICY;
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
try {
expect(() => PrivacyPage()).toThrow("NEXT_NOT_FOUND");
} finally {
if (previous === undefined) delete process.env.ENABLE_PRIVACY_POLICY;
else process.env.ENABLE_PRIVACY_POLICY = previous;
if (previousPublic === undefined) {
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
} else {
process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY = previousPublic;
}
}
});
test("privacy page covers hosting, recommendations, and campus privacy", async () => {
await renderLegalPage("privacy", messages.pages.privacy);
const page = messages.pages.privacy;
expect(screen.getByTestId("content-banner")).toHaveAttribute(
@@ -71,8 +111,8 @@ describe("legal document pages", () => {
);
});
test("terms page covers licenses and the templates API, not ranking", () => {
render(<TermsPage />);
test("terms page covers licenses and the templates API, not ranking", async () => {
await renderLegalPage("terms", messages.pages.terms);
const page = messages.pages.terms;
expect(
@@ -105,8 +145,8 @@ describe("legal document pages", () => {
).toHaveAttribute("href", "/api/templates");
});
test("cookies settings page explains there are no optional cookies", () => {
render(<CookiesPage />);
test("cookies settings page explains there are no optional cookies", async () => {
await renderLegalPage("cookies", messages.pages.cookies);
const page = messages.pages.cookies;
expect(
@@ -115,11 +155,15 @@ describe("legal document pages", () => {
expect(
screen.getByRole("heading", { level: 2, name: "The session cookie" }),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "The claim cookie" }),
).toBeInTheDocument();
expect(
screen.getByText(/There are no advertising or analytics cookies to turn off/),
).toBeInTheDocument();
expect(screen.getByText(/cr_session/)).toBeInTheDocument();
expect(screen.getByText(/cr_rule_claim/)).toBeInTheDocument();
expect(JSON.stringify(page)).not.toMatch(/magic link/i);
expect(
screen.getAllByRole("link", { name: "Privacy Policy" })[0],
).toHaveAttribute("href", "/privacy");
+46 -1
View File
@@ -1,6 +1,9 @@
import { describe, expect, it } from "vitest";
import { MAGIC_LINK_TTL_MINUTES } from "../../lib/privacyRetention";
import { buildMagicLinkMail } from "../../lib/server/magicLinkMail";
import {
buildEmailChangeMail,
buildMagicLinkMail,
} from "../../lib/server/magicLinkMail";
const VERIFY_URL =
"https://communityrule.info/api/auth/magic-link/verify?token=abc";
@@ -32,4 +35,46 @@ describe("buildMagicLinkMail", () => {
expect(mail.html).not.toContain("Hi ");
expect(mail.text).not.toContain("Hi ");
});
it("omits the privacy link while the policy flag is off", () => {
const previous = process.env.ENABLE_PRIVACY_POLICY;
const previousPublic = process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
delete process.env.ENABLE_PRIVACY_POLICY;
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
try {
const off = buildMagicLinkMail({
verifyUrl: VERIFY_URL,
origin: "https://communityrule.info",
});
expect(off.html).not.toContain("/privacy");
expect(off.text).not.toContain("/privacy");
expect(off.html).toContain("/about");
} finally {
if (previous === undefined) delete process.env.ENABLE_PRIVACY_POLICY;
else process.env.ENABLE_PRIVACY_POLICY = previous;
if (previousPublic === undefined) {
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
} else {
process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY = previousPublic;
}
}
});
});
describe("buildEmailChangeMail", () => {
const mail = buildEmailChangeMail({
verifyUrl: "https://communityrule.info/api/user/email-change/verify?token=abc",
origin: "https://communityrule.info",
});
it("matches the login email chrome with CommunityRule copy", () => {
expect(mail.subject).toBe("Confirm your new CommunityRule email");
expect(mail.html).toContain("background:#000000");
expect(mail.html).toContain(">Confirm email</a>");
expect(mail.html).toContain("CommunityRule account");
expect(mail.text).toContain("CommunityRule account");
expect(mail.subject).not.toMatch(/Community Rule/);
expect(mail.html).not.toMatch(/Community Rule/);
expect(mail.text).not.toMatch(/Community Rule/);
});
});
+11 -3
View File
@@ -100,14 +100,22 @@ describe("resolveMailFrom", () => {
it("prefers SMTP_FROM, then CLOUDRON_MAIL_FROM", () => {
delete process.env.SMTP_FROM;
delete process.env.CLOUDRON_MAIL_FROM;
expect(resolveMailFrom()).toBe("noreply@localhost");
expect(resolveMailFrom()).toBe("CommunityRule <noreply@localhost>");
process.env.CLOUDRON_MAIL_FROM = "staging.app@communityrule.info";
expect(resolveMailFrom()).toBe("staging.app@communityrule.info");
expect(resolveMailFrom()).toBe(
"CommunityRule <staging.app@communityrule.info>",
);
process.env.SMTP_FROM = "Community Rule <hello@communityrule.info>";
expect(resolveMailFrom()).toBe(
"Community Rule <hello@communityrule.info>",
"CommunityRule <hello@communityrule.info>",
);
});
it("puts CommunityRule on a bare mailbox", () => {
delete process.env.SMTP_FROM;
process.env.CLOUDRON_MAIL_FROM = "hello@communityrule.info";
expect(resolveMailFrom()).toBe("CommunityRule <hello@communityrule.info>");
});
});
@@ -6,6 +6,7 @@ const sendOrganizerInquiryNotificationMock = vi.fn();
vi.mock("../../lib/server/mail", () => ({
sendOrganizerInquiryNotification: (...args: unknown[]) =>
sendOrganizerInquiryNotificationMock(...args),
resolveMailFrom: () => "CommunityRule <noreply@localhost>",
}));
const rateLimitKeyMock = vi.hoisted(() =>
@@ -54,6 +55,7 @@ describe("POST /api/organizer-inquiry", () => {
expect(body).toEqual({ ok: true });
expect(sendOrganizerInquiryNotificationMock).toHaveBeenCalledTimes(1);
const arg = sendOrganizerInquiryNotificationMock.mock.calls[0][0];
expect(arg.fromEmail).toBe("CommunityRule <noreply@localhost>");
expect(arg.visitorEmail).toBe("visitor@example.com");
expect(arg.message).toBe("How do we run consensus meetings?");
});
+40
View File
@@ -0,0 +1,40 @@
import { afterEach, describe, expect, it } from "vitest";
import {
isPrivacyPolicyEnabled,
privacyPolicyUrl,
} from "../../lib/privacyPolicyEnabled";
const KEYS = ["ENABLE_PRIVACY_POLICY", "NEXT_PUBLIC_ENABLE_PRIVACY_POLICY"] as const;
const ORIGINAL = Object.fromEntries(
KEYS.map((key) => [key, process.env[key]]),
) as Record<(typeof KEYS)[number], string | undefined>;
afterEach(() => {
for (const key of KEYS) {
const original = ORIGINAL[key];
if (original === undefined) delete process.env[key];
else process.env[key] = original;
}
});
describe("isPrivacyPolicyEnabled", () => {
it("is off unless a flag is the string true", () => {
delete process.env.ENABLE_PRIVACY_POLICY;
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
expect(isPrivacyPolicyEnabled()).toBe(false);
expect(privacyPolicyUrl("https://communityrule.info")).toBeNull();
process.env.ENABLE_PRIVACY_POLICY = "yes";
expect(isPrivacyPolicyEnabled()).toBe(false);
process.env.ENABLE_PRIVACY_POLICY = "true";
expect(isPrivacyPolicyEnabled()).toBe(true);
expect(privacyPolicyUrl("https://communityrule.info/")).toBe(
"https://communityrule.info/privacy",
);
delete process.env.ENABLE_PRIVACY_POLICY;
process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY = "true";
expect(isPrivacyPolicyEnabled()).toBe(true);
});
});
+20
View File
@@ -55,4 +55,24 @@ describe("buildPublicSitemap", () => {
lastModified: updatedAt,
});
});
it("omits /privacy while the policy flag is off", () => {
const previous = process.env.ENABLE_PRIVACY_POLICY;
const previousPublic = process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
delete process.env.ENABLE_PRIVACY_POLICY;
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
try {
const urls = buildPublicSitemap().map((entry) => entry.url);
expect(urls).not.toContain(sitemapUrl("/privacy"));
expect(urls).toContain(sitemapUrl("/terms"));
} finally {
if (previous === undefined) delete process.env.ENABLE_PRIVACY_POLICY;
else process.env.ENABLE_PRIVACY_POLICY = previous;
if (previousPublic === undefined) {
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
} else {
process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY = previousPublic;
}
}
});
});
+1 -1
View File
@@ -10,7 +10,7 @@ describe("useCaseTemplateDuplicateTitle", () => {
it("falls back when the source title is empty", () => {
expect(useCaseTemplateDuplicateTitle(" ")).toBe(
"Community Rule Template (Copy)",
"CommunityRule Template (Copy)",
);
});
});
@@ -153,6 +153,7 @@ describe("POST /api/user/email-change/request", () => {
expect(sendEmailChangeEmailMock).toHaveBeenCalledWith(
"new@x.com",
expect.stringContaining("/api/user/email-change/verify?token="),
"https://x.test",
);
});