import { describe, expect, it } from "vitest"; import { normalizeUrl } from "~/lib/url"; describe("normalizeUrl", () => { it("normalizes domains, drops fragments, removes tracking params, and sorts query params", () => { expect(normalizeUrl("HTTPS://WWW.Example.COM:443/story?b=2&utm_source=x&a=1#comments")).toEqual({ url: "https://www.example.com/story?a=1&b=2", normalizedUrl: "https://www.example.com/story?a=1&b=2", sourceDomain: "example.com", }); }); it("rejects unsupported protocols", () => { expect(() => normalizeUrl("ftp://example.com/file")).toThrow("Only HTTP and HTTPS"); }); it("rejects malformed URLs", () => { expect(() => normalizeUrl("not a url")).toThrow("Enter a valid URL"); }); });