import { describe, expect, it } from "vitest"; import { findMothershipAvgWeightBlockMessage, findMothershipCargoWeightBlockMessage, findMothershipTotalWeightBlockMessage, isMothershipAverageWeightEachAllowed, isMothershipTotalWeightAllowed, isMothershipWeekendIso, isMothershipWeightEachAllowed, MOTHERSHIP_AVG_WEIGHT_BLOCK_MESSAGE, MOTHERSHIP_MAX_TOTAL_WEIGHT_LB, MOTHERSHIP_TOTAL_WEIGHT_BLOCK_MESSAGE, normalizeMothershipReadyDateIso, resolveMothershipAverageWeightEachLb, snapMothershipReadyDateToWeekday, sumMothershipTotalWeightLb, ceilMothershipNumeric, hasMothershipFractionalPart, } from "@/lib/mothership/logged-in-constraints"; describe("mothership logged-in constraints", () => { it("小数向上取整(进一)", () => { expect(ceilMothershipNumeric(25.68)).toBe(26); expect(ceilMothershipNumeric(25)).toBe(25); expect(ceilMothershipNumeric(40.01)).toBe(41); expect(hasMothershipFractionalPart(25.68)).toBe(true); expect(hasMothershipFractionalPart(26)).toBe(false); }); 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(isMothershipAverageWeightEachAllowed(5000)).toBe(true); expect(isMothershipAverageWeightEachAllowed(5000.01)).toBe(false); expect(isMothershipWeightEachAllowed(50)).toBe(true); expect(resolveMothershipAverageWeightEachLb(4800, 10)).toBe(4800); }); it("整票总重 ≤45000 可询价", () => { expect(isMothershipTotalWeightAllowed(45000)).toBe(true); expect(isMothershipTotalWeightAllowed(45001)).toBe(false); expect(sumMothershipTotalWeightLb([{ weightLb: 1000, quantity: 45 }])).toBe( 45000, ); expect( findMothershipTotalWeightBlockMessage([ { weightLb: 1000, quantity: 46 }, ]), ).toBe(MOTHERSHIP_TOTAL_WEIGHT_BLOCK_MESSAGE); }); it("多行任一超均重则阻断", () => { expect( findMothershipAvgWeightBlockMessage([ { weightLb: 400, quantity: 30 }, { weightLb: 5001, quantity: 1 }, ]), ).toBe(MOTHERSHIP_AVG_WEIGHT_BLOCK_MESSAGE); expect( findMothershipAvgWeightBlockMessage([{ weightLb: 400, quantity: 40 }]), ).toBeNull(); }); it("均重与总重合并校验", () => { expect( findMothershipCargoWeightBlockMessage([ { weightLb: 1200, quantity: 37 }, ]), ).toBeNull(); expect( findMothershipCargoWeightBlockMessage([ { weightLb: 1200, quantity: 38 }, ]), ).toBe(MOTHERSHIP_TOTAL_WEIGHT_BLOCK_MESSAGE); expect(MOTHERSHIP_MAX_TOTAL_WEIGHT_LB).toBe(45000); }); it("normalize 周末日期", () => { expect(normalizeMothershipReadyDateIso("2026-07-19")).toBe("2026-07-20"); expect(normalizeMothershipReadyDateIso("2026-07-20")).toBe("2026-07-20"); expect(normalizeMothershipReadyDateIso(undefined)).toBeUndefined(); }); });