import { describe, expect, it } from "vitest"; import { hostForKnot } from "$lib/api/_request"; describe("hostForKnot", () => { it.each([ ["did:web:knot2.example.com", "knot2.example.com"], ["did:web:KNOT2.EXAMPLE.COM", "knot2.example.com"], ["did:web:knot.example.com%3A8443", "knot.example.com:8443"], ["did:web:knot.example.com%3a8443", "knot.example.com:8443"], ["did:web:localhost%3A3000", "localhost:3000"], ["knot2.example.com", "knot2.example.com"], ["knot.example.com:8443", "knot.example.com:8443"], ["localhost", "localhost"], ["localhost:3000", "localhost:3000"], ["127.0.0.1:8000", "127.0.0.1:8000"] ])("normalizes %s to %s", (input, expected) => { expect(hostForKnot(input)).toBe(expected); }); it.each([ "did:plc:iz6r437h6kndu44y7u7f7rly", "https://knot2.example.com", "knot2.example.com/path", "did:web:", "did:web:foo/bar", "did:web:knot.dev:8443", "garbage text", ":::", "", " ", "knot..dev", "-knot.dev", "knot.dev:99999", "knot.dev:0", "foo@bar.com" ])("rejects garbage %j", (input) => { expect(() => hostForKnot(input)).toThrow(); }); });