test(firstleg): resolve trucking fixtures from active catalogs

This commit is contained in:
2026-09-01 10:21:37 +08:00
parent 3d7990250f
commit 0613d1095e
2 changed files with 68 additions and 14 deletions
@@ -18,6 +18,12 @@ export function platformWarehouseIdentity(item) {
return { warehouseId: id(item?.warehouseId || item?.id || item?.warehouse?.id), platformTenantId: '0' }
}
export function activeCustomerIdentity(item) {
const customerId = id(item?.id || item?.tenantId)
const customerName = String(item?.tenantName || item?.customerName || item?.name || '').trim()
return customerId && customerName ? { customerId, customerName } : null
}
async function request(context, method, path, body, headers = {}) {
try {
const response = await fetch(`${context.options.gateway}${path}`, {
@@ -67,19 +73,39 @@ async function activeSupplier(context, category, suffix) {
}
async function bookingMaster(context, suffix) {
const tenantId = id(context.createdResources?.merchantQualificationFixture?.tenantId)
const customerName = String(context.options?.customerName || `全量验收下单客户-${suffix}`).trim()
const warehousesResponse = await request(context, 'GET', '/api/platform/v1/warehouse-admin?tenantId=0&status=ACTIVE&page=1&size=100')
for (const item of records(data(warehousesResponse))) {
const { warehouseId } = platformWarehouseIdentity(item)
if (!warehouseId) continue
const channelsResponse = await request(context, 'GET', `${BOOKINGS}/channels?originWarehouseId=${warehouseId}`)
const channel = (data(channelsResponse) || [])[0]
if (channel?.channelCode) return { customerId: tenantId, customerName, warehouseId,
channelCode: channel.channelCode, channelName: channel.channelName }
const fixtureCustomerId = id(context.createdResources?.merchantQualificationFixture?.tenantId
|| context.context?.customerId || context.customerId)
const customersResponse = await request(context, 'GET', '/api/platform/v1/iam/tenants?page=1&size=100&status=ACTIVE')
const candidates = records(data(customersResponse))
const customer = activeCustomerIdentity(candidates.find((item) =>
fixtureCustomerId && id(item?.id || item?.tenantId) === fixtureCustomerId) || candidates[0])
if (!customer) {
context.addStep(MODULE, '通过正式平台客户查询解析 ACTIVE 订舱客户', customersResponse, false,
`preferredCustomerId=${fixtureCustomerId || 'missing'}`, OPTIONS)
return null
}
context.addStep(MODULE, '解析具备有效海运渠道的平台仓库', warehousesResponse, false,
`platformTenantId=0, customerId=${tenantId || 'missing'}`, OPTIONS)
let lastWarehousesResponse = null
for (let page = 1; page <= 100; page++) {
const warehousesResponse = await request(context, 'GET',
`/api/platform/v1/warehouse-admin?tenantId=0&status=ACTIVE&page=${page}&size=100`)
lastWarehousesResponse = warehousesResponse
const warehousePage = data(warehousesResponse); const warehouseRows = records(warehousePage)
for (const item of warehouseRows) {
const { warehouseId } = platformWarehouseIdentity(item)
if (!warehouseId) continue
const channelsResponse = await request(context, 'GET', `${BOOKINGS}/channels?originWarehouseId=${warehouseId}`)
const channelRows = records(data(channelsResponse)); const channel = channelRows[0]
if (channel?.channelCode) {
context.addStep(MODULE, '完整分页平台仓并解析有效海运渠道', channelsResponse, true,
`warehousePage=${page}, warehouseRecords=${warehouseRows.length}, channelRecords=${channelRows.length}, warehouseId=${warehouseId}`, OPTIONS)
return { ...customer, warehouseId, channelCode: channel.channelCode, channelName: channel.channelName }
}
}
const total = Number(warehousePage?.total ?? warehouseRows.length)
if (warehouseRows.length === 0 || page * 100 >= total) break
}
context.addStep(MODULE, '解析具备有效海运渠道的平台仓库', lastWarehousesResponse, false,
`platformTenantId=0, customerId=${customer.customerId}`, OPTIONS)
return null
}