test: accept automatic outbound confirmation
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user