fix(test): align receiving pallets with FBA destinations

This commit is contained in:
2026-09-08 12:45:46 +08:00
parent 847df6a85f
commit 096ab8d48b
3 changed files with 32 additions and 7 deletions
@@ -5,7 +5,7 @@ import test from 'node:test'
import { fileURLToPath } from 'node:url'
import { normalizeModuleOrder } from '../admin-test-env-acceptance.mjs'
import { run } from './phase4-overseas-pda-operations.mjs'
import { auxiliaryPalletFbaWarehouseCode, run } from './phase4-overseas-pda-operations.mjs'
const here = path.dirname(fileURLToPath(import.meta.url))
const source = fs.readFileSync(path.join(here, 'phase4-overseas-pda-operations.mjs'), 'utf8')
@@ -58,6 +58,16 @@ test('P2 to P5 cover all frozen endpoints, replays and conflict boundaries witho
assert.match(source, /traceId=/)
})
test('auxiliary pallets use the authoritative inbound FBA code and never the business destination fallback', () => {
assert.equal(auxiliaryPalletFbaWarehouseCode('FBA', ' ABE3 '), 'ABE3')
assert.equal(auxiliaryPalletFbaWarehouseCode('OVERSEAS', 'ABE3'), null)
assert.equal(auxiliaryPalletFbaWarehouseCode('FBA', ''), null)
assert.match(receivingSource,
/destinationType: inbound\.destinationType,[\s\S]*fbaWarehouseCode: inbound\.destinationType === 'FBA' \? inbound\.fbaWarehouseCode : null/)
assert.match(source, /fbaWarehouseCode,\s*\n\s*remark:/)
assert.doesNotMatch(source, /createEmptyPallet\([^\n]*main\.destinationWarehouseCode/)
})
test('fixture failure still disables both picker accounts and removes all transient tokens', async () => {
const cleanups = []
const gaps = []
@@ -95,13 +95,26 @@ async function createLocation(context, warehouseId, suffix) {
return success(response) ? { locationId, locationCode } : null
}
async function createEmptyPallet(context, token, fixture, suffix, destinationWarehouseCode) {
export function auxiliaryPalletFbaWarehouseCode(destinationType, fbaWarehouseCode) {
if (destinationType === 'OVERSEAS') return null
if (destinationType === 'FBA' && nonBlank(fbaWarehouseCode)) return fbaWarehouseCode.trim()
return null
}
async function createEmptyPallet(context, token, fixture, suffix) {
const fbaWarehouseCode = auxiliaryPalletFbaWarehouseCode(
fixture.destinationType, fixture.fbaWarehouseCode)
if (fixture.destinationType === 'FBA' && !fbaWarehouseCode) {
blocker(context, `${suffix}辅助空托盘`,
`当前FBA入仓码 ${fixture.inboundCode || 'missing'} 缺少权威fbaWarehouseCode`)
return null
}
const palletCode = `PDAOPS-${context.marker}-${suffix}`.replace(/[^A-Za-z0-9_-]/g, '').slice(-120)
const response = await context.requestOverseas('POST',
`/api/platform/v1/warehouse-admin/${encodeURIComponent(fixture.overseasWarehouseId)}/pallets`, {
palletCode, palletType: '木托盘', capacityCbm: 10, unitPrice: 0, status: 'IDLE',
locationId: fixture.location.locationId,
fbaWarehouseCode: destinationWarehouseCode || null,
fbaWarehouseCode,
remark: `${context.marker}-pda-operations-${suffix}`,
})
context.addStep(MODULE, `创建${suffix}辅助空托盘`, response, success(response), trace(response), OPTIONS)
@@ -234,9 +247,9 @@ async function verifyPalletOperations(context, token, fixture) {
'主托盘只有一箱可用库存,解绑会清空唯一业务托盘;必须由本轮生产矩阵提供至少两箱')
return false
}
const swapTarget = await createEmptyPallet(context, token, fixture, 'SWAP', main.destinationWarehouseCode)
const splitTarget = await createEmptyPallet(context, token, fixture, 'SPLIT', main.destinationWarehouseCode)
const unbindTarget = await createEmptyPallet(context, token, fixture, 'UNBIND', main.destinationWarehouseCode)
const swapTarget = await createEmptyPallet(context, token, fixture, 'SWAP')
const splitTarget = await createEmptyPallet(context, token, fixture, 'SPLIT')
const unbindTarget = await createEmptyPallet(context, token, fixture, 'UNBIND')
if (!swapTarget || !splitTarget || !unbindTarget) {
blocker(context, 'P4辅助实物托盘', '无法创建换托、拆托和解绑所需辅助托盘')
return false
@@ -669,7 +669,9 @@ async function runReceiving(context, token, secondaryToken, merchantToken, prefe
pallets.get(inbound.inboundCode), inbound.destinationType)
if (warehouseFacts && context.context?.phase4OverseasPdaOperations) {
context.context.phase4OverseasPdaOperations.completedFixtures.push({
containerNo, order, ...warehouseFacts,
containerNo, order, destinationType: inbound.destinationType,
fbaWarehouseCode: inbound.destinationType === 'FBA' ? inbound.fbaWarehouseCode : null,
...warehouseFacts,
})
}
}