test: automate overseas wallet and pallet cost closure

This commit is contained in:
2026-09-06 11:00:06 +08:00
parent 64bf5aa0fe
commit 20b3074cb1
21 changed files with 506 additions and 103 deletions
@@ -194,11 +194,9 @@ export async function run(context) {
try {
await verifyLocationLifecycle(context, warehouseId)
await verifyPalletLifecycle(context, warehouseId)
await verifyRelabelLifecycle(context, customerId, warehouseId)
context.context.phase4OverseasWarehouse = {
customerId, warehouseId,
palletId: context.createdResources.phase4OverseasWarehouse.palletId,
relabelNo: context.createdResources.phase4OverseasWarehouse.relabelNo,
}
} finally {
if (ownedWarehouse) await retireWarehouseFixture(context, customerId, warehouseId)
@@ -250,68 +248,6 @@ async function verifyLocationLifecycle(context, warehouseId) {
}
}
async function verifyRelabelLifecycle(context, customerId, warehouseId) {
const marker = String(context.marker || 'PHASE4')
const idempotencyKey = `${marker}:RELABEL`.slice(0, 255)
const skuSuffix = marker.replace(/[^A-Za-z0-9]/g, '').slice(-20).toUpperCase() || 'PHASE4'
const payload = {
customerOrderNo: `${marker}-RELABEL`, overseasWarehouseId: warehouseId,
labelDeadline: new Date(Date.now() + 86400000).toISOString().slice(0, 19),
contactName: 'Phase4 QA', contactPhone: '+1-213-555-0199', remark: marker, idempotencyKey,
items: [{ skuCode: `OLD-${skuSuffix}`.slice(0, 128), productNameZh: `${marker} 换标商品`,
totalPackageCount: 2, notifiedPackageCount: 2, shipmentNo: `SHIP-${skuSuffix}`.slice(0, 128),
newSkuCode: `NEW-${skuSuffix}`.slice(0, 128), labelRequirement: marker }],
}
let relabelNo = ''
let terminalStatus = ''
try {
const created = await overseasMutation(context, 'POST', '创建本轮换标单',
query('/api/platform/v1/last-leg/relabel-applications', { customerId }), payload)
relabelNo = id(created.data?.application?.relabelNo)
context.createdResources.phase4OverseasWarehouse.relabelNo = relabelNo || null
context.assert(MODULE, '换标单创建事实正确', created.response,
nonBlank(relabelNo) && created.data?.application?.customerOrderNo === payload.customerOrderNo
&& created.data?.application?.status === 'PENDING_PROCESSING'
&& Array.isArray(created.data?.items) && created.data.items.length === 1,
`relabelNo=${relabelNo || 'missing'}, status=${created.data?.application?.status || 'missing'}; ${trace(created.response)}`, OPTIONS)
if (!relabelNo) return
const replay = await overseasMutation(context, 'POST', '换标单幂等精确重放',
query('/api/platform/v1/last-leg/relabel-applications', { customerId }), payload)
context.assert(MODULE, '换标单精确重放返回同一单号', replay.response,
replay.data?.application?.relabelNo === relabelNo,
`expected=${relabelNo}, actual=${replay.data?.application?.relabelNo || 'missing'}; ${trace(replay.response)}`, OPTIONS)
const conflict = await context.requestOverseas('POST',
query('/api/platform/v1/last-leg/relabel-applications', { customerId }), { ...payload, remark: `${marker}-DIFFERENT` })
context.addStep(MODULE, '换标单同幂等键不同请求返回A0409', conflict, businessConflict(conflict), trace(conflict), OPTIONS)
const processing = await overseasMutation(context, 'PUT', '换标单进入处理中',
`/api/platform/v1/last-leg/relabel-applications/${encodeURIComponent(relabelNo)}/status`,
{ status: 'PROCESSING', remark: marker })
context.assert(MODULE, '换标单状态推进为PROCESSING', processing.response,
processing.data?.application?.status === 'PROCESSING',
`status=${processing.data?.application?.status || 'missing'}; ${trace(processing.response)}`, OPTIONS)
const completed = await overseasMutation(context, 'PUT', '完成本轮换标单',
`/api/platform/v1/last-leg/relabel-applications/${encodeURIComponent(relabelNo)}/status`,
{ status: 'COMPLETED', remark: `${marker}-completed` })
terminalStatus = completed.data?.application?.status || ''
context.createdResources.phase4OverseasWarehouse.relabelTerminalStatus = terminalStatus || null
context.assert(MODULE, '本轮换标单已完成收口', completed.response, terminalStatus === 'COMPLETED',
`relabelNo=${relabelNo}, status=${terminalStatus || 'missing'}; ${trace(completed.response)}`, OPTIONS)
} finally {
if (relabelNo && terminalStatus !== 'COMPLETED') {
const cancelled = await context.requestOverseas('PUT',
`/api/platform/v1/last-leg/relabel-applications/${encodeURIComponent(relabelNo)}/status`,
{ status: 'CANCELLED', remark: `${marker}-acceptance-cleanup` })
const status = cancelled?.body?.data?.application?.status
context.createdResources.phase4OverseasWarehouse.relabelTerminalStatus = status || null
context.addStep(MODULE, '异常路径换标单取消收口', cancelled,
cancelled?.http === 200 && String(cancelled?.body?.code) === '200' && status === 'CANCELLED', trace(cancelled), OPTIONS)
}
}
}
async function createWarehouseFixture(context, customerId) {
const suffix = String(context.marker || '').replace(/[^A-Za-z0-9]/g, '').slice(-20).toUpperCase()
const payload = {