WMS_MAIN/test_reports/pass/20260707-手工运单号硬删除误删修复单元测试报告.md
liufumingren 19f0449992 fix: 手工运单号防误删三层防护 + 操作日志businessId修正
1. hardDeleteWaybillAsyncOrderExpressRows 加 status:0 过滤,保护手工录入 status=1 记录
2. createWaybillCodePipeline 入口跳过 business_key=1 且已分配运单的订单
3. manualWaybill 操作日志 businessId 从仓库ID 修正为订单ID String(orderId)
4. 新增 14 个单元测试,全部通过
2026-07-07 17:06:43 +08:00

74 lines
3.2 KiB
Markdown
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.

# 20260707-手工运单号硬删除误删修复单元测试报告
## 测试目标
验证上一轮三轮修复(`hardDeleteWaybillAsyncOrderExpressRows` 加 `status:0` 过滤、`manualWaybill` 操作日志 `businessId` 修正、`createWaybillCodePipeline` 跳过已分配订单)是否符合预期。
## 测试类型
单元测试(Unit Test)
## 测试范围
| 被测方法 | 被测文件 | 测试用例数 | 通过 | 失败 |
|----------|---------|-----------|------|------|
| `hardDeleteWaybillAsyncOrderExpressRows` | `app/service/systems/express.js` | 6 | 6 | 0 |
| `createWaybillCodePipeline` | `app/service/systems/express.js` | 5 | 5 | 0 |
| `manualWaybill` | `app/service/systemMethods/order/pendingOrder.js` | 3 | 3 | 0 |
## 测试产物
- `test/app/service/systems/express.manualWaybill.guard.test.js` — hardDelete + pipeline 跳过逻辑测试
- `test/app/service/systemMethods/order/pendingOrder.manualWaybill.log.test.js` — manualWaybill 操作日志测试
## 测试结果摘要
### ✅ 全部 14 个测试用例通过(0 失败)
### 1. hardDeleteWaybillAsyncOrderExpressRows — status:0 过滤
| 用例 | 结果 |
|------|------|
| destroy 应包含 status:0 条件,保护 status=1 的手工记录 | ✅ PASS |
| 缺少 business_key 时应返回 false,不调用 destroy | ✅ PASS |
| 缺少 order_id 时应返回 false,不调用 destroy | ✅ PASS |
| OrderExpress 模型不可用时应返回 false | ✅ PASS |
| 空数组应返回 false | ✅ PASS |
| destroy 抛异常时应返回 false 并记录错误日志 | ✅ PASS |
### 2. createWaybillCodePipeline — 跳过 business_key=1 已分配订单
| 用例 | 结果 |
|------|------|
| 订单已有 status=1 且传入 business_key=1 时,应跳过该订单 | ✅ PASS |
| 订单有 status=1 但传入 business_key=2 时,不应跳过(不同 business_key) | ✅ PASS |
| 订单有 status=1 但 business_key 不是 1 时,传入 business_key=1 应跳过 | ✅ PASS |
| 全部订单均已完成时,应直接返回无需处理 | ✅ PASS |
| 无 status=1 记录时,所有订单正常进入 pipeline | ✅ PASS |
### 3. manualWaybill — 操作日志 businessId 修正
| 用例 | 结果 |
|------|------|
| createOperationLog 的 businessId 应为 String(orderId),而非仓库ID | ✅ PASS |
| businessId 不应为 warehouseId(回归验证) | ✅ PASS |
| business_key 从已有最大值递增 | ✅ PASS |
## 关键验证点
1. **三层防护闭环验证**:
- 第 1 层(pipeline 入口):`business_key=1` + 已完成的订单在 pipeline 入口即被过滤
- 第 2 层(trans 内):`createWaybillCode` 的 `completedOrderKeySet` 事务内二次校验
- 第 3 层(失败清理):`hardDeleteWaybillAsyncOrderExpressRows` 仅删 `status=0`
2. **操作日志可检索性**:`manualWaybill` 的 `businessId` 已修正为订单 ID,可通过订单 ID 检索操作日志
3. **向后兼容**:
- `business_key ≠ 1` 的已分配订单不会被误跳过
- 无已完成记录时 pipeline 正常运作
## 结论与建议
三轮修复均通过单元测试验证,符合预期行为:
- 手工录入的运单号(`status=1`)不再被失败清理逻辑误删
- 操作日志可正确按订单 ID 检索
- pipeline 入口即过滤已分配订单,避免无效异步任务提交