Merge remote-tracking branch 'origin/test' into dev
# Conflicts: # scripts/admin-test-env-modules/phase4-tail-order-controls.mjs
This commit is contained in:
@@ -78,6 +78,70 @@ async function request(context, method, path, body, headers = {}) {
|
||||
return { method, path, http: 0, body: null, raw: String(error), requestId: null, traceId: null }
|
||||
}
|
||||
}
|
||||
|
||||
async function requestPdf(context, path, body) {
|
||||
try {
|
||||
const response = await fetch(`${context.options.gateway}${path}`, {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/pdf', Authorization: `Bearer ${context.token}`,
|
||||
'Content-Type': 'application/json; charset=utf-8' },
|
||||
body: JSON.stringify(body), signal: AbortSignal.timeout(60_000),
|
||||
})
|
||||
const bytes = new Uint8Array(await response.arrayBuffer())
|
||||
return { method: 'POST', path, http: response.status, body: null, raw: null,
|
||||
contentType: response.headers.get('content-type'), byteLength: bytes.length,
|
||||
pdfMagic: String.fromCharCode(...bytes.slice(0, 4)),
|
||||
requestId: response.headers.get('x-request-id'), traceId: response.headers.get('x-trace-id') }
|
||||
} catch (error) {
|
||||
return { method: 'POST', path, http: 0, body: null, raw: String(error), contentType: null,
|
||||
byteLength: 0, pdfMagic: null, requestId: null, traceId: null }
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyPalletLabels(context, fixture, loadingPlanId) {
|
||||
if (fixture.destinationType !== 'FBA' || fixture.fulfillmentType === 'ONE_CLICK_DROPSHIP') return null
|
||||
const warehouseId = id(fixture.warehouseId)
|
||||
const base = `/api/platform/v1/first-leg/loading-plans/${encodeURIComponent(loadingPlanId)}/pallet-labels`
|
||||
const path = `${base}/prepare?warehouseId=${encodeURIComponent(warehouseId)}`
|
||||
const preparedResponse = await context.request('POST', path, {})
|
||||
const manifest = context.apiSuccess(MODULE, '生成并读取按 FBA 仓分组的散货托盘码清单', preparedResponse, '', OPTIONS)
|
||||
const labels = (manifest?.groups || []).flatMap((group) => group?.labels || [])
|
||||
const codesValid = labels.length > 0 && labels.every((label) => {
|
||||
const index = Number(label?.palletIndex)
|
||||
return id(label?.containerNo) === id(fixture.containerNo)
|
||||
&& id(label?.destinationWarehouseInternalCode)
|
||||
&& id(label?.palletCode) === `${fixture.containerNo}-${label.destinationWarehouseInternalCode}-${String(index).padStart(3, '0')}`
|
||||
})
|
||||
const indexesValid = (manifest?.groups || []).every((group) =>
|
||||
(group?.labels || []).every((label, index) => Number(label?.palletIndex) === index + 1))
|
||||
context.assert(MODULE, '散货托盘码使用柜号-FBA内部编号-仓内连续下标', preparedResponse,
|
||||
id(manifest?.containerNo) === id(fixture.containerNo)
|
||||
&& Number(manifest?.totalCount) === labels.length && codesValid && indexesValid,
|
||||
`containerNo=${manifest?.containerNo || 'missing'}, groups=${manifest?.groups?.length ?? 0}, labels=${labels.length}`,
|
||||
OPTIONS)
|
||||
|
||||
const replayResponse = await context.request('POST', path, {})
|
||||
const replay = context.apiSuccess(MODULE, '重复生成散货托盘码返回稳定清单', replayResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '散货托盘码重复生成零漂移', replayResponse,
|
||||
JSON.stringify(replay) === JSON.stringify(manifest), `labels=${labels.length}`, OPTIONS)
|
||||
|
||||
const printPath = `${base}/print?warehouseId=${encodeURIComponent(warehouseId)}`
|
||||
const allPdf = await requestPdf(context, printPath, { destinationWarehouseCode: null, count: null })
|
||||
context.addStep(MODULE, '打印全部 FBA 仓散货托盘码 PDF', allPdf,
|
||||
allPdf.http === 200 && allPdf.contentType?.toLowerCase().includes('application/pdf')
|
||||
&& allPdf.pdfMagic === '%PDF' && allPdf.byteLength > 0,
|
||||
`HTTP=${allPdf.http}, type=${allPdf.contentType || 'missing'}, bytes=${allPdf.byteLength}`, OPTIONS)
|
||||
const group = manifest?.groups?.[0]
|
||||
const selectedPdf = await requestPdf(context, printPath,
|
||||
{ destinationWarehouseCode: group?.destinationWarehouseCode, count: 1 })
|
||||
context.addStep(MODULE, '按指定 FBA 仓补打 1 张托盘码 PDF', selectedPdf,
|
||||
Boolean(group?.destinationWarehouseCode) && selectedPdf.http === 200
|
||||
&& selectedPdf.contentType?.toLowerCase().includes('application/pdf')
|
||||
&& selectedPdf.pdfMagic === '%PDF' && selectedPdf.byteLength > 0,
|
||||
`warehouse=${group?.destinationWarehouseCode || 'missing'}, HTTP=${selectedPdf.http}, bytes=${selectedPdf.byteLength}`,
|
||||
OPTIONS)
|
||||
return manifest
|
||||
}
|
||||
function blockResourceIdentity(resource) {
|
||||
return JSON.stringify({
|
||||
blockId: id(resource?.blockId), slotNo: Number(resource?.slotNo),
|
||||
@@ -490,6 +554,7 @@ export async function run(context) {
|
||||
inventoryBlockSettlementVerified: expectedBlocks.length > 0
|
||||
&& releasedOrTransferredBlocks.every((item) => item.verified) && completedInventoryReleased,
|
||||
}
|
||||
const palletLabelManifest = await verifyPalletLabels(context, fixture, loadingPlanId)
|
||||
const producer = {
|
||||
marker: context.context?.phase4ProducerMatrixMarker || context.marker,
|
||||
eventType: 'FIRST_LEG_LOADING_PLAN_COMPLETED',
|
||||
@@ -514,6 +579,7 @@ export async function run(context) {
|
||||
destinationType: fixture.destinationType || null,
|
||||
destinationWarehouseId: id(fixture.destinationWarehouseId),
|
||||
destinationWarehouseCode: fixture.destinationWarehouseCode || null,
|
||||
palletLabelManifest,
|
||||
containerNo: fixture.containerNo || null,
|
||||
sourceStatus: 'LOADED',
|
||||
verification: 'PRODUCED_IN_COMPLETE_TRANSACTION_PENDING_BRIDGE_CONSUMER_HTTP',
|
||||
|
||||
@@ -69,6 +69,25 @@ test('records LOADED and clears the reason only after a real LOADED reread', ()
|
||||
assert.equal(result.notCleanedReason, null)
|
||||
})
|
||||
|
||||
test('finalize acceptance covers stable pallet generation and both print modes', () => {
|
||||
const value = source('./phase3-loading-finalize.mjs')
|
||||
assert.match(value, /pallet-labels`/)
|
||||
assert.match(value, /`\$\{base\}\/prepare\?warehouseId=/)
|
||||
assert.match(value, /柜号-FBA内部编号-仓内连续下标/)
|
||||
assert.match(value, /重复生成散货托盘码返回稳定清单/)
|
||||
assert.match(value, /destinationWarehouseCode: null, count: null/)
|
||||
assert.match(value, /按指定 FBA 仓补打 1 张托盘码 PDF/)
|
||||
assert.match(value, /pdfMagic === '%PDF'/)
|
||||
assert.match(value, /palletLabelManifest,/)
|
||||
})
|
||||
|
||||
test('overseas conversion proves source-code preservation and native code generation boundaries', () => {
|
||||
const value = source('./phase4-overseas-pda.mjs')
|
||||
assert.match(value, /头程 FBA 散货托盘码跨区原样用于实体托盘/)
|
||||
assert.match(value, /标准海外仓订单由海外仓生成本地实体托盘码/)
|
||||
assert.match(value, /actualPalletCodes\.every\(\(code\) => code\.startsWith\('PLT-'\)\)/)
|
||||
})
|
||||
|
||||
test('container loading follows push, claim, real pick, completed sequence', () => {
|
||||
const value = source('./phase3-container-loading.mjs')
|
||||
assert.match(value, /const containerDetail = containerRecord\(context\.apiSuccess/)
|
||||
|
||||
@@ -350,6 +350,24 @@ async function convertReceivingContainers(context, producers) {
|
||||
&& convertedInboundCodes.size === inboundCodes,
|
||||
`plans=${plans.length}, inboundCodes=${convertedInboundCodes.size}, expected=${inboundCodes}; ${trace(convertedResponse)}`, OPTIONS)
|
||||
if (plans.length !== inboundCodes) return false
|
||||
const actualPalletCodes = plans.flatMap((item) => Array.isArray(item?.pallets) ? item.pallets : [])
|
||||
.map((pallet) => id(pallet?.palletNo)).filter(nonBlank).sort()
|
||||
const expectedPalletCodes = (producer?.palletLabelManifest?.groups || [])
|
||||
.flatMap((group) => group?.labels || []).map((label) => id(label?.palletCode)).filter(nonBlank).sort()
|
||||
if (producer?.destinationType === 'FBA' && producer?.fulfillmentType !== 'ONE_CLICK_DROPSHIP') {
|
||||
context.assert(MODULE, `头程 FBA 散货托盘码跨区原样用于实体托盘 ${containerNo}`, convertedResponse,
|
||||
expectedPalletCodes.length > 0
|
||||
&& JSON.stringify(actualPalletCodes) === JSON.stringify(expectedPalletCodes),
|
||||
`source=${expectedPalletCodes.join(',') || 'missing'}, overseas=${actualPalletCodes.join(',') || 'missing'}`,
|
||||
OPTIONS)
|
||||
}
|
||||
if (producer?.destinationType === 'OVERSEAS' && producer?.fulfillmentType !== 'ONE_CLICK_DROPSHIP') {
|
||||
context.assert(MODULE, `标准海外仓订单由海外仓生成本地实体托盘码 ${containerNo}`, convertedResponse,
|
||||
expectedPalletCodes.length === 0 && actualPalletCodes.length > 0
|
||||
&& actualPalletCodes.every((code) => code.startsWith('PLT-')),
|
||||
`sourceCount=${expectedPalletCodes.length}, overseas=${actualPalletCodes.join(',') || 'missing'}`,
|
||||
OPTIONS)
|
||||
}
|
||||
rememberGeneratedPlans(context, plans)
|
||||
const replayResponse = await context.requestOverseas('POST',
|
||||
'/api/platform/v1/last-leg/inbound-plans/convert-container', body,
|
||||
|
||||
@@ -168,22 +168,23 @@ async function verifyDestinationMergeFeeAndExport(context, details, producer) {
|
||||
{ orderIds: allIds, palletMergeRequired: false })
|
||||
context.assert(MODULE, '批量合托分组取消成功', batchCleared.response, batchCleared.data == null, trace(batchCleared.response), OPTIONS)
|
||||
|
||||
const feeItemCode = `${context.marker}-TAIL-FEE`.slice(0, 64)
|
||||
const feeItemName = `尾程费用-${context.marker}`.slice(0, 200)
|
||||
const feeItem = `${context.marker}-TAIL-FEE`.slice(0, 128)
|
||||
const fee = await api(context, 'POST', '新增本轮尾程订单费用',
|
||||
query(`${ORDERS}/${encodeURIComponent(id(representative.id))}/fees`, { customerId: id(representative.customerId) }),
|
||||
{ feeItemCode, feeItemName, direction: 'RECEIVABLE', currency: 'USD', amount: 0.01,
|
||||
businessDate: new Date().toISOString().slice(0, 10) })
|
||||
{ feeItemCode: feeItem.slice(0, 64), feeItemName: feeItem, direction: 'RECEIVABLE',
|
||||
currency: 'USD', amount: 0.01, businessDate: new Date().toISOString().slice(0, 10) },
|
||||
{ 'Idempotency-Key': `${context.marker}-tail-fee`.slice(0, 128) })
|
||||
context.assert(MODULE, '尾程费用冻结币种金额和审核状态', fee.response,
|
||||
id(fee.data?.orderId) === id(representative.id) && fee.data?.feeItemCode === feeItemCode
|
||||
&& fee.data?.feeItemName === feeItemName && fee.data?.direction === 'RECEIVABLE'
|
||||
&& fee.data?.currency === 'USD' && Number(fee.data?.amount) === 0.01
|
||||
&& fee.data?.reviewStatus === 'PENDING_REVIEW',
|
||||
id(fee.data?.orderId) === id(representative.id) && fee.data?.feeItemName === feeItem
|
||||
&& fee.data?.originalCurrency === 'USD' && Number(fee.data?.originalAmount) === 0.01
|
||||
&& fee.data?.currency === 'CNY' && Number(fee.data?.amount) > 0
|
||||
&& fee.data?.reviewStatus === 'PENDING',
|
||||
trace(fee.response), OPTIONS)
|
||||
const feeRead = await detail(context, representative, '回查尾程订单费用明细')
|
||||
context.assert(MODULE, '尾程费用详情可追溯', feeRead.response,
|
||||
feeRead.data?.fees?.some((row) => row?.feeItemCode === feeItemCode && row?.feeItemName === feeItemName
|
||||
&& row?.direction === 'RECEIVABLE' && Number(row?.amount) === 0.01), trace(feeRead.response), OPTIONS)
|
||||
feeRead.data?.fees?.some((row) => row?.feeItemName === feeItem
|
||||
&& row?.originalCurrency === 'USD' && Number(row?.originalAmount) === 0.01
|
||||
&& row?.currency === 'CNY' && Number(row?.amount) > 0), trace(feeRead.response), OPTIONS)
|
||||
|
||||
const exported = await context.requestOverseasBinary('GET', query(`${ORDERS}/export`, {
|
||||
customerId: id(representative.customerId), containerNo: producer.containerNo,
|
||||
|
||||
Reference in New Issue
Block a user