Files
community-rule/tests/unit/sharePaths.test.ts
T
adilallo 5cbda35e32 Start every Rule private, with a rotating link and files that follow its readers.
New Rules stay off lists until the person who holds the pen turns on a share link, or the team features one. Uploaded files are readable only by those readers, stripped of location metadata, and deleted with the Rule, draft, or account.
2026-11-09 19:54:04 -07:00

47 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { RULE_VISIBILITY } from "../../lib/ruleVisibility";
import {
buildShareRuleUrl,
formatShareUrlDisplay,
isShareSlug,
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");
});
});