Files
SupplierSystem/server/tests/processingOrderTaskDedupe.test.ts
T
Ubuntu de14fb01f0
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
feat: 供应商系统 2026-11 阶段成果(分公司模板/真还原预览、商品远程搜索、主系统联调、加工幂等修复)
- 分公司类型模板:超管配置隐藏路由/菜单 + 中文文案覆盖,仅对挂类型的分公司生效(后端 service/routes、前端 Provider/守卫/配置页)
- 超管模板 iframe 真还原预览:28 个业务页注册、白名单点选编辑、空/示例数据 fixture、白名单漂移检测工具
- 商品/SKU 下拉远程搜索:服务端关键词搜索 + 前端 useRemoteOptionSearch/SearchableSelect 接入(订单/采购/商品等页)
- 主系统联调:子系统主动解绑主系统授权(幂等重试/本地兜底)、追加修改 price_amend 视图代理与 amend-price 转发
- 修复:仓内加工重复建单幂等(已完成需求单 guard、order 任务一商品一单 guard)
- 修复:出入库记录只取前 100 条 → 服务端分页 + 真实总数
- 其它:库存/订单若干修复、分公司管理响应式布局、i18n 文案、设计文档与回归测试
2026-11-07 20:10:48 +08:00

78 lines
3.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it, vi } from 'vitest';
/**
* 2026-11-07 事故回归(主系统 a2b8df4d 移植):
* 同订单 + 同 SKU + 同加工方式只允许一条 order 加工任务。
*
* 旧逻辑只按 inspection_id 查重:同一订单同 SKU 有两张验收单时,第二张会再 INSERT 一条
* source_type='order' 的加工任务(task_code=NULL、界面出现两颗待加工行)。
*/
const calls: Array<{ text: string; params: unknown[] }> = [];
let existingOrderTask: { id: string } | null = { id: 'existing-order-task' };
vi.mock('../src/db', () => {
const q = async (text: string, params: unknown[] = []) => {
calls.push({ text: String(text), params });
const sql = String(text);
// 工作流开关(system_configs)
if (sql.includes('system_configs')) return { rows: [{ config_value: { enabled: true } }], rowCount: 1 };
// resolveProcessingContextForInspection:订单行工艺
if (sql.includes('FROM order_items oi') && sql.includes('processing_method')) {
return { rows: [{ processing_method: '去皮', processing_owner: 'warehouse', process_unit_price: 5 }], rowCount: 1 };
}
// orderSkuHasWarehouseDemand:无需求行
if (sql.includes('processing_demand_items')) return { rows: [], rowCount: 0 };
// 旧查重:按 inspection_id —— 第二张验收单查不到
if (sql.includes('WHERE inspection_id = $1')) return { rows: [], rowCount: 0 };
// 新守卫:同 order + sku + method + source_type='order' + status<50
if (sql.includes("source_type = 'order'") && sql.includes('processing_method = $3')) {
return { rows: existingOrderTask ? [existingOrderTask] : [], rowCount: existingOrderTask ? 1 : 0 };
}
if (sql.includes('UPDATE processing_tasks')) return { rows: [], rowCount: 1 };
return { rows: [], rowCount: 0 };
};
return {
pool: { query: q, connect: vi.fn() },
query: q,
getRawPoolQuery: () => q,
getRawPoolConnect: vi.fn(),
};
});
const { ensureProcessingTaskForInspection } = await import('../src/services/processingTaskService');
const BASE_INPUT = {
inspectionId: 'insp-second',
orderCode: 'ORD_X',
skuCode: 'SKU86017523428',
processingDetails: { processing_method: '去皮', processing_owner: 'warehouse' },
prepareQty: 15,
itemName: '土豆',
branchCode: 'BR002',
sourceQty: 15,
};
describe('ensureProcessingTaskForInspection 一商品一加工单', () => {
it('同订单+同SKU+同加工方式已有 order 任务 ⇒ 复用(更新)并返回 false,不再 INSERT', async () => {
existingOrderTask = { id: 'existing-order-task' };
calls.length = 0;
const created = await ensureProcessingTaskForInspection(BASE_INPUT, { query: async (t: string, p: unknown[] = []) => {
// 复用同一 mock 逻辑(通过动态 import 的 db mock 不可直接拿 q,这里重新实现最小集)
const sql = String(t);
calls.push({ text: sql, params: p });
if (sql.includes('system_configs')) return { rows: [{ config_value: { enabled: true } }], rowCount: 1 } as never;
if (sql.includes('FROM order_items oi')) return { rows: [{ processing_method: '去皮', processing_owner: 'warehouse', process_unit_price: 5 }], rowCount: 1 } as never;
if (sql.includes('processing_demand_items')) return { rows: [], rowCount: 0 } as never;
if (sql.includes('WHERE inspection_id = $1')) return { rows: [], rowCount: 0 } as never;
if (sql.includes("source_type = 'order'") && sql.includes('processing_method = $3')) return { rows: [existingOrderTask], rowCount: 1 } as never;
if (sql.includes('UPDATE processing_tasks')) return { rows: [], rowCount: 1 } as never;
return { rows: [], rowCount: 0 } as never;
} } as never);
expect(created).toBe(false);
const sqls = calls.map((c) => c.text);
expect(sqls.some((s) => s.includes("source_type = 'order'"))).toBe(true);
expect(sqls.some((s) => s.includes('INSERT INTO processing_tasks'))).toBe(false);
});
});