test(acceptance): follow automatic departure flow

This commit is contained in:
2026-09-02 14:16:44 +08:00
parent 5d098c9762
commit b6800a48c6
3 changed files with 41 additions and 5 deletions
@@ -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}`)
}