import { describe, expect, it } from "vitest";
import {
  isMothershipWeekendIso,
  isMothershipWeightEachAllowed,
  normalizeMothershipReadyDateIso,
  snapMothershipReadyDateToWeekday,
} from "@/lib/mothership/logged-in-constraints";

describe("mothership logged-in constraints", () => {
  it("识别周末", () => {
    expect(isMothershipWeekendIso("2026-07-18")).toBe(true); // Sat
    expect(isMothershipWeekendIso("2026-07-19")).toBe(true); // Sun
    expect(isMothershipWeekendIso("2026-07-20")).toBe(false); // Mon
  });

  it("周末拨到周一", () => {
    expect(snapMothershipReadyDateToWeekday("2026-07-18")).toBe("2026-07-20");
    expect(snapMothershipReadyDateToWeekday("2026-07-19")).toBe("2026-07-20");
    expect(snapMothershipReadyDateToWeekday("2026-07-20")).toBe("2026-07-20");
  });

  it("单件重量 ≤5000", () => {
    expect(isMothershipWeightEachAllowed(5000)).toBe(true);
    expect(isMothershipWeightEachAllowed(5000.01)).toBe(false);
    expect(isMothershipWeightEachAllowed(50)).toBe(true);
  });

  it("normalize 周末日期", () => {
    expect(normalizeMothershipReadyDateIso("2026-07-19")).toBe("2026-07-20");
    expect(normalizeMothershipReadyDateIso("2026-07-20")).toBe("2026-07-20");
    expect(normalizeMothershipReadyDateIso(undefined)).toBeUndefined();
  });
});
