import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; /** * 「散客录单」单不得被**定时强推**推进(开发者 2026-10-15 要求: * 「我们不是有一个主数据不卡流程吗,他的那个推进,我们的独立进货单、散客单,给这两个下的不能被影响」)。 * * 现场核查结论(改前): * · 独立进货单:双重保护 —— 单订单判定有显式守卫,且批量扫描的「仍有未分配行」条件也挡得住 * (实测其明细 `supplier_code` 为空); * · 散客单:**没有**守卫,且批量扫描会命中 —— 实测其明细 `supplier_code='STOCK_COVER'`(非空, * 不被"未分配"挡)、SKU 非直送(不被"全单直送"挡)、`delivery_date` 有值 ⇒ 停在 30 的散客单 * 会被推成 50「待配送」。子步骤(验收/分拣/配送任务)虽有守卫,但**置 50 那一句没有**。 * * 本文件钉住两处收口:单订单判定 + 两个扫描口径(定时 + 「立即执行一次」测试口径)。 */ const src = readFileSync(new URL('../src/services/orderAutoAdvanceService.ts', import.meta.url), 'utf8'); describe('定时强推 · 散客单守卫', () => { it('单订单判定:散客单直接跳过,且发生在「补建验收单」与「置 50」之前', () => { expect(src).toContain("import { isRetailOrder, RETAIL_CUSTOMER_CODE } from './retailOrder';"); expect(src).toContain('if (await isRetailOrder(code, pool)) {'); expect(src).toContain("result.skippedReason = '散客单,跳过定时强推';"); const guardAt = src.indexOf('if (await isRetailOrder(code, pool)) {'); const ensureInspectionsAt = src.indexOf('const created = await ensureInspectionsForOrder(code, branch);'); const setFiftyAt = src.indexOf('SET order_status = 50,\n auto_advanced_from_status'); expect(guardAt).toBeGreaterThan(-1); expect(ensureInspectionsAt).toBeGreaterThan(guardAt); expect(setFiftyAt).toBeGreaterThan(guardAt); }); it('两个扫描口径都排除哨兵客户(定时 + 立即执行一次),且用常量而非硬编码字面量', () => { const sqlConstants = src.match(/const AUTO_ADVANCE_(ELIGIBLE|TEST_MODE)_WHERE_SQL = `[\s\S]*?`;/g) || []; expect(sqlConstants).toHaveLength(2); for (const sql of sqlConstants) { expect(sql).toContain("AND COALESCE(o.customer_code, '') <> '${RETAIL_CUSTOMER_CODE}'"); } }); it('独立进货守卫仍在(两个哨兵客户并列保护,防未来误删一条)', () => { expect(src).toContain('if (await isOrderIndependentInbound(code, pool)) {'); expect(src).toContain("result.skippedReason = '独立进货单,跳过定时强推';"); expect(src).toContain("result.skippedReason = '散客单,跳过定时强推';"); // 两条守卫都在置 50 之前 const setFiftyAt = src.indexOf('SET order_status = 50,\n auto_advanced_from_status'); expect(src.indexOf('if (await isOrderIndependentInbound(code, pool)) {')).toBeLessThan(setFiftyAt); expect(src.indexOf('if (await isRetailOrder(code, pool)) {')).toBeLessThan(setFiftyAt); }); });