import { describe, expect, it } from 'vitest'; import { resolvePreparationInsertPrice } from '../src/services/orderAllocationService'; import { PREP_SUGGESTED_PRICE_SQL } from '../src/services/supplierPreparationOpenApiShape'; describe('resolvePreparationInsertPrice', () => { it('优先使用中标 supplyPrice', () => { expect(resolvePreparationInsertPrice(12.5, 3)).toBe(12.5); }); it('无中标价时回退历史成本', () => { expect(resolvePreparationInsertPrice(0, 4.2)).toBe(4.2); expect(resolvePreparationInsertPrice(undefined, 4.2)).toBe(4.2); expect(resolvePreparationInsertPrice(null, 4.2)).toBe(4.2); }); it('两者皆无效时为 0', () => { expect(resolvePreparationInsertPrice(0, 0)).toBe(0); expect(resolvePreparationInsertPrice(undefined, -1)).toBe(0); }); }); describe('PREP_SUGGESTED_PRICE_SQL', () => { it('包含中标价兜底(bid_awards)', () => { expect(PREP_SUGGESTED_PRICE_SQL).toMatch(/bid_awards/); expect(PREP_SUGGESTED_PRICE_SQL).toMatch(/bid_rounds/); expect(PREP_SUGGESTED_PRICE_SQL).toMatch(/unit_price/); // 本单优先于周期 expect(PREP_SUGGESTED_PRICE_SQL).toMatch(/cycle_mode\s*=\s*'period'/); }); });