test(phase4): provision overseas lifecycle fixtures

This commit is contained in:
2026-08-24 15:07:17 +08:00
parent cd97229791
commit e11a528dfe
12 changed files with 248 additions and 48 deletions
@@ -18,6 +18,8 @@ function contextFixture({ tenants = [{ id: '10001', status: 'ACTIVE' }], warehou
async request(method, requestPath) { calls.push({ channel: 'domestic', method, path: requestPath }); return response(page(tenants)) },
async requestOverseas(method, requestPath, body) {
calls.push({ channel: 'overseas', method, path: requestPath, body })
if (method === 'POST' && requestPath === '/api/platform/v1/warehouse-admin') return response('20001')
if (method === 'PATCH' && requestPath.includes('/warehouse-admin/20001/status?')) return response(null)
if (method === 'POST' && requestPath.endsWith('/warehouse-admin/20001/pallets')) { createdPallet = { id: '71001', customerId: '0', warehouseId: '20001', locationId: '72001', ...body }; return response('71001') }
if (method === 'PUT' && requestPath.endsWith('/warehouse-admin/20001/pallets/71001')) { createdPallet = { ...createdPallet, ...body }; return response(null) }
if (requestPath.startsWith('/api/platform/v1/last-leg/orders?')) return response(page([{ id: '30001', orderNo: 'LL-1', currentStatus: 'PENDING_ASSIGNMENT' }]))
@@ -31,7 +33,7 @@ function contextFixture({ tenants = [{ id: '10001', status: 'ACTIVE' }], warehou
if (requestPath.includes('/inventory/balances/60001/positions?')) return response([{ id: '61001', balanceId: '60001', totalPackages: 10 }])
if (requestPath.includes('/inventory/ledger?')) return response(page([{ id: '62001', customerId: '10001', businessType: 'STOCK_IN', beforePackages: 0, deltaPackages: 10, afterPackages: 10, occurredAt: '2026-08-21T10:00:00' }]))
if (requestPath.startsWith('/api/platform/v1/warehouse-admin?')) return response(page(warehouseRecords))
if (requestPath.includes('/warehouse-admin/20001?')) return response({ warehouse: { id: '20001' } })
if (requestPath.includes('/warehouse-admin/20001?')) return response({ warehouse: { id: '20001', customerId: '10001', status: 'ACTIVE' } })
if (requestPath.endsWith('/warehouse-admin/20001/pallets?page=1&size=20')) return response(page([{ id: '70001', customerId: '0', warehouseId: '20001', palletCode: 'PLT-1', status: 'IDLE' }]))
if (requestPath.endsWith('/warehouse-admin/20001/pallets/70001')) return response({ id: '70001', customerId: '0', warehouseId: '20001' })
if (requestPath.endsWith('/warehouse-admin/20001/pallets/71001')) return response(createdPallet)
@@ -54,8 +56,7 @@ test('模块只依赖注入请求,不读取环境或自行联网', () => {
assert.doesNotMatch(source, /process\.env|fetch\(|requestBinary/)
})
test('仅托盘生命周期允许写请求,其他海外业务保持只读', () => {
assert.doesNotMatch(source, /requestOverseas\(['"]PATCH['"]/)
test('既有仓库场景只写本轮托盘生命周期', () => {
const context = contextFixture()
return run(context).then(() => {
assert.ok(context.calls.length >= 12)
@@ -82,7 +83,7 @@ test('覆盖冻结的海外只读列表与有记录才查详情', async () => {
assert.deepEqual(context.createdResources.phase4OverseasWarehouse, { marker: 'ACC-PHASE4-TEST', customerId: '10001', warehouseId: '20001', palletId: '71001', terminalStatus: 'SCRAPPED' })
})
test('缺少真实客户或仓库时记录 coverageGap,不使用固定业务ID补洞', async () => {
test('缺少客户时记录缺口,缺少仓库时通过正式接口创建并停用fixture', async () => {
const noCustomer = contextFixture({ tenants: [] })
await run(noCustomer)
assert.equal(noCustomer.gaps.length, 1)
@@ -91,8 +92,10 @@ test('缺少真实客户或仓库时记录 coverageGap,不使用固定业务ID
const noWarehouse = contextFixture({ warehouseRecords: [] })
await run(noWarehouse)
assert.equal(noWarehouse.gaps.some((gap) => gap[2] === '公共托盘真实仓库前置'), true)
assert.equal(noWarehouse.calls.some((call) => call.path.includes('/pallets')), false)
assert.equal(noWarehouse.gaps.some((gap) => gap[2] === '公共托盘真实仓库前置'), false)
assert.ok(noWarehouse.calls.some((call) => call.method === 'POST' && call.path === '/api/platform/v1/warehouse-admin'))
assert.ok(noWarehouse.calls.some((call) => call.method === 'PATCH' && call.path.includes('/warehouse-admin/20001/status?')))
assert.ok(noWarehouse.calls.some((call) => call.path.includes('/pallets')))
})
test('合同覆盖库存CSV并明确排除暂缓、离仓、PDA与内部路径', () => {