test(acceptance): reconcile dropship runtime facts
This commit is contained in:
@@ -328,29 +328,51 @@ async function verifyPalletOperations(context, token, fixture) {
|
||||
return success(unbound.response)
|
||||
}
|
||||
|
||||
async function verifyRelabel(context, token, fixture) {
|
||||
async function verifyRelabel(context, token, merchantToken, fixture) {
|
||||
const customerId = id(fixture.order?.order?.customerId || context.createdResources?.phase4OverseasPda?.customerId)
|
||||
const customerOrderNo = fixture.order?.order?.orderNo || fixture.order?.order?.sourceOrderNo
|
||||
|| `PDA-${context.marker}`
|
||||
const inventory = fixture.inventory.find((item) => nonBlank(item?.skuCode))
|
||||
if (!customerId || !inventory?.skuCode || !fixture.overseasWarehouseId) {
|
||||
blocker(context, 'P5本轮库存换标申请', '缺少本轮完成库存的客户、SKU或海外仓事实')
|
||||
if (!customerId || !inventory?.skuCode || !fixture.overseasWarehouseId || !nonBlank(merchantToken)) {
|
||||
blocker(context, 'P5本轮库存换标申请', '缺少本轮完成库存的客户、SKU、海外仓或客户令牌事实')
|
||||
return false
|
||||
}
|
||||
if (!await fundRelabelWallet(context, customerId)) return false
|
||||
const inventoryCandidatesResponse = await context.requestOverseas('GET', query(
|
||||
'/api/merchant/v1/last-leg/relabel-applications/inventory-candidates', {
|
||||
operationWarehouseId: fixture.overseasWarehouseId, inboundCode: fixture.inboundCode,
|
||||
}), undefined, {}, merchantToken)
|
||||
const inventoryCandidates = success(inventoryCandidatesResponse)
|
||||
&& Array.isArray(inventoryCandidatesResponse.body?.data) ? inventoryCandidatesResponse.body.data : []
|
||||
const source = inventoryCandidates.find((item) => id(item?.inventoryBalanceId) === id(inventory?.balanceId))
|
||||
|| inventoryCandidates.find((item) => item?.skuCode === inventory.skuCode
|
||||
&& item?.inboundCode === fixture.inboundCode)
|
||||
const sourcePosition = source?.positions?.find((item) => id(item?.positionId) === id(inventory?.positionId)
|
||||
&& Number(item?.availablePackages) >= 3)
|
||||
|| source?.positions?.find((item) => Number(item?.availablePackages) >= 3)
|
||||
context.addStep(MODULE, 'P5客户库存候选返回换标权威来源', inventoryCandidatesResponse,
|
||||
Boolean(source) && Boolean(sourcePosition) && id(source?.inboundOrderId) !== '',
|
||||
`balanceId=${id(source?.inventoryBalanceId) || 'missing'}, positionId=${id(sourcePosition?.positionId) || 'missing'}, inboundOrderId=${id(source?.inboundOrderId) || 'missing'}; ${trace(inventoryCandidatesResponse)}`, OPTIONS)
|
||||
if (!source || !sourcePosition || !id(source.inboundOrderId)) {
|
||||
blocker(context, 'P5本轮库存换标来源', '客户库存候选未返回本轮库存的余额、至少三箱位置和来源入库单', inventoryCandidatesResponse)
|
||||
return false
|
||||
}
|
||||
const relabelBase = '/api/platform/v1/last-leg/relabel-applications'
|
||||
const pdaBase = '/api/pda/v1/last-leg/relabel-tasks'
|
||||
const newSku = `${inventory.skuCode}-NEW-${String(context.marker).slice(-8)}`.slice(0, 128)
|
||||
const createBody = {
|
||||
customerOrderNo: String(customerOrderNo).slice(0, 128), overseasWarehouseId: id(fixture.overseasWarehouseId),
|
||||
customerOrderNo: String(customerOrderNo).slice(0, 128), operationWarehouseId: id(fixture.overseasWarehouseId),
|
||||
labelDeadline: new Date(Date.now() + 7 * 86400000).toISOString().slice(0, 19),
|
||||
contactName: 'PDA换标验收', contactPhone: '13800000006', chargeAmount: 0.01, remark: context.marker,
|
||||
idempotencyKey: key(context, 'RELABEL-CREATE'),
|
||||
items: [{ skuCode: inventory.skuCode, productNameZh: inventory.productName || '本轮库存商品',
|
||||
items: [{ sourceInventoryBalanceId: id(source.inventoryBalanceId),
|
||||
sourceInventoryPositionId: id(sourcePosition.positionId), sourceInboundOrderId: id(source.inboundOrderId),
|
||||
skuCode: source.skuCode, productNameZh: source.productNameZh || inventory.productName || '本轮库存商品',
|
||||
totalPackageCount: 3, notifiedPackageCount: 3, shipmentNo: `SHIP-${context.marker}`.slice(0, 128),
|
||||
newSkuCode: newSku, labelRequirement: context.marker,
|
||||
cartonMark: `CM-${String(context.marker).slice(-32)}`,
|
||||
fbaCartonMark: `FBA-${String(context.marker).slice(-32)}` }],
|
||||
fbaCartonMark: `FBA-${String(context.marker).slice(-32)}`,
|
||||
destinationFbaWarehouseCode: source.destinationFbaWarehouseCode }],
|
||||
}
|
||||
const createdResponse = await context.requestOverseas('POST',
|
||||
query(relabelBase, { customerId }), createBody)
|
||||
@@ -469,6 +491,7 @@ async function verifyRelabel(context, token, fixture) {
|
||||
export async function run(context) {
|
||||
const handoff = context.context?.phase4OverseasPdaOperations
|
||||
const token = handoff?.primary?.token
|
||||
const merchantToken = handoff?.merchantToken
|
||||
try {
|
||||
if (handoff?.marker !== context.marker || !nonBlank(token)
|
||||
|| !Array.isArray(handoff.completedFixtures) || handoff.completedFixtures.length === 0) {
|
||||
@@ -488,13 +511,14 @@ export async function run(context) {
|
||||
await verifyStocktake(context, token, fixture)
|
||||
await verifyInventoryMove(context, token, fixture)
|
||||
await verifyPalletOperations(context, token, fixture)
|
||||
await verifyRelabel(context, token, fixture)
|
||||
await verifyRelabel(context, token, merchantToken, fixture)
|
||||
} finally {
|
||||
try {
|
||||
if (typeof handoff?.cleanup === 'function') await handoff.cleanup()
|
||||
} finally {
|
||||
if (handoff?.primary) delete handoff.primary.token
|
||||
if (handoff?.secondary) delete handoff.secondary.token
|
||||
if (handoff) delete handoff.merchantToken
|
||||
delete context.context.phase4OverseasPdaOperations
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user