fix: complete October 22 workflow feedback and request failure recovery
This commit is contained in:
@@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs'
|
||||
import test from 'node:test'
|
||||
|
||||
import { normalizeModuleOrder, parseArguments } from '../admin-test-env-acceptance.mjs'
|
||||
import { cleanupSucceeded, isAcceptanceFeeItem, formalFeeItems } from './fee-items.mjs'
|
||||
import { cleanupSucceeded, formalFeeItems, run } from './fee-items.mjs'
|
||||
|
||||
const source = readFileSync(new URL('./fee-items.mjs', import.meta.url), 'utf8')
|
||||
|
||||
@@ -23,15 +23,44 @@ test('cleanup treats successful deletion and an already absent resource as clean
|
||||
assert.equal(cleanupSucceeded({ http: 200, body: { code: 'A0422' } }), false)
|
||||
})
|
||||
|
||||
test('stale cleanup only recognizes the acceptance-owned code and name pair', () => {
|
||||
assert.equal(isAcceptanceFeeItem({ feeCode: 'ACPT_813083345572', feeTypeName: '全量验收费用-813083345572-已编辑' }), true)
|
||||
assert.equal(isAcceptanceFeeItem({ feeCode: 'FEE_TYPE_001', feeTypeName: '全量验收费用-001' }), false)
|
||||
assert.equal(isAcceptanceFeeItem({ feeCode: 'ACPT_813083345572', feeTypeName: '正式费用项目' }), false)
|
||||
test('no automatic historical fee-item cleanup remains', () => {
|
||||
assert.doesNotMatch(source, /cleanupStaleAcceptanceItems|isAcceptanceFeeItem/)
|
||||
})
|
||||
|
||||
test('baseline checks run only after stale acceptance cleanup', () => {
|
||||
assert.ok(source.indexOf('cleanupStaleAcceptanceItems(context)')
|
||||
< source.indexOf("'全部目录默认20条分页与完整列表一致'"))
|
||||
for (const missingBaseline of [false, true]) test(`fixed fee catalogue preserves old test items and performs no master writes; missing=${missingBaseline}`, async () => {
|
||||
const codes = ['FBA_HEAD_FREIGHT', 'PRIVATE_LAST_MILE_DELIVERY', ...Array.from({ length: 110 }, (_, i) => `FEE_TYPE_${String(i + 1).padStart(3, '0')}`)]
|
||||
const catalogue = codes.map((feeCode, i) => ({ id: String(i + 1), feeCode, tenantId: '0', status: 'ACTIVE',
|
||||
tradeScope: i < 84 ? 'DOMESTIC' : 'INTERNATIONAL', category: '标准', feeTypeName: `费用${i}` }))
|
||||
catalogue.push({ id: '999', feeCode: 'ACPT_123456', feeTypeName: '全量验收费用-123456', tenantId: '0', status: 'DISABLED', category: '临时', tradeScope: 'DOMESTIC' })
|
||||
if (missingBaseline) catalogue.splice(3, 1)
|
||||
const calls = [], gaps = []
|
||||
const context = { options: { fixedCustomerId: '101' }, marker: 'TEST', createdResources: {},
|
||||
async request(method, path, body, token) {
|
||||
calls.push({ method, path })
|
||||
const response = data => ({ http: 200, path, body: { code: '200', data } })
|
||||
if (path === '/api/auth/login') return response({ accessToken: 'client', refreshToken: 'refresh' })
|
||||
if (path === '/api/auth/logout') return response({})
|
||||
assert.equal(method, 'GET')
|
||||
if (token === 'client') return { http: 403, body: { code: 'A0403' } }
|
||||
const params = new URL(path, 'https://test.invalid').searchParams
|
||||
const selected = catalogue.filter(row => ['category', 'tradeScope', 'status'].every(key => !params.has(key) || row[key] === params.get(key))
|
||||
&& (!params.has('keyword') || row.feeTypeName.includes(params.get('keyword'))))
|
||||
const size = Number(params.get('size')), page = Number(params.get('page'))
|
||||
return response({ records: selected.slice((page - 1) * size, page * size), total: selected.length, page, size, pages: Math.ceil(selected.length / size) })
|
||||
}, apiSuccess(_m, _n, response) { return response.body.data },
|
||||
assert(_m, name, _r, passed) { assert.ok(passed, name) },
|
||||
addCoverageGap(...args) { gaps.push(args) },
|
||||
}
|
||||
const before = structuredClone(catalogue)
|
||||
if (missingBaseline) await assert.rejects(run(context), /112条/)
|
||||
else {
|
||||
await run(context)
|
||||
assert.equal(context.createdResources.feeItems.mode, 'READ_ONLY')
|
||||
assert.equal(gaps.length, 1)
|
||||
assert.equal(calls.filter(row => row.path === '/api/auth/logout').length, 1)
|
||||
}
|
||||
assert.deepEqual(catalogue, before)
|
||||
assert.ok(calls.every(row => row.method === 'GET' || row.path.startsWith('/api/auth/')))
|
||||
})
|
||||
|
||||
test('正式费用按编码识别,扩展停用项目保留且不掩盖缺失正式编码', () => {
|
||||
|
||||
Reference in New Issue
Block a user