Something went wrong. Try again.
A downstream fork of Tranquil PDS for use in margin.cafe
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import { describe, expect, it } from "vitest";import { composeHandle, handleEndsWith, normalizeSuffix } from "../lib/handle.ts";
describe("handle helpers", () => { describe("normalizeSuffix", () => { it("adds a dot if missing", () => { expect(normalizeSuffix("margin.cafe")).toBe(".margin.cafe"); });
it("keeps existing dot", () => { expect(normalizeSuffix(".margin.cafe")).toBe(".margin.cafe"); });
it("handles empty input", () => { expect(normalizeSuffix("")).toBe(""); expect(normalizeSuffix(" ")).toBe(""); });
it("trims whitespace", () => { expect(normalizeSuffix(" margin.cafe ")).toBe(".margin.cafe"); expect(normalizeSuffix(" .margin.cafe ")).toBe(".margin.cafe"); }); });
describe("composeHandle", () => { it("composes local handle and undotted suffix", () => { expect(composeHandle("alice", "margin.cafe")).toBe("alice.margin.cafe"); });
it("composes local handle and dotted suffix", () => { expect(composeHandle("alice", ".margin.cafe")).toBe("alice.margin.cafe"); });
it("returns handle as-is if it already contains a dot", () => { expect(composeHandle("alice.com", "margin.cafe")).toBe("alice.com"); expect(composeHandle("alice.margin.cafe", ".margin.cafe")).toBe("alice.margin.cafe"); });
it("handles empty suffix", () => { expect(composeHandle("alice", "")).toBe("alice"); });
it("handles empty handle", () => { expect(composeHandle("", "margin.cafe")).toBe(""); }); it("trims handle and suffix", () => { expect(composeHandle(" alice ", " margin.cafe ")).toBe("alice.margin.cafe"); }); });
describe("handleEndsWith", () => { it("returns true for matching undotted domain", () => { expect(handleEndsWith("alice.margin.cafe", "margin.cafe")).toBe(true); });
it("returns true for matching dotted domain", () => { expect(handleEndsWith("alice.margin.cafe", ".margin.cafe")).toBe(true); });
it("returns false if dot is missing in handle", () => { // "alicemargin.cafe" does not end with ".margin.cafe" expect(handleEndsWith("alicemargin.cafe", "margin.cafe")).toBe(false); });
it("returns false for non-matching domain", () => { expect(handleEndsWith("alice.margin.cafe", "other.com")).toBe(false); });
it("handles empty inputs", () => { expect(handleEndsWith("", "margin.cafe")).toBe(false); expect(handleEndsWith("alice.margin.cafe", "")).toBe(false); }); });});