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); }); });