feat(in-transit-transfer): 实现在途仓自动调拨Agent一期完整功能
包含后端服务层、任务处理器与消费Worker、前端聊天组件、数据库模型与迁移脚本、测试用例,同时新增外部系统连接器框架基础能力并更新相关文档。
This commit is contained in:
1 parent
f3050164d0
commit
6b53b563e7
177 files changed
+17260
-36
No files matched your search
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* 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(() => ({
|
||||
createTransferPrecheck: vi.fn(),
|
||||
getTransferPrecheck: vi.fn(),
|
||||
executeTransferPrecheck: 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 { TransferPrecheckDetail } from '@/features/chat/types/transfer.types';
|
||||
|
||||
const detail: TransferPrecheckDetail = {
|
||||
summary: {
|
||||
precheck_id: 'TPC-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, prechecked_count: 2, executable_count: 2, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '2400',
|
||||
estimated_erp_write_count: 2,
|
||||
precheck_hash: 'sha256:abc',
|
||||
},
|
||||
sources: [{ source_code: 'DBS-AWSBI', stage: 'file_ready', file_no: 'REC-1', file_version: 'v3' }],
|
||||
items: [
|
||||
{ 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' },
|
||||
{ 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' },
|
||||
{ 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: {
|
||||
erp_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.createTransferPrecheck.mockResolvedValue(detail.summary);
|
||||
api.getTransferPrecheck.mockResolvedValue(detail);
|
||||
api.executeTransferPrecheck.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('主路径:预检 → 只选 INV-001 → 生成调拨单 → 结果按 ERP 单号聚合', async () => {
|
||||
const transfer = useChatTransfer();
|
||||
await transfer.createPrecheck(['DBS-AWSBI', 'DBS-AWSSG'], '2026-08-06');
|
||||
// 未成熟项默认不勾选
|
||||
expect(transfer.selected.value.has('INV-041')).toBe(false);
|
||||
// 取消 INV-002,只执行 INV-001
|
||||
transfer.toggleSelect('INV-002', false);
|
||||
await transfer.execute();
|
||||
expect(api.executeTransferPrecheck).toHaveBeenCalledWith('TPC-20260806-001', ['INV-001']);
|
||||
expect(transfer.run.value?.result.erp_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.erp_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, '线下已处理');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user