Files
community-rule/tests/unit/sharePaths.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

64 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { RULE_VISIBILITY } from "../../lib/ruleVisibility";
import {
ASK_ORGANIZER_HASH,
askOrganizerUrl,
buildShareRuleUrl,
formatShareUrlDisplay,
isShareSlug,
ruleExportMarkdownUrl,
ruleExportPdfUrl,
shareCopyUrl,
shareRulePath,
} from "../../lib/sharePaths";
describe("sharePaths", () => {
it("accepts the rotating slug shape", () => {
expect(isShareSlug("k7f2-9qxm")).toBe(true);
expect(isShareSlug("K7F2-9QXM")).toBe(false);
expect(isShareSlug("not-a-slug")).toBe(false);
});
it("builds /r/{slug} URLs and the display host+path", () => {
expect(shareRulePath("k7f2-9qxm")).toBe("/r/k7f2-9qxm");
expect(buildShareRuleUrl("https://communityrule.info", "k7f2-9qxm")).toBe(
"https://communityrule.info/r/k7f2-9qxm",
);
expect(
formatShareUrlDisplay("https://communityrule.info", "k7f2-9qxm"),
).toBe("communityrule.info/r/k7f2-9qxm");
});
it("copies the slug URL once a link is on, otherwise the internal Rule URL", () => {
expect(
shareCopyUrl({
origin: "https://communityrule.info",
ruleId: "rule-1",
shareSlug: "k7f2-9qxm",
visibility: RULE_VISIBILITY.shared_by_link,
}),
).toBe("https://communityrule.info/r/k7f2-9qxm");
expect(
shareCopyUrl({
origin: "https://communityrule.info",
ruleId: "rule-1",
shareSlug: null,
visibility: RULE_VISIBILITY.private,
}),
).toBe("https://communityrule.info/rules/rule-1");
});
it("builds Ask an organizer and export URLs", () => {
expect(ASK_ORGANIZER_HASH).toBe("ask-organizer");
expect(askOrganizerUrl("https://communityrule.info/")).toBe(
"https://communityrule.info/#ask-organizer",
);
expect(
ruleExportPdfUrl("https://communityrule.info", "rule/1", "tok"),
).toBe("https://communityrule.info/api/rules/rule%2F1/export/pdf?t=tok");
expect(
ruleExportMarkdownUrl("https://communityrule.info", "id", "tok"),
).toBe("https://communityrule.info/api/rules/id/export/md?t=tok");
});
});