import { describe, expect, it } from "vitest";
import {
  defaultFlockPickupDateIso,
  flockPickupDateValidationMessageFromDisplay,
  flockPickupDateValidationMessageFromIso,
  isFlockPickupDateOnOrAfterToday,
  minFlockPickupDateIso,
} from "@/lib/flock/pickup-date";

describe("flock pickup date", () => {
  it("今天及以后合法", () => {
    const today = minFlockPickupDateIso();
    expect(isFlockPickupDateOnOrAfterToday(today)).toBe(true);
    expect(flockPickupDateValidationMessageFromIso(today)).toBeNull();
    expect(
      flockPickupDateValidationMessageFromIso(defaultFlockPickupDateIso()),
    ).toBeNull();
  });

  it("早于今天拒绝", () => {
    const d = new Date();
    d.setDate(d.getDate() - 1);
    const yyyy = d.getFullYear();
    const mm = String(d.getMonth() + 1).padStart(2, "0");
    const dd = String(d.getDate()).padStart(2, "0");
    const iso = `${yyyy}-${mm}-${dd}`;
    expect(isFlockPickupDateOnOrAfterToday(iso)).toBe(false);
    expect(flockPickupDateValidationMessageFromIso(iso)).toMatch(/不能早于今天/);
    expect(
      flockPickupDateValidationMessageFromDisplay(`${mm}/${dd}/${yyyy}`),
    ).toMatch(/不能早于今天/);
  });

  it("周六周日拒绝", () => {
    expect(flockPickupDateValidationMessageFromIso("2026-07-18")).toMatch(
      /周六或周日/,
    );
    expect(flockPickupDateValidationMessageFromDisplay("07/19/2026")).toMatch(
      /周六或周日/,
    );
    expect(flockPickupDateValidationMessageFromIso("2026-07-20")).toBeNull();
  });

  it("默认值为工作日", () => {
    expect(flockPickupDateValidationMessageFromIso(defaultFlockPickupDateIso())).toBeNull();
  });
});
