import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; describe('ensurePreparationForAssign 不复用无货备货', () => { const source = readFileSync( new URL('../src/services/purchaseSupplierAssignService.ts', import.meta.url), 'utf8' ); it('查找已有备货排除 is_stockout / transferred_to_purchase', () => { const fnStart = source.indexOf('async function ensurePreparationForAssign'); const fnEnd = source.indexOf('export async function assignPurchaseOrderToSupplier'); expect(fnStart).toBeGreaterThanOrEqual(0); expect(fnEnd).toBeGreaterThan(fnStart); const body = source.slice(fnStart, fnEnd); expect(body).toContain('COALESCE(is_stockout, false) = false'); expect(body).toContain('COALESCE(transferred_to_purchase, false) = false'); const selectCount = body.split('SELECT id FROM supplier_preparations').length - 1; expect(selectCount).toBe(2); const stockoutCount = body.split('COALESCE(is_stockout, false) = false').length - 1; expect(stockoutCount).toBe(2); }); it('转供应商作废自采后删除未入库待验', () => { expect(source).toContain('deletePendingInspectionsForPurchaseCode'); }); });