优化
This commit is contained in:
@@ -4,7 +4,30 @@ import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { buildContainerCostBody, buildSupplierBody, normalizeFinanceFixtureSources, run,
|
||||
supplierCategoryForFeeItem } from './finance-full-fixtures.mjs'
|
||||
supplierCategoryForFeeItem, loadSupplier } from './finance-full-fixtures.mjs'
|
||||
|
||||
test('fixed customer supplier selection paginates and never creates a fallback', async () => {
|
||||
const calls = [], failures = []
|
||||
const supplier = { id: '123', status: 'ACTIVE', category: 'TRUCKING', name: 'Existing' }
|
||||
const context = {
|
||||
options: { fixedCustomerId: '456' }, marker: 'REUSE',
|
||||
async request(method, path) {
|
||||
calls.push({ method, path })
|
||||
const data = path.includes('/123?') ? supplier : path.includes('page=2')
|
||||
? { records: [supplier], total: 101 }
|
||||
: { records: Array.from({ length: 100 }, () => ({ id: '99', status: 'ACTIVE', category: 'BOOKING' })), total: 101 }
|
||||
return { body: { data } }
|
||||
},
|
||||
apiSuccess(_module, _name, response) { return response.body.data },
|
||||
addStep(...args) { failures.push(args) },
|
||||
}
|
||||
assert.equal((await loadSupplier(context, 'TRUCKING')).id, '123')
|
||||
assert.equal(calls.length, 3)
|
||||
assert.ok(calls.every(call => call.method === 'GET'))
|
||||
context.request = async method => { assert.equal(method, 'GET'); return { body: { data: { records: [], total: 0 } } } }
|
||||
assert.equal(await loadSupplier(context, 'TRUCKING'), null)
|
||||
assert.equal(failures.length, 1)
|
||||
})
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url))
|
||||
const source = fs.readFileSync(path.join(here, 'finance-full-fixtures.mjs'), 'utf8')
|
||||
|
||||
Reference in New Issue
Block a user