From e5c6e03033e939d2940ecd05860e26ea3cee2dbf Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Sat, 8 Aug 2026 20:47:26 +0800 Subject: [PATCH] test(admin): stabilize service center acceptance fixtures --- scripts/admin-test-env-modules/ocean-bookings.mjs | 2 +- .../service-center-flow.mjs | 6 +++++- .../admin-test-env-modules/truck-appointments.mjs | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/admin-test-env-modules/ocean-bookings.mjs b/scripts/admin-test-env-modules/ocean-bookings.mjs index c451e3df2..142707b88 100644 --- a/scripts/admin-test-env-modules/ocean-bookings.mjs +++ b/scripts/admin-test-env-modules/ocean-bookings.mjs @@ -37,7 +37,7 @@ export async function run(context) { context.apiSuccess(MODULE, '创建隔离海运订舱', createResponse, `key=${key}`, OPTIONS) context.assert(MODULE, '订舱 DTO 字段、DRAFT 和9类关联字段完整', createResponse, Boolean(bookingId) && detail?.oceanBooking?.status === 'DRAFT' && detail?.parties?.length === 3 && detail?.containerRequirements?.length === 1, `bookingId=${bookingId || 'missing'}, parties=${detail?.parties?.length ?? 'n/a'}, requirements=${detail?.containerRequirements?.length ?? 'n/a'}`, OPTIONS) if (!bookingId) return - context.createdResources.oceanBooking = { id: bookingId, marker: context.marker, finalStatus: 'RELEASED' } + context.createdResources.oceanBooking = { id: bookingId, customerId: '10001', marker: context.marker, finalStatus: 'RELEASED' } const replay = await createBooking(context, suffix, key) context.assert(MODULE, '创建 Idempotency-Key 重放返回同一订舱', replay, String(data(replay)?.oceanBooking?.id) === bookingId, `first=${bookingId}, replay=${id(data(replay)?.oceanBooking?.id)}`, OPTIONS) const path = `${BASE}/${bookingId}` diff --git a/scripts/admin-test-env-modules/service-center-flow.mjs b/scripts/admin-test-env-modules/service-center-flow.mjs index 538d42774..6dbc877a1 100644 --- a/scripts/admin-test-env-modules/service-center-flow.mjs +++ b/scripts/admin-test-env-modules/service-center-flow.mjs @@ -15,7 +15,11 @@ export async function run(context) { } const suffix = context.marker.replace(/\D/g, '').slice(-10) - const customerId = id(context.context?.customerId || '10001') + const oceanResponse = await context.request('GET', `${OCEAN}/${ocean.id}`) + const oceanDetail = context.apiSuccess(MODULE, '读取跨服务链路订舱真实客户归属', oceanResponse, `oceanBookingId=${ocean.id}`, OPTIONS) + const customerId = id(oceanDetail?.oceanBooking?.customerId) + context.assert(MODULE, '跨服务链路订舱客户归属有效', oceanResponse, Boolean(customerId), `customerId=${customerId || 'missing'}`, OPTIONS) + if (!customerId) return const payload = { outboundOrderId: null, oceanBookingId: ocean.id, containerBookingId: null, loadingPlanId: null, warehouseId: id(context.createdResources?.warehouse?.id || context.context?.warehouseId || '193000000000000001'), diff --git a/scripts/admin-test-env-modules/truck-appointments.mjs b/scripts/admin-test-env-modules/truck-appointments.mjs index c5e3068c0..435a4a009 100644 --- a/scripts/admin-test-env-modules/truck-appointments.mjs +++ b/scripts/admin-test-env-modules/truck-appointments.mjs @@ -25,7 +25,8 @@ async function request(context, method, path, body, headers = {}) { async function uploadAttachment(context, appointmentId) { const path = `${BASE}/${appointmentId}/attachments/upload?attachmentType=ACCEPTANCE_EVIDENCE` const form = new FormData() - form.append('file', new Blob([new TextEncoder().encode(context.marker)], { type: 'text/plain' }), `${context.marker}-truck.txt`) + const png = Uint8Array.from([137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,1,0,0,0,1,8,6,0,0,0,31,21,196,137,0,0,0,13,73,68,65,84,8,215,99,248,207,192,240,31,0,5,0,1,255,137,153,61,29,0,0,0,0,73,69,78,68,174,66,96,130]) + form.append('file', new Blob([png], { type: 'image/png' }), `${context.marker}-truck.png`) try { const response = await fetch(`${context.options.gateway}${path}`, { method: 'POST', headers: { Accept: 'application/json', Authorization: `Bearer ${context.token}` }, body: form, signal: AbortSignal.timeout(60_000) }) const raw = await response.text(); let payload = null @@ -59,6 +60,16 @@ export async function run(context) { context.addStep(MODULE, `拖车预约 ${status} 筛选`, response, response.http === 200 && codeOf(response) === '200' && Array.isArray(result?.records) && result.records.every((item) => item.status === status), `HTTP=${response.http}, code=${codeOf(response)}, records=${result?.records?.length ?? 'n/a'}`, OPTIONS) } + if (!context.createdResources?.oceanBooking?.id) { + const oceanBookings = await import(new URL('./ocean-bookings.mjs', import.meta.url)) + await oceanBookings.run(context) + } + if (!context.createdResources?.oceanBooking?.id) { + context.addStep(MODULE, '创建拖车预约所需隔离订舱 fixture', null, false, + '本轮 ocean-bookings 未返回可关联的隔离订舱,未使用历史订舱', OPTIONS) + return + } + const createResponse = await request(context, 'POST', BASE, payload(context, suffix)); const appointment = context.apiSuccess(MODULE, '创建隔离拖车预约', createResponse, '', OPTIONS) const appointmentId = id(appointment?.id) context.assert(MODULE, '拖车预约费用、司机车辆和地址字段完整', createResponse, Boolean(appointmentId) && appointment?.status === 'DRAFT' && appointment?.payableAmount != null && appointment?.receivableAmount != null, `id=${appointmentId || 'missing'}, status=${appointment?.status || 'missing'}`, OPTIONS) @@ -66,7 +77,7 @@ export async function run(context) { context.createdResources.truckAppointment = { id: appointmentId, marker: context.marker, finalStatus: 'COMPLETED' } const path = `${BASE}/${appointmentId}` - const upload = await uploadAttachment(context, appointmentId); const attachment = context.apiSuccess(MODULE, '上传本轮拖车预约文本附件', upload, `fileName=${context.marker}-truck.txt`, OPTIONS) + const upload = await uploadAttachment(context, appointmentId); const attachment = context.apiSuccess(MODULE, '上传本轮拖车预约图片附件', upload, `fileName=${context.marker}-truck.png`, OPTIONS) const attachmentId = id(attachment?.id) context.assert(MODULE, '附件引用归属、类型和哈希元数据完整', upload, Boolean(attachmentId) && id(attachment?.appointmentId) === appointmentId && attachment?.attachmentType === 'ACCEPTANCE_EVIDENCE' && Boolean(attachment?.fileId) && Boolean(attachment?.fileHash), `attachmentId=${attachmentId || 'missing'}, fileId=${attachment?.fileId || 'missing'}`, OPTIONS) const attachments = await request(context, 'GET', `${path}/attachments`); const attachmentList = context.apiSuccess(MODULE, '查询拖车预约附件列表', attachments, '', OPTIONS)