import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; const svc = readFileSync(new URL('../src/services/orderWorkflowFulfillmentService.ts', import.meta.url), 'utf8'); describe('结束配送库存口径', () => { it('读取 marker/inbound/outbound;30/40 跳过,45 已扣跳过/未扣软扣,无入库普通单跳过', () => { const start = svc.indexOf('const settleCtx = await db.query('); const end = svc.indexOf('const now = new Date();', start); const fn = svc.slice(start, end); expect(fn).toContain('auto_advanced_from_status'); expect(fn).toContain('has_inbound'); expect(fn).toContain('has_outbound'); expect(fn).toContain('(marker === 30 || marker === 40) && !hasStockCover'); expect(fn).toContain('has_stock_cover'); expect(fn).toContain('marker === 45'); expect(fn).toContain('fallbackToRequiredQty = true'); expect(fn).toContain('else if (!hasInbound && !hasStockCover)'); }); it('结案扣库必须软扣,不能因库存不足阻断置 90', () => { const start = svc.indexOf('const settleCtx = await db.query('); const end = svc.indexOf('const now = new Date();', start); const fn = svc.slice(start, end); expect(fn).toContain('options?.softInventorySettle === true || !hasInbound || marker === 45'); expect(fn).toContain('fallbackToRequiredQty'); }); });