import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; const read = (rel: string) => readFileSync(new URL(`../${rel}`, import.meta.url), 'utf8'); const svc = read('src/services/purchaseOperationService.ts'); const backfill = read('src/services/deliveryLoadingBackfillService.ts'); const picking = read('src/services/pickingService.ts'); const manual = read('src/routes/mobile/mobilePurchaseRoutes.ts'); describe('自动补完成采购允许 0 成本', () => { it('internal allowZeroCost 仅 status20 放行 0/未填,负数/NaN 仍拒', () => { expect(svc).toContain('allowZeroCost?: boolean'); expect(svc).toContain('const internalAllowZeroCost = input.allowZeroCost === true'); expect(svc).toContain('selfProcessed || warehouseDemand || internalAllowZeroCost'); expect(svc).toContain('!Number.isFinite(effectivePrice) || effectivePrice < 0'); expect(svc).toContain('if (actualPrice === null || actualPrice <= 0) actualPrice = 0'); }); it('自动补完成 4 处传 true;手工路由不传', () => { expect((backfill.match(/allowZeroCost: true/g) || []).length).toBe(3); expect((picking.match(/allowZeroCost: true/g) || []).length).toBe(1); expect(manual).not.toContain('allowZeroCost'); }); it('zeroPurchaseCost 清计划价逻辑认 internal flag', () => { expect(svc).toContain('if (internalAllowZeroCost || Boolean(flagRow.rows[0]?.self_processed)'); }); });