test(acceptance): follow automatic departure flow
This commit is contained in:
@@ -77,10 +77,30 @@ async function oceanAction(context, value, endpoint, body = {}) {
|
||||
return next
|
||||
}
|
||||
|
||||
async function uploadBookingConfirmation(context, value, index) {
|
||||
const bookingId = id(value?.oceanBooking?.id)
|
||||
const form = new FormData()
|
||||
form.append('expectedVersion', String(Number(value?.oceanBooking?.version)))
|
||||
form.append('documentType', 'BOOKING_CONFIRMATION')
|
||||
form.append('file', new Blob([`${context.marker}-BOOKING_CONFIRMATION-${index}`],
|
||||
{ type: 'text/plain' }), `booking-confirmation-${suffix(context, index)}.txt`)
|
||||
const response = await context.requestMultipart('POST',
|
||||
`${OCEAN_BASE}/${bookingId}/documents/upload`, form, context.token,
|
||||
{ 'Idempotency-Key': key(context, `ocean-booking-document-${index}`) })
|
||||
const document = context.apiSuccess(MODULE, `订舱样本 ${index} 上传订舱确认文件`, response, '', OPTIONS)
|
||||
if (!Number.isInteger(Number(document?.bookingVersion))) {
|
||||
throw new Error(`订舱样本 ${index} 未返回有效文件版本`)
|
||||
}
|
||||
return { ...value, oceanBooking: { ...value.oceanBooking, version: Number(document.bookingVersion) } }
|
||||
}
|
||||
|
||||
async function buildOcean(context, template, status, index) {
|
||||
let value = await createOcean(context, template, index)
|
||||
if (status === 'DRAFT') return value
|
||||
if (status === 'RELEASED') return oceanAction(context, value, 'release')
|
||||
if (status === 'RELEASED') {
|
||||
value = await uploadBookingConfirmation(context, value, index)
|
||||
return oceanAction(context, value, 'release')
|
||||
}
|
||||
throw new Error(`unsupported ocean status ${status}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ export async function run(context) {
|
||||
const warehouseRemarkPath = `${smartLoadingBase}/plans/${loadingPlanId}/items/${id(assignedItem.id)}/warehouse-remark`
|
||||
const warehouseRemarkBody = Object.freeze({ warehouseRemark,
|
||||
expectedPlanVersion: Number(assignedLoadingPlan.version), expectedItemVersion: Number(assignedItem.version),
|
||||
operationId: `${context.marker}-warehouse-remark`.slice(0, 128) })
|
||||
operationId: `${context.marker}-${loadingPlanId}-warehouse-remark`.slice(0, 128) })
|
||||
const remarkResponse = await request(context, 'PATCH', warehouseRemarkPath, warehouseRemarkBody)
|
||||
const remarkedPlan = context.apiSuccess(MODULE, 'EDITING 装柜明细保存仓库备注', remarkResponse, '', OPTIONS)
|
||||
const remarkedItem = remarkedPlan?.items?.find?.((item) => id(item.id) === id(assignedItem.id))
|
||||
@@ -274,7 +274,7 @@ export async function run(context) {
|
||||
const staleRemarkResponse = await request(context, 'PATCH',
|
||||
`${smartLoadingBase}/plans/${loadingPlanId}/items/${id(assignedItem.id)}/warehouse-remark`, {
|
||||
warehouseRemark: `${warehouseRemark}-STALE`, expectedPlanVersion: Number(assignedLoadingPlan.version),
|
||||
expectedItemVersion: Number(assignedItem.version), operationId: `${context.marker}-warehouse-remark-stale`.slice(0, 128),
|
||||
expectedItemVersion: Number(assignedItem.version), operationId: `${context.marker}-${loadingPlanId}-warehouse-remark-stale`.slice(0, 128),
|
||||
})
|
||||
context.addStep(MODULE, '仓库备注旧版本 A0409 且零写入', staleRemarkResponse,
|
||||
staleRemarkResponse.http === 200 && codeOf(staleRemarkResponse) === 'A0409',
|
||||
@@ -290,7 +290,7 @@ export async function run(context) {
|
||||
const clearRemarkResponse = await request(context, 'PATCH',
|
||||
`${smartLoadingBase}/plans/${loadingPlanId}/items/${id(remarkedItem.id)}/warehouse-remark`, {
|
||||
warehouseRemark: ' ', expectedPlanVersion: Number(remarkedPlan.version),
|
||||
expectedItemVersion: Number(remarkedItem.version), operationId: `${context.marker}-warehouse-remark-clear`.slice(0, 128),
|
||||
expectedItemVersion: Number(remarkedItem.version), operationId: `${context.marker}-${loadingPlanId}-warehouse-remark-clear`.slice(0, 128),
|
||||
})
|
||||
const clearedPlan = context.apiSuccess(MODULE, 'EDITING 装柜明细空白仓库备注归一化为 null', clearRemarkResponse, '', OPTIONS)
|
||||
const clearedItem = clearedPlan?.items?.find?.((item) => id(item.id) === id(remarkedItem.id))
|
||||
@@ -302,7 +302,7 @@ export async function run(context) {
|
||||
const restoreRemarkResponse = await request(context, 'PATCH',
|
||||
`${smartLoadingBase}/plans/${loadingPlanId}/items/${id(clearedItem.id)}/warehouse-remark`, {
|
||||
warehouseRemark, expectedPlanVersion: Number(clearedPlan.version), expectedItemVersion: Number(clearedItem.version),
|
||||
operationId: `${context.marker}-warehouse-remark-restore`.slice(0, 128),
|
||||
operationId: `${context.marker}-${loadingPlanId}-warehouse-remark-restore`.slice(0, 128),
|
||||
})
|
||||
const persistedRemarkPlan = context.apiSuccess(MODULE, '恢复真实仓库备注供装柜完成事件下发', restoreRemarkResponse, '', OPTIONS)
|
||||
if (!Number.isInteger(Number(persistedRemarkPlan?.version))) return
|
||||
|
||||
@@ -79,6 +79,22 @@ export async function run(context) {
|
||||
&& gateItems.every((item) => !['TRUCK_DEPARTED', 'SAILING_SCHEDULE'].includes(item.code)),
|
||||
`truck=${aggregate?.truckAppointmentStatus || 'none'}, ocean=${aggregate?.oceanBookingStatus || 'none'}`, OPTIONS)
|
||||
|
||||
if (aggregate?.dispatchStatus === 'WAITING_FOR_LOADING') {
|
||||
context.assert(MODULE, '整柜报关完成后系统已自动确认国内离仓', detailResponse,
|
||||
aggregate?.inbounds?.every?.((item) => item?.inboundStatus === 'LOADED')
|
||||
&& detail?.timeline?.some?.((item) => item.module === 'OUTBOUND_DISPATCH'
|
||||
&& item.action === 'CONFIRM_DISPATCH'),
|
||||
`dispatch=${aggregate.dispatchStatus}, inbounds=${aggregate?.inbounds?.length ?? 'missing'}`, OPTIONS)
|
||||
context.createdResources.phase3OutboundDispatch = {
|
||||
marker: context.marker, inboundId, containerBookingId,
|
||||
orderId: id(inboundBinding?.orderId), tenantId: id(inboundBinding?.tenantId),
|
||||
confirmedStatus: aggregate.dispatchStatus, confirmedInboundStatus: 'LOADED',
|
||||
confirmedVersion: Number(aggregate.version), finalStatus: aggregate.dispatchStatus,
|
||||
finalInboundStatus: 'LOADED', finalVersion: Number(aggregate.version),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const expectedVersion = Number(aggregate.version)
|
||||
const confirmKey = `${context.marker}-outbound-confirm`.slice(0, 128)
|
||||
if (!gate?.passed) {
|
||||
|
||||
Reference in New Issue
Block a user