fix(acceptance): require FBA pallet label configuration
This commit is contained in:
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
|
|||||||
import { readFileSync } from 'node:fs'
|
import { readFileSync } from 'node:fs'
|
||||||
import test from 'node:test'
|
import test from 'node:test'
|
||||||
|
|
||||||
import { findPricedOrderRoute, findPricedOrderRouteAcrossOrigins } from './orders.mjs'
|
import { eligibleOrderDestinations, findPricedOrderRoute, findPricedOrderRouteAcrossOrigins } from './orders.mjs'
|
||||||
|
|
||||||
const source = readFileSync(new URL('orders.mjs', import.meta.url), 'utf8')
|
const source = readFileSync(new URL('orders.mjs', import.meta.url), 'utf8')
|
||||||
|
|
||||||
@@ -18,6 +18,16 @@ test('orders fixture verifies the complete pricing tuple before selecting an FBA
|
|||||||
assert.match(source, /warehouse\?\.status === 'ACTIVE'/)
|
assert.match(source, /warehouse\?\.status === 'ACTIVE'/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('FBA order fixture excludes warehouses without the internal code required by pallet labels', () => {
|
||||||
|
const warehouses = [
|
||||||
|
{ id: 'abe3', warehouseCode: 'ABE3', status: 'ACTIVE', internalCode: null },
|
||||||
|
{ id: 'abe4', warehouseCode: 'ABE4', status: 'ACTIVE', internalCode: '126' },
|
||||||
|
{ id: 'abe8', warehouseCode: 'ABE8', status: 'INACTIVE', internalCode: '39' },
|
||||||
|
]
|
||||||
|
assert.deepEqual(eligibleOrderDestinations(warehouses, 'FBA').map((item) => item.warehouseCode), ['ABE4'])
|
||||||
|
assert.deepEqual(eligibleOrderDestinations(warehouses, 'OVERSEAS').map((item) => item.warehouseCode), ['ABE3', 'ABE4'])
|
||||||
|
})
|
||||||
|
|
||||||
test('pricing selection skips an ACTIVE domestic warehouse with an empty channel catalog', async () => {
|
test('pricing selection skips an ACTIVE domestic warehouse with an empty channel catalog', async () => {
|
||||||
const channelCalls = []
|
const channelCalls = []
|
||||||
const result = await findPricedOrderRouteAcrossOrigins({
|
const result = await findPricedOrderRouteAcrossOrigins({
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ export function requestedOrderDestinationType(context) {
|
|||||||
const value = String(context?.context?.orderDestinationType || 'FBA').trim().toUpperCase()
|
const value = String(context?.context?.orderDestinationType || 'FBA').trim().toUpperCase()
|
||||||
return ['FBA', 'OVERSEAS', 'PRIVATE'].includes(value) ? value : 'FBA'
|
return ['FBA', 'OVERSEAS', 'PRIVATE'].includes(value) ? value : 'FBA'
|
||||||
}
|
}
|
||||||
|
export function eligibleOrderDestinations(values, destinationType) {
|
||||||
|
const active = (Array.isArray(values) ? values : []).filter((warehouse) => warehouse?.status === 'ACTIVE')
|
||||||
|
return destinationType === 'FBA'
|
||||||
|
? active.filter((warehouse) => String(warehouse?.internalCode || '').trim() !== '')
|
||||||
|
: active
|
||||||
|
}
|
||||||
export function approvedInboundReady(orderDetail, taskResponse, tenantId, orderId) {
|
export function approvedInboundReady(orderDetail, taskResponse, tenantId, orderId) {
|
||||||
const summary = orderDetail?.summary
|
const summary = orderDetail?.summary
|
||||||
const task = success(taskResponse) ? taskResponse.body?.data : null
|
const task = success(taskResponse) ? taskResponse.body?.data : null
|
||||||
@@ -251,13 +257,13 @@ async function loadMasterData(context, merchantToken) {
|
|||||||
records(destinationPage).length > 0, `count=${records(destinationPage).length}`)
|
records(destinationPage).length > 0, `count=${records(destinationPage).length}`)
|
||||||
}
|
}
|
||||||
const receivings = records(domesticPage).filter((warehouse) => warehouse?.status === 'ACTIVE')
|
const receivings = records(domesticPage).filter((warehouse) => warehouse?.status === 'ACTIVE')
|
||||||
let destinations = records(destinationPage).filter((warehouse) => warehouse?.status === 'ACTIVE')
|
let destinations = eligibleOrderDestinations(records(destinationPage), destinationType)
|
||||||
if (Number(destinationPage?.total) > destinations.length) {
|
if (Number(destinationPage?.total) > destinations.length) {
|
||||||
const nextResponse = await request(context, 'GET',
|
const nextResponse = await request(context, 'GET',
|
||||||
`/api/merchant/v1/warehouses?page=2&size=200&status=ACTIVE&warehouseType=${encodeURIComponent(destinationType)}`,
|
`/api/merchant/v1/warehouses?page=2&size=200&status=ACTIVE&warehouseType=${encodeURIComponent(destinationType)}`,
|
||||||
undefined, merchantToken)
|
undefined, merchantToken)
|
||||||
const nextPage = context.apiSuccess(MODULE, `Client 查询 ${destinationType} 目的仓第二页`, nextResponse)
|
const nextPage = context.apiSuccess(MODULE, `Client 查询 ${destinationType} 目的仓第二页`, nextResponse)
|
||||||
destinations = [...destinations, ...records(nextPage).filter((warehouse) => warehouse?.status === 'ACTIVE')]
|
destinations = [...destinations, ...eligibleOrderDestinations(records(nextPage), destinationType)]
|
||||||
}
|
}
|
||||||
if (receivings.length === 0 || (destinationType !== 'PRIVATE' && destinations.length === 0)) {
|
if (receivings.length === 0 || (destinationType !== 'PRIVATE' && destinations.length === 0)) {
|
||||||
throw new Error('缺少创建测试订单所需的收货仓或目的仓')
|
throw new Error('缺少创建测试订单所需的收货仓或目的仓')
|
||||||
|
|||||||
Reference in New Issue
Block a user