import { describe, expect, it } from 'vitest'; import { buildXfxGoodsPayload } from './xfx-goods.util'; describe('buildXfxGoodsPayload', () => { it('瓶装:品名 + 酒精度,件数等于购买瓶数', () => { expect( buildXfxGoodsPayload({ productName: '杜康老窖', productSpec: '单瓶', physicalSpec: '500ml | 53度', quantity: 2, bottlesPerUnit: 1, }), ).toEqual({ goodsName: '杜康老窖 500ml | 53度 单瓶', goodsNum: 2, }); }); it('箱装:追加包装规格,件数换算为瓶当量', () => { expect( buildXfxGoodsPayload({ productName: '杜康老窖', productSpec: '整箱', physicalSpec: '500ml | 53度', quantity: 2, bottlesPerUnit: 6, }), ).toEqual({ goodsName: '杜康老窖 500ml | 53度 整箱', goodsNum: 12, }); }); it('无度数:回落 SKU 规格;再缺失则只用品名', () => { expect( buildXfxGoodsPayload({ productName: '杜康老窖', productSpec: '单瓶', physicalSpec: null, quantity: 3, bottlesPerUnit: 1, }), ).toEqual({ goodsName: '杜康老窖 单瓶', goodsNum: 3, }); expect( buildXfxGoodsPayload({ productName: '杜康老窖', productSpec: ' ', physicalSpec: undefined, quantity: 1, bottlesPerUnit: 1, }), ).toEqual({ goodsName: '杜康老窖', goodsNum: 1, }); }); it('规格重复:不把相同文案拼两次', () => { expect( buildXfxGoodsPayload({ productName: '杜康老窖', productSpec: '500ml | 53度', physicalSpec: '500ml | 53度', quantity: 1, bottlesPerUnit: 1, }), ).toEqual({ goodsName: '杜康老窖 500ml | 53度', goodsNum: 1, }); expect( buildXfxGoodsPayload({ productName: '杜康老窖', productSpec: '53度', physicalSpec: '500ml | 53度', quantity: 1, bottlesPerUnit: 1, }).goodsName, ).toBe('杜康老窖 500ml | 53度'); }); });