|
|
|
@@ -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)
|
|
|
|
|