diff --git a/scripts/admin-test-env-modules/orders-pricing-fixture-contract.test.mjs b/scripts/admin-test-env-modules/orders-pricing-fixture-contract.test.mjs index 1cdcc0f66..5198741cb 100644 --- a/scripts/admin-test-env-modules/orders-pricing-fixture-contract.test.mjs +++ b/scripts/admin-test-env-modules/orders-pricing-fixture-contract.test.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' 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') @@ -18,6 +18,16 @@ test('orders fixture verifies the complete pricing tuple before selecting an FBA 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 () => { const channelCalls = [] const result = await findPricedOrderRouteAcrossOrigins({ diff --git a/scripts/admin-test-env-modules/orders.mjs b/scripts/admin-test-env-modules/orders.mjs index b64056891..56d45e27b 100644 --- a/scripts/admin-test-env-modules/orders.mjs +++ b/scripts/admin-test-env-modules/orders.mjs @@ -55,6 +55,12 @@ export function requestedOrderDestinationType(context) { const value = String(context?.context?.orderDestinationType || 'FBA').trim().toUpperCase() 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) { const summary = orderDetail?.summary 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}`) } 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) { const nextResponse = await request(context, 'GET', `/api/merchant/v1/warehouses?page=2&size=200&status=ACTIVE&warehouseType=${encodeURIComponent(destinationType)}`, undefined, merchantToken) 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)) { throw new Error('缺少创建测试订单所需的收货仓或目的仓')