test(acceptance): reuse fixed customers and align native fulfillment flows

This commit is contained in:
2026-10-23 04:48:02 +08:00
parent b92f7fe991
commit 139f6b1932
51 changed files with 1076 additions and 228 deletions
@@ -6,6 +6,38 @@ const validId = value => /^[1-9]\d*$/.test(id(value))
const stable = value => JSON.stringify(value, (_, item) => item && typeof item === 'object' && !Array.isArray(item)
? Object.fromEntries(Object.keys(item).sort().map(key => [key, item[key]])) : item)
/** 只读筛选既有异仓空闲资源,供造单前选线和收货前重新核验共用。 */
export async function findReusableTransferReceiptTarget({ sourceWarehouseId, fbaWarehouseCode = '', request, check }) {
if (!validId(sourceWarehouseId)) throw Error('缺少转运来源作业仓')
let target
// 完整翻页寻找既有空闲资源,不创建公共托盘,也不借用已被其他业务占用的托盘。
for (let page = 1; page <= 100 && !target; page++) {
const pallets = await request('GET', `${RESOURCES}/pallets?status=IDLE&page=${page}&size=200`)
check('目标托盘分页有效', Array.isArray(pallets?.records) && Number.isSafeInteger(Number(pallets.total)) && Number(pallets.total) >= 0)
for (const candidate of pallets.records) {
if (candidate.status !== 'IDLE' || id(candidate.customerId) !== '0' || !validId(candidate.warehouseId)
|| id(candidate.warehouseId) === sourceWarehouseId || (!candidate.fbaWarehouseCode || (fbaWarehouseCode && candidate.fbaWarehouseCode !== fbaWarehouseCode))
|| !validId(candidate.id) || !validId(candidate.locationId)) continue
const resource = `${RESOURCES}/${candidate.warehouseId}`
const pallet = await request('GET', `${resource}/pallets/${candidate.id}`)
if (pallet?.status !== 'IDLE' || id(pallet.id) !== id(candidate.id) || id(pallet.customerId) !== '0'
|| id(pallet.warehouseId) !== id(candidate.warehouseId) || id(pallet.locationId) !== id(candidate.locationId)
|| pallet.fbaWarehouseCode !== candidate.fbaWarehouseCode || !pallet.palletCode) continue
const location = await request('GET', `${resource}/locations/${pallet.locationId}`)
if (id(location?.customerId) !== '0' || id(location?.warehouseId) !== id(pallet.warehouseId)
|| id(location?.id) !== id(pallet.locationId) || !location.locationCode
|| !(location.locationType === 'VIRTUAL' ? location.status === 'ACTIVE' : location.status === 'IDLE')) continue
const master = await request('GET', `/api/platform/v1/warehouse-admin/${pallet.warehouseId}?tenantId=0`)
const warehouse = master?.warehouse
if (id(warehouse?.id) !== id(pallet.warehouseId) || id(warehouse.tenantId) !== '0'
|| warehouse.warehouseType !== 'OVERSEAS' || warehouse.status !== 'ACTIVE') continue
target = { pallet, location, warehouse }; break
}
if (page * 200 >= Number(pallets.total)) break
}
return target
}
/** 转运收货复用其他海外仓的空闲匹配托盘,并验证原单入库及关联换标结算。 */
export async function receiveWarehouseTransfer(context, { proof, merchantToken, checkpoint, delay = () => new Promise(resolve => setTimeout(resolve, 1000)) }) {
if (context.createdResources?.phase4OverseasClientServices?.transferFulfillment !== proof
@@ -47,32 +79,8 @@ export async function receiveWarehouseTransfer(context, { proof, merchantToken,
try {
const original = await request('GET', base + scope)
check('原转运出库来源不变', same(original, 'OUTBOUNDED') && Boolean(original.fbaWarehouseCode))
let target
// 完整翻页寻找既有空闲资源,不创建公共托盘,也不借用已被其他业务占用的托盘。
for (let page = 1; page <= 100 && !target; page++) {
const pallets = await request('GET', `${RESOURCES}/pallets?status=IDLE&page=${page}&size=200`)
check('目标托盘分页有效', Array.isArray(pallets?.records) && Number.isSafeInteger(Number(pallets.total)) && Number(pallets.total) >= 0)
for (const candidate of pallets.records) {
if (candidate.status !== 'IDLE' || id(candidate.customerId) !== '0' || !validId(candidate.warehouseId)
|| id(candidate.warehouseId) === proof.warehouseId || candidate.fbaWarehouseCode !== original.fbaWarehouseCode
|| !validId(candidate.id) || !validId(candidate.locationId)) continue
const resource = `${RESOURCES}/${candidate.warehouseId}`
const pallet = await request('GET', `${resource}/pallets/${candidate.id}`)
if (pallet?.status !== 'IDLE' || id(pallet.id) !== id(candidate.id) || id(pallet.customerId) !== '0'
|| id(pallet.warehouseId) !== id(candidate.warehouseId) || id(pallet.locationId) !== id(candidate.locationId)
|| pallet.fbaWarehouseCode !== original.fbaWarehouseCode || !pallet.palletCode) continue
const location = await request('GET', `${resource}/locations/${pallet.locationId}`)
if (id(location?.customerId) !== '0' || id(location?.warehouseId) !== id(pallet.warehouseId)
|| id(location?.id) !== id(pallet.locationId) || !location.locationCode
|| !(location.locationType === 'VIRTUAL' ? location.status === 'ACTIVE' : location.status === 'IDLE')) continue
const master = await request('GET', `/api/platform/v1/warehouse-admin/${pallet.warehouseId}?tenantId=0`)
const warehouse = master?.warehouse
if (id(warehouse?.id) !== id(pallet.warehouseId) || id(warehouse.tenantId) !== '0'
|| warehouse.warehouseType !== 'OVERSEAS' || warehouse.status !== 'ACTIVE') continue
target = { pallet, location, warehouse }; break
}
if (page * 200 >= Number(pallets.total)) break
}
const target = await findReusableTransferReceiptTarget({ sourceWarehouseId: proof.warehouseId,
fbaWarehouseCode: original.fbaWarehouseCode, request, check })
check('必须存在其他海外仓同目的仓的空闲托盘与可预留库位', Boolean(target))
evidence.target = target
const { pallet, location, warehouse } = target