test(fba): preserve verified fleet and fulfillment acceptance workflows

This commit is contained in:
2026-10-03 06:26:33 +08:00
parent c55bd7f4b6
commit d858357c5d
52 changed files with 4217 additions and 103 deletions
@@ -131,6 +131,13 @@ function oceanDraft(context, suffix, master) {
}
}
export function portScheduleCustomerScope(bookingCustomerId) {
if (bookingCustomerId == null) return '0'
const value = String(bookingCustomerId)
if (!/^[1-9][0-9]*$/.test(value)) throw new Error('ocean booking customer scope must be null or a positive ID')
return value
}
async function ensureOceanBooking(context, suffix, master, preferredOceanBookingId = null) {
const existingId = id(preferredOceanBookingId || context.createdResources?.oceanBooking?.id)
if (existingId) {
@@ -139,7 +146,7 @@ async function ensureOceanBooking(context, suffix, master, preferredOceanBooking
`oceanBookingId=${existingId}`, OPTIONS)
return detail?.oceanBooking ? {
id: existingId,
customerId: id(detail.oceanBooking.customerId),
customerId: portScheduleCustomerScope(detail.oceanBooking.customerId),
allocatedContainerBookingIds: (detail.containers || [])
.map((item) => id(item?.containerBookingId)).filter(Boolean),
} : null
@@ -152,7 +159,7 @@ async function ensureOceanBooking(context, suffix, master, preferredOceanBooking
Boolean(oceanBookingId) && id(detail?.oceanBooking?.customerId) === id(master.customerId),
`oceanBookingId=${oceanBookingId || 'missing'}, customerId=${id(detail?.oceanBooking?.customerId) || 'missing'}`, OPTIONS)
return oceanBookingId ? {
id: oceanBookingId, customerId: id(detail.oceanBooking.customerId),
id: oceanBookingId, customerId: portScheduleCustomerScope(detail.oceanBooking.customerId),
allocatedContainerBookingIds: (detail.containers || [])
.map((item) => id(item?.containerBookingId)).filter(Boolean),
} : null
@@ -191,6 +198,12 @@ export async function run(context) {
Array.isArray(page?.records) && Number.isFinite(Number(page?.total)),
`records=${page?.records?.length ?? 'n/a'}, total=${page?.total ?? 'n/a'}`, OPTIONS)
const publicResponse = await request(context, 'GET', `${BASE}?customerId=0&page=1&size=5`)
const publicPage = context.apiSuccess(MODULE, '平台公共船期支持customerId=0查询', publicResponse, '', OPTIONS)
context.assert(MODULE, '平台公共船期查询不混入其他客户', publicResponse,
Array.isArray(publicPage?.records) && publicPage.records.every(row => id(row?.schedule?.customerId) === '0'),
`records=${publicPage?.records?.length ?? 'missing'}`, OPTIONS)
const master = await resolveOceanBookingMaster(context, MODULE)
if (!master) return
const flow = context.createdResources?.phase3Loading
@@ -206,7 +219,8 @@ export async function run(context) {
OPTIONS)
return
}
const payload = { expectedVersion: 0, data: scheduleData(context, suffix, ocean.id, knownAllocation, ocean.customerId), reason: context.marker }
const scheduleCustomerId = ocean.customerId
const payload = { expectedVersion: 0, data: scheduleData(context, suffix, ocean.id, knownAllocation, scheduleCustomerId), reason: context.marker }
const createKey = `${context.marker}-port-create`.slice(0, 128)
const createResponse = await request(context, 'POST', BASE, payload, { 'Idempotency-Key': createKey })
const created = context.apiSuccess(MODULE, '新增独立港务船期观测', createResponse, '', OPTIONS)
@@ -245,7 +259,7 @@ export async function run(context) {
}
const initialVersion = Number(created.portSchedule.schedule.version)
const expiredData = scheduleData(context, suffix, ocean.id, knownAllocation, master.customerId, true)
const expiredData = scheduleData(context, suffix, ocean.id, knownAllocation, scheduleCustomerId, true)
expiredData.sourceRef = payload.data.sourceRef
// 甩柜只修改原柜的船信息;柜次、订舱关联和船期任务身份保持不变。
expiredData.vesselName = `甩柜改配船-${suffix}`
@@ -305,7 +319,7 @@ export async function run(context) {
`inbounds=${expiredGate?.inbounds?.length ?? 'missing'}, obsoleteScheduleGate=${gateItems.some((item) => item?.code === 'SAILING_SCHEDULE')}`, OPTIONS)
}
const currentData = scheduleData(context, suffix, ocean.id, knownAllocation, master.customerId, false)
const currentData = scheduleData(context, suffix, ocean.id, knownAllocation, scheduleCustomerId, false)
currentData.sourceRef = payload.data.sourceRef
currentData.sourceType = 'MANUAL'
currentData.sourceName = `平台人工兜底-${suffix}`