Files
community-rule/tests/unit/privacyPolicyEnabled.test.ts
T
adilallo 81ad287c24 Keep /privacy off unless the runtime flag is on, and show that link in the footer story.
A build-time public env value was enough to publish the page, and the footer interaction story still looked for a link the component hides by default.
2026-11-20 15:40:05 -07:00

45 lines
1.5 KiB
TypeScript

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(false);
expect(privacyPolicyUrl("https://communityrule.info")).toBeNull();
process.env.ENABLE_PRIVACY_POLICY = "true";
expect(isPrivacyPolicyEnabled()).toBe(true);
});
});