import { describe, expect, it } from "vitest"; import { assertFourTiers, normalizeToFourTiers, } from "@/modules/quote/quote-completeness"; const FOUR_TIERS = [ { service_level: "standard", rate_option: "lowest" }, { service_level: "standard", rate_option: "fastest" }, { service_level: "guaranteed", rate_option: "lowest" }, { service_level: "guaranteed", rate_option: "fastest" }, ]; describe("assertFourTiers", () => { it("4 档 → 通过", () => { expect(() => assertFourTiers(FOUR_TIERS)).not.toThrow(); }); it("仅 2 档 lowest → normalize 后通过", () => { expect(() => assertFourTiers([ { service_level: "standard", rate_option: "lowest" }, { service_level: "guaranteed", rate_option: "lowest" }, ]), ).not.toThrow(); }); it("缺 guaranteed 整档 → 仅含 standard/lowest 仍通过", () => { expect(() => assertFourTiers( FOUR_TIERS.filter((t) => t.service_level !== "guaranteed"), ), ).not.toThrow(); }); it("有 guaranteed/lowest 无 fastest → 通过", () => { const incomplete = FOUR_TIERS.filter( (t) => !(t.service_level === "guaranteed" && t.rate_option === "fastest"), ); expect(() => assertFourTiers(incomplete)).not.toThrow(); }); it("含 bestValue 扩展档 → 保留 API 返回的全部档位", () => { const six = [ ...FOUR_TIERS, { service_level: "standard", rate_option: "bestValue" }, { service_level: "guaranteed", rate_option: "bestValue" }, ]; const normalized = normalizeToFourTiers(six); expect(normalized).toHaveLength(6); expect(() => assertFourTiers(six)).not.toThrow(); }); it("2+1 动态档位全部保留", () => { const tiers = [ { service_level: "standard", rate_option: "lowest" }, { service_level: "standard", rate_option: "fastest" }, { service_level: "guaranteed", rate_option: "lowest" }, ]; expect(normalizeToFourTiers(tiers)).toHaveLength(3); }); it("3+3 动态档位全部保留", () => { const tiers = [ { service_level: "standard", rate_option: "lowest" }, { service_level: "standard", rate_option: "fastest" }, { service_level: "standard", rate_option: "bestValue" }, { service_level: "guaranteed", rate_option: "lowest" }, { service_level: "guaranteed", rate_option: "fastest" }, { service_level: "guaranteed", rate_option: "bestValue" }, ]; expect(normalizeToFourTiers(tiers)).toHaveLength(6); }); });