import { describe, it, expect } from "vitest";
import { buildBuyTicketUrl, escapeHtml } from "./buyTicketUrl.js";

describe("buildBuyTicketUrl", () => {
  it("builds a URL with the correct base", () => {
    const url = buildBuyTicketUrl("MOW", "LED", "20260501");
    expect(url.startsWith("https://www.aeroflot.ru/sb/app/ru-ru#/search?")).toBe(true);
  });

  it("includes the routes triple dep.date.arr", () => {
    const url = buildBuyTicketUrl("MOW", "LED", "20260501");
    expect(url).toContain("routes=MOW.20260501.LED");
  });

  it("includes the stable UTM and adults/cabin params", () => {
    const url = buildBuyTicketUrl("MOW", "LED", "20260501");
    expect(url).toContain("adults=1");
    expect(url).toContain("cabin=economy");
    expect(url).toContain("autosearch=Y");
    expect(url).toContain("utm_source=aflwebbot");
  });
});

describe("escapeHtml", () => {
  it("escapes &, <, >, and double-quote", () => {
    expect(escapeHtml("A & B < C > D \"E\"")).toBe(
      "A &amp; B &lt; C &gt; D &quot;E&quot;",
    );
  });

  it("returns the input unchanged when no special chars", () => {
    expect(escapeHtml("Москва")).toBe("Москва");
  });
});
