import { describe, expect, it } from "vitest";
import { canonicalizeJobUrl } from "./job-url-canonical";

describe("canonicalizeJobUrl", () => {
  it("strips tracking query params and normalizes host", () => {
    const a =
      "https://www.example.com/jobs/123?utm_source=linkedin&role=eng&utm_medium=social";
    const b = "http://example.com/jobs/123?role=eng";
    expect(canonicalizeJobUrl(a)).toBe(canonicalizeJobUrl(b));
  });

  it("removes trailing slash on path", () => {
    expect(canonicalizeJobUrl("https://example.com/path/")).toBe(
      "https://example.com/path",
    );
  });

  it("sorts query params for stable comparison", () => {
    const a = "https://example.com/x?b=2&a=1";
    const b = "https://example.com/x?a=1&b=2";
    expect(canonicalizeJobUrl(a)).toBe(canonicalizeJobUrl(b));
  });

  it("returns trimmed non-URL strings unchanged", () => {
    expect(canonicalizeJobUrl("  not a url  ")).toBe("not a url");
  });
});
