test(firstleg): parse platform warehouse scope explicitly

This commit is contained in:
2026-09-01 10:17:41 +08:00
parent 3d6216910f
commit cdcf3e0f4f
2 changed files with 16 additions and 3 deletions
@@ -2,7 +2,16 @@ import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { inspectOceanBookingIdentity, truckAppointmentPayload } from './truck-appointments.mjs'
import { inspectOceanBookingIdentity, platformWarehouseIdentity, truckAppointmentPayload } from './truck-appointments.mjs'
test('platform warehouse scope is fixed to zero without requiring response tenantId', () => {
assert.deepEqual(platformWarehouseIdentity({ warehouseId: '41', warehouseName: '宁波仓' }),
{ warehouseId: '41', platformTenantId: '0' })
assert.deepEqual(platformWarehouseIdentity({ id: 42, warehouseName: '义乌仓' }),
{ warehouseId: '42', platformTenantId: '0' })
const source = readFileSync(new URL('truck-appointments.mjs', import.meta.url), 'utf8')
assert.doesNotMatch(source, /item\?\.tenantId|item\.tenantId/)
})
test('booking identity is marker scoped and contains no customer snapshot', () => {
const result = inspectOceanBookingIdentity('RUN-2', { id: '91', marker: 'RUN-2', warehouseId: '41' })
@@ -14,6 +14,10 @@ function data(response) { return codeOf(response) === '200' ? response.body.data
function failure(response) { return response?.http === 0 || response?.http >= 400 || (response?.http === 200 && codeOf(response) !== '200') }
function records(value) { return Array.isArray(value) ? value : value?.records || [] }
export function platformWarehouseIdentity(item) {
return { warehouseId: id(item?.warehouseId || item?.id || item?.warehouse?.id), platformTenantId: '0' }
}
async function request(context, method, path, body, headers = {}) {
try {
const response = await fetch(`${context.options.gateway}${path}`, {
@@ -67,7 +71,7 @@ async function bookingMaster(context, suffix) {
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 = id(item?.id || item?.warehouse?.id)
const { warehouseId } = platformWarehouseIdentity(item)
if (!warehouseId) continue
const channelsResponse = await request(context, 'GET', `${BOOKINGS}/channels?originWarehouseId=${warehouseId}`)
const channel = (data(channelsResponse) || [])[0]
@@ -75,7 +79,7 @@ async function bookingMaster(context, suffix) {
channelCode: channel.channelCode, channelName: channel.channelName }
}
context.addStep(MODULE, '解析具备有效海运渠道的平台仓库', warehousesResponse, false,
`tenantId=${tenantId || 'missing'}`, OPTIONS)
`platformTenantId=0, customerId=${tenantId || 'missing'}`, OPTIONS)
return null
}