fix(order): show authoritative progress and billing in customer detail
This commit is contained in:
@@ -8,6 +8,32 @@ const storeSource = readFileSync(new URL('./firstLegOrders.ts', import.meta.url)
|
||||
const apiSource = readFileSync(new URL('../api/firstLeg.ts', import.meta.url), 'utf8')
|
||||
const unifiedApiSource = readFileSync(new URL('../api/unifiedOrders.ts', import.meta.url), 'utf8')
|
||||
|
||||
test('detail fetches authoritative progress on direct entry and refresh, and clears stale progress on failure', async () => {
|
||||
const functionSource = storeSource.slice(storeSource.indexOf(' async function loadDetail('), storeSource.indexOf(' async function loadWarehouseDetail('))
|
||||
const progressSource = readFileSync(new URL('../utils/orderProgress.ts', import.meta.url), 'utf8')
|
||||
const validationSource = progressSource.slice(progressSource.indexOf('export function requireOrderProgress(')).replace('export ', '')
|
||||
const javascript = ts.transpileModule(`${validationSource}\n${functionSource}`, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText
|
||||
const id = '2110663764278312961'
|
||||
const orderProgress = { value: {} }
|
||||
let calls = 0
|
||||
let response = { progress: { orderId: id, stage: 'scheduled', partial: true } }
|
||||
const loadDetail = runInNewContext(`${javascript}; loadDetail`, {
|
||||
orderProgress, warehouses: { value: [] },
|
||||
getMerchantUnifiedOrder: async requested => { assert.equal(requested, id); calls++; return response },
|
||||
mapUnifiedOrderDetail: detail => ({ id, detail }), upsertOrder: order => order,
|
||||
})
|
||||
await loadDetail(id)
|
||||
assert.equal(orderProgress.value[id].stage, 'scheduled')
|
||||
assert.equal(orderProgress.value[id].partial, true)
|
||||
response = { progress: { orderId: id, stage: 'delivering', partial: false } }
|
||||
await loadDetail(id)
|
||||
assert.equal(calls, 2)
|
||||
assert.equal(orderProgress.value[id].stage, 'delivering')
|
||||
response = { progress: { orderId: 'another-order', stage: 'delivered', partial: false } }
|
||||
await assert.rejects(loadDetail(id), /订单履约进度不完整/)
|
||||
assert.equal(orderProgress.value[id], undefined)
|
||||
})
|
||||
|
||||
test('renders estimated sailing from the current API without substituting actual departure', () => {
|
||||
const mapper = storeSource.slice(storeSource.indexOf('function businessSummary('), storeSource.indexOf('\nconst unifiedActionLabels'))
|
||||
const javascript = ts.transpileModule(mapper, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText
|
||||
|
||||
Reference in New Issue
Block a user