import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; const svc = readFileSync(new URL('../src/services/inventoryOutboundService.ts', import.meta.url), 'utf8'); describe('软扣允许部分扣减', () => { it('软扣传 allowPartial;可用>0 时先扣可用,不因缺口提前抛错', () => { expect(svc).toContain('allowPartial?: boolean'); expect(svc).toContain('allowPartial: softInventory'); expect(svc).toContain('!input.allowPartial || claimable <= 1e-9'); }); it('部分扣减也标记 deductedAny,尾差记 softSkipped;硬扣仍走原错误', () => { expect(svc).toContain('deductedAny = true;'); expect(svc).toContain("reason: softSkipped.length ? 'partial_soft_skip'"); expect(svc).toContain("if (softInventory && (error?.code === 'inventory_outbound'"); }); });