Files
community-rule/tests/unit/umami.test.ts
T
adilallo d9c475a967 Give finished Rules a print path, folded launch counts, and a two-day follow-up.
Export is PDF, RULE.md, and Print on US Letter, with every shared term, no member names, and a takeaway that points at Ask an organizer. Finished Rules keep type and place so the team can read folded counts without a database, Umami can sit beside the app with no cookies, and the person who holds the pen gets working PDF and RULE.md links 48 hours later.
2026-11-10 18:32:33 -07:00

42 lines
1.4 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { umamiTracker } from "../../lib/umami";
const KEYS = ["NEXT_PUBLIC_UMAMI_SRC", "NEXT_PUBLIC_UMAMI_WEBSITE_ID"] 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("umamiTracker", () => {
it("is off when either env var is missing", () => {
delete process.env.NEXT_PUBLIC_UMAMI_SRC;
delete process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID;
expect(umamiTracker()).toBeNull();
process.env.NEXT_PUBLIC_UMAMI_SRC = "https://analytics.example.com/script.js";
expect(umamiTracker()).toBeNull();
});
it("returns the script URL and website id", () => {
process.env.NEXT_PUBLIC_UMAMI_SRC =
"https://analytics.example.com/script.js";
process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID = "site-1";
expect(umamiTracker()).toEqual({
src: "https://analytics.example.com/script.js",
websiteId: "site-1",
});
});
it("rejects a non-http script URL", () => {
process.env.NEXT_PUBLIC_UMAMI_SRC = "javascript:alert(1)";
process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID = "site-1";
expect(umamiTracker()).toBeNull();
});
});