From d965a82cfd0b64c818bb310937375af57a109b93 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Tue, 1 Sep 2026 22:54:02 +0800 Subject: [PATCH] test: accept automatic outbound confirmation --- .../phase3-outbound-dispatch.mjs | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/scripts/admin-test-env-modules/phase3-outbound-dispatch.mjs b/scripts/admin-test-env-modules/phase3-outbound-dispatch.mjs index cd8a4ae98..c919ac212 100644 --- a/scripts/admin-test-env-modules/phase3-outbound-dispatch.mjs +++ b/scripts/admin-test-env-modules/phase3-outbound-dispatch.mjs @@ -98,30 +98,41 @@ export async function run(context) { } const confirmBody = { expectedVersion, remark: context.marker } - const confirmResponse = await request(context, 'POST', `${BASE}/${encodeURIComponent(containerBookingId)}/confirm`, confirmBody, - { 'Idempotency-Key': confirmKey }) - const confirmed = context.apiSuccess(MODULE, '确认国内出仓进入等待装船', confirmResponse, '', OPTIONS) - context.assert(MODULE, 'confirm-dispatch 推进 WAITING_FOR_LOADING 并递增版本', confirmResponse, - confirmed?.aggregate?.dispatchStatus === 'WAITING_FOR_LOADING' - && confirmed?.aggregate?.inbounds?.every?.((item) => item?.inboundStatus === 'LOADED') - && Number(confirmed?.aggregate?.version) === expectedVersion + 1, - `dispatch=${confirmed?.aggregate?.dispatchStatus || 'missing'}, inbounds=${confirmed?.aggregate?.inbounds?.length ?? 'missing'}, version=${confirmed?.aggregate?.version ?? 'missing'}`, OPTIONS) + let confirmed + if (aggregate.dispatchStatus === 'WAITING_FOR_LOADING') { + confirmed = detail + context.assert(MODULE, '整柜报关完成事件已自动确认国内出仓', detailResponse, + confirmed?.aggregate?.dispatchStatus === 'WAITING_FOR_LOADING' + && confirmed?.aggregate?.inbounds?.every?.((item) => item?.inboundStatus === 'LOADED') + && confirmed?.timeline?.some?.((item) => item.module === 'OUTBOUND_DISPATCH' + && item.action === 'CONFIRM_DISPATCH'), + `dispatch=${confirmed?.aggregate?.dispatchStatus || 'missing'}, version=${confirmed?.aggregate?.version ?? 'missing'}`, OPTIONS) + } else { + const confirmResponse = await request(context, 'POST', `${BASE}/${encodeURIComponent(containerBookingId)}/confirm`, confirmBody, + { 'Idempotency-Key': confirmKey }) + confirmed = context.apiSuccess(MODULE, '确认国内出仓进入等待装船', confirmResponse, '', OPTIONS) + context.assert(MODULE, 'confirm-dispatch 推进 WAITING_FOR_LOADING 并递增版本', confirmResponse, + confirmed?.aggregate?.dispatchStatus === 'WAITING_FOR_LOADING' + && confirmed?.aggregate?.inbounds?.every?.((item) => item?.inboundStatus === 'LOADED') + && Number(confirmed?.aggregate?.version) === expectedVersion + 1, + `dispatch=${confirmed?.aggregate?.dispatchStatus || 'missing'}, inbounds=${confirmed?.aggregate?.inbounds?.length ?? 'missing'}, version=${confirmed?.aggregate?.version ?? 'missing'}`, OPTIONS) + + const replayResponse = await request(context, 'POST', `${BASE}/${encodeURIComponent(containerBookingId)}/confirm`, confirmBody, + { 'Idempotency-Key': confirmKey }) + const replay = context.apiSuccess(MODULE, 'confirm-dispatch 幂等重放', replayResponse, '', OPTIONS) + context.assert(MODULE, '确认重放保持同一终态和版本', replayResponse, + replay?.aggregate?.dispatchStatus === 'WAITING_FOR_LOADING' + && Number(replay?.aggregate?.version) === Number(confirmed?.aggregate?.version), + `version=${replay?.aggregate?.version ?? 'missing'}`, OPTIONS) + + const hashConflict = await request(context, 'POST', `${BASE}/${encodeURIComponent(containerBookingId)}/confirm`, { ...confirmBody, remark: 'forged' }, + { 'Idempotency-Key': confirmKey }) + context.addStep(MODULE, '相同 Idempotency-Key 不同请求拒绝', hashConflict, + hashConflict.http === 200 && codeOf(hashConflict) === 'A0409', + `HTTP=${hashConflict.http}, code=${codeOf(hashConflict)}`, OPTIONS) + } if (!confirmed?.aggregate) return - const replayResponse = await request(context, 'POST', `${BASE}/${encodeURIComponent(containerBookingId)}/confirm`, confirmBody, - { 'Idempotency-Key': confirmKey }) - const replay = context.apiSuccess(MODULE, 'confirm-dispatch 幂等重放', replayResponse, '', OPTIONS) - context.assert(MODULE, '确认重放保持同一终态和版本', replayResponse, - replay?.aggregate?.dispatchStatus === 'WAITING_FOR_LOADING' - && Number(replay?.aggregate?.version) === Number(confirmed?.aggregate?.version), - `version=${replay?.aggregate?.version ?? 'missing'}`, OPTIONS) - - const hashConflict = await request(context, 'POST', `${BASE}/${encodeURIComponent(containerBookingId)}/confirm`, { ...confirmBody, remark: 'forged' }, - { 'Idempotency-Key': confirmKey }) - context.addStep(MODULE, '相同 Idempotency-Key 不同请求拒绝', hashConflict, - hashConflict.http === 200 && codeOf(hashConflict) === 'A0409', - `HTTP=${hashConflict.http}, code=${codeOf(hashConflict)}`, OPTIONS) - const reverseKey = `${context.marker}-outbound-reverse`.slice(0, 128) const reverseResponse = await request(context, 'POST', `${BASE}/${encodeURIComponent(containerBookingId)}/reverse`, { expectedVersion: Number(confirmed.aggregate.version), remark: context.marker,