import { describe, expect, it } from "vitest";
import {
  buildAeroflotSbSearchUrl,
  formatAeroflotRouteDate,
} from "./aeroflot.js";

describe("formatAeroflotRouteDate", () => {
  it("uses the date encoded in an offset-aware local timestamp", () => {
    expect(formatAeroflotRouteDate("2026-05-05T23:30:00-04:00")).toBe("20260505");
  });

  it("accepts compact yyyyMMdd dates", () => {
    expect(formatAeroflotRouteDate("20260505")).toBe("20260505");
  });
});

describe("buildAeroflotSbSearchUrl", () => {
  it("uses Angular's hardcoded ru-ru SB route", () => {
    const url = buildAeroflotSbSearchUrl({
      departure: "SVO",
      arrival: "LED",
      date: "20260505",
    });

    expect(url).toContain("https://www.aeroflot.ru/sb/app/ru-ru#/search?");
    expect(url).toContain("routes=SVO.20260505.LED");
    expect(url).toContain("autosearch=Y");
  });

  it("omits the date segment when no date is supplied", () => {
    const url = buildAeroflotSbSearchUrl({
      departure: "MOW",
      arrival: "LED",
      date: null,
    });

    expect(url).toContain("routes=MOW.LED");
  });
});
