// src/lib/sites/url.test.ts
import { describe, expect, test } from "bun:test";
import { cleanDomain, splitUrl } from "./url";

describe("cleanDomain", () => {
  test("strips scheme, www, trailing slash, lowercases", () => {
    expect(cleanDomain("HTTPS://WWW.Foo.com/")).toBe("foo.com");
    expect(cleanDomain("  http://foo.com  ")).toBe("foo.com");
    expect(cleanDomain("foo.com")).toBe("foo.com");
  });
});

describe("splitUrl", () => {
  test("https + www", () => {
    expect(splitUrl("https://www.foo.com")).toEqual({
      scheme: "https://www.",
      domain: "foo.com",
    });
  });
  test("http no www", () => {
    expect(splitUrl("http://foo.com")).toEqual({
      scheme: "http://",
      domain: "foo.com",
    });
  });
  test("https no www", () => {
    expect(splitUrl("https://foo.com")).toEqual({
      scheme: "https://",
      domain: "foo.com",
    });
  });
  test("round-trips through scheme+domain", () => {
    const { scheme, domain } = splitUrl("https://www.foo.com");
    expect(`${scheme}${domain}`).toBe("https://www.foo.com");
  });
  test("empty url falls back to https://", () => {
    expect(splitUrl("")).toEqual({ scheme: "https://", domain: "" });
  });
});
