Files
baiyue-firstleg/scripts/admin-test-env-modules/download-center-contract.test.mjs
2026-10-08 17:07:57 +08:00

37 lines
1.9 KiB
JavaScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { verifyDownloadCenterExport } from './download-center.mjs'
import { exportWorkbook } from './download-center-fixture.mjs'
function fixture(status = 'SUCCEEDED', values = ['LM-1']) {
const calls = []
return {
marker: 'export-test', calls,
async request(method, path, body) {
calls.push({ method, path, body })
return { http: 200, body: { code: '200', data: { id: 'EXP-1', status: method === 'POST' ? 'PENDING' : status } } }
},
apiSuccess(_module, _name, response) { return response.body.data },
assert(_module, name, _response, passed) { assert.ok(passed, name) },
async requestBinary(method, path) {
calls.push({ method, path })
return { http: 200, contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', bytes: exportWorkbook(['尾程单号'], values) }
},
}
}
test('creates, polls and validates the actual XLSX through File', async () => {
const context = fixture()
await verifyDownloadCenterExport(context, 'orders', 'LAST_MILE_ORDER_LIST', { orderNo: 'LM-1' }, ['尾程单号'], ['LM-1'])
assert.deepEqual(context.calls[0].body.parameters, { orderNo: 'LM-1' })
assert.equal(context.calls[0].body.format, 'XLSX')
assert.ok(context.calls.at(-1).path.endsWith('/EXP-1/download'))
})
test('failed generation cannot be reported as a successful download', async () => {
const context = fixture('FAILED')
await assert.rejects(verifyDownloadCenterExport(context, 'orders', 'LAST_MILE_ORDER_LIST', {}, ['尾程单号']))
assert.equal(context.calls.some(call => call.path.endsWith('/download')), false)
})
test('a file missing this run business data fails acceptance', async () => {
await assert.rejects(verifyDownloadCenterExport(fixture('SUCCEEDED', ['OTHER']), 'orders', 'LAST_MILE_ORDER_LIST', {}, ['尾程单号'], ['LM-1']))
})