import { describe, expect, it } from "vitest"; import { parseMarkupInput } from "@/modules/pricing/markup-validation"; describe("parseMarkupInput", () => { it("默认百分比模式", () => { const result = parseMarkupInput({ markup_percent: 10 }); expect(result).toEqual({ markupType: "percent", markupPercent: 10, markupFixedAmount: null, }); }); it("固定金额模式", () => { const result = parseMarkupInput({ markup_type: "fixed", markup_fixed_amount: 50.5, }); expect(result).toEqual({ markupType: "fixed", markupPercent: 0, markupFixedAmount: 50.5, }); }); it("比例超过 30% 拒绝", () => { const result = parseMarkupInput({ markup_percent: 30.1 }); expect(result).toMatchObject({ code: "PERCENT_TOO_HIGH", message: "加价比例不能超过 30%", }); }); it("支持 0.01% 步长", () => { const result = parseMarkupInput({ markup_percent: 0.01 }); expect(result).toEqual({ markupType: "percent", markupPercent: 0.01, markupFixedAmount: null, }); }); it("百分比四舍五入到两位小数", () => { const result = parseMarkupInput({ markup_percent: 1.235 }); expect(result).toEqual({ markupType: "percent", markupPercent: 1.24, markupFixedAmount: null, }); }); });