Files
syops/frontend/src/features/chat/e2e/in-transit-transfer.spec.ts
T
hugo 0cf3c24119 refactor(in-transit-transfer): 行归属解耦、按行执行三层门禁并重构术语为匹配
- 行不迁移:匹配记录降级为评估留痕(scope/counts/hash 留痕不拦执行),
  匹配/重查原地刷新行并续行级新鲜度(updated_at)
- 执行改按行:POST /items/execute 三层门禁(行级新鲜度 TTL/文件版本对账/写前复查),
  Run 留痕不绑匹配记录;消失行 blocked_file_removed fail-closed 入异常池
- 恢复处理收敛为行级重查(batch-resume 删除);待处理池补齐匹配窗口字段,
  排序改业务稳定键(收料日期→Invoice→created_at,操作不再引起跳位)
- 首页待办看板四队列:可调拨明细/待恢复异常/已人工关闭/结果未知;「最近预检」移除;
  收料日期默认 T-1 并加输入期限制;「重新查询 ERP」更名「重查」
- 术语重构 precheck→match:表 transfer_matchings、列 matching_id/matching_no/matching_hash、
  API /matchings、单号前缀 MTG、状态值 prechecking→matching(迁移 rn1a2b3c4d5e6,模块未上线无兼容层)
- 修复 integration_connector mapping 扇出嵌套丢行缺陷;对账结论:0 vs 30/40/36
  系收料仓库映射曾指向错误账套 TGHX(已改 TGHX1),探针留档 backend/tmp
- 测试:后端 in_transit_transfer+api+connector 393 passed;前端 chat 713 passed;build ✓
2026-09-24 00:24:03 +08:00

118 lines
5.5 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.
/**
* features/chat/e2e/in-transit-transfer.spec.ts
* 用途:在途仓自动调拨全链路契约冒烟(对应 TDD §10 主路径)——
* 匹配 → 选择子集 → 生成调拨单 → Run 恢复 → 下载留底。
* 依赖:Vitest、vi.mock(transfer.api)、useChatTransfer。
* 逻辑:不启浏览器;用组合式函数 + Mock API 断言产品契约,避免 e2e 环境依赖
* (与仓库 shipping e2e 约定一致)。
*/
import { describe, expect, it, vi, beforeEach } from 'vitest';
const api = vi.hoisted(() => ({
createTransferMatching: vi.fn(),
getTransferMatching: vi.fn(),
executeTransferItems: vi.fn(),
getTransferRun: vi.fn(),
retryTransferItem: vi.fn(),
manualCloseTransferItem: vi.fn(),
downloadTransferReceiptFiles: vi.fn(),
downloadTransferErpInventory: vi.fn(),
downloadTransferExceptions: vi.fn(),
}));
vi.mock('@/features/chat/api/transfer.api', () => api);
import { useChatTransfer } from '@/features/chat/composables/useChatTransfer';
import type { TransferMatchingDetail } from '@/features/chat/types/transfer.types';
const detail: TransferMatchingDetail = {
summary: {
matching_id: 'MTG-20260806-001',
status: 'ready_to_execute',
business_date: '2026-08-06',
eligible_receipt_date_to: '2026-08-05',
expires_at: '',
counts: { file_invoice_count: 3, not_matured_count: 1, matched_count: 2, executable_count: 2, blocked_count: 0 },
estimated_transfer_quantity: '2400',
estimated_external_write_count: 2,
matching_hash: 'sha256:abc',
},
sources: [{ source_code: 'DBS-AWSBI', stage: 'file_ready', file_no: 'REC-1', file_version: 'v3' }],
items: [
{ item_id: 11, source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器组件', specification: 'A', invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
{ item_id: 12, source_code: 'DBS-AWSBI', material_no: 'MAT-2', material_name: '控制器组件', specification: 'B', invoice_no: 'INV-002', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
{ item_id: 13, source_code: 'DBS-AWSSG', material_no: 'MAT-41', material_name: '连接器', specification: 'C', invoice_no: 'INV-041', from_warehouse: '', from_quantity: null, to_warehouse: '', to_quantity: '400', result: 'not_matured' },
],
};
const runResult = {
run_no: 'RUN-20260806-001',
status: 'success',
result: {
external_documents: [{
document_no: 'TRF-10001',
from_warehouse: 'DBS-TRANSIT',
to_warehouse: 'HUB-CN01',
material_count: 2,
total_quantity: '2400',
posting_status: 'posted',
lines: [
{ material_no: 'MAT-1', material_name: '连接器组件', specification: 'A', invoice_no: 'INV-001', quantity: '1200' },
{ material_no: 'MAT-2', material_name: '控制器组件', specification: 'B', invoice_no: 'INV-002', quantity: '1200' },
],
}],
exceptions: [],
},
};
describe('in-transit-transfer e2e contract', () => {
beforeEach(() => {
vi.clearAllMocks();
api.createTransferMatching.mockResolvedValue(detail.summary);
api.getTransferMatching.mockResolvedValue(detail);
api.executeTransferItems.mockResolvedValue({ run_no: 'RUN-20260806-001', status: 'success' });
api.getTransferRun.mockResolvedValue(runResult);
api.downloadTransferReceiptFiles.mockResolvedValue({ blob: new Blob(['zip']), filename: 'receipt-files.zip' });
api.downloadTransferErpInventory.mockResolvedValue({ blob: new Blob(['csv']), filename: 'erp.csv' });
});
it('主路径:匹配 → 只选 item 11 → 按明细行生成调拨单 → 结果按 ERP 单号聚合', async () => {
const transfer = useChatTransfer();
await transfer.createMatching(['DBS-AWSBI', 'DBS-AWSSG'], '2026-08-06');
// 未成熟项默认不勾选
expect(transfer.selected.value.has(13)).toBe(false);
// 取消 item 12,只执行 item 11
transfer.toggleSelect(12, false);
await transfer.execute();
expect(api.executeTransferItems).toHaveBeenCalledWith([11]);
expect(transfer.run.value?.result.external_documents[0].document_no).toBe('TRF-10001');
});
it('刷新恢复:重建 composable 后按 run_no 恢复最终结果(决策 17)', async () => {
const transfer = useChatTransfer();
transfer.runNo.value = 'RUN-20260806-001';
await transfer.refreshRun();
expect(transfer.run.value?.status).toBe('success');
expect(transfer.run.value?.result.external_documents[0].material_count).toBe(2);
});
it('下载:收料来源文件与 ERP 库存表(决策 21/22 前端入口)', async () => {
const transfer = useChatTransfer();
transfer.runNo.value = 'RUN-20260806-001';
await transfer.downloadReceiptFiles();
await transfer.downloadErpInventory();
expect(api.downloadTransferReceiptFiles).toHaveBeenCalledWith('RUN-20260806-001');
expect(api.downloadTransferErpInventory).toHaveBeenCalledWith('RUN-20260806-001');
});
it('异常处理:人工重试与人工关闭走独立 API', async () => {
api.retryTransferItem.mockResolvedValue({ item_id: 1, status: 'ready_to_execute', attempt_no: 2 });
api.manualCloseTransferItem.mockResolvedValue({ item_id: 2, status: 'manually_closed' });
const transfer = useChatTransfer();
await transfer.retry(1);
await transfer.manualClose(2, '线下已处理');
expect(api.retryTransferItem).toHaveBeenCalledWith(1);
expect(api.manualCloseTransferItem).toHaveBeenCalledWith(2, '线下已处理');
});
});