- 新增采集成功/失败记录、卡日流量、套餐日流量详单、冲正流水、退款后处理尝试记录 6 个查询页 - 资产详情新增采集记录、冲正记录与人工冲正,同步后展示本次流量入账结果 - 退款列表与详情展示资产后处理状态,支持按状态筛选、人工重试与查看尝试记录 - 新增前端权限码常量(需在 tb_permission 补数据)
This commit is contained in:
112
scripts/tests/trafficRecords.test.mjs
Normal file
112
scripts/tests/trafficRecords.test.mjs
Normal file
@@ -0,0 +1,112 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import ts from 'typescript'
|
||||
|
||||
function evaluate(path, imports = {}) {
|
||||
const compiled = ts.transpileModule(readFileSync(path, 'utf8'), {
|
||||
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS }
|
||||
}).outputText
|
||||
const module = { exports: {} }
|
||||
new Function('require', 'module', 'exports', compiled)(
|
||||
(name) => {
|
||||
assert.ok(imports[name], `Unexpected dependency: ${name}`)
|
||||
return imports[name]
|
||||
},
|
||||
module,
|
||||
module.exports
|
||||
)
|
||||
return module.exports
|
||||
}
|
||||
|
||||
const constants = evaluate('src/config/constants/trafficRecords.ts')
|
||||
const utils = evaluate('src/utils/business/trafficRecords.ts', {
|
||||
'@/config/constants/trafficRecords': constants
|
||||
})
|
||||
|
||||
test('时间范围:结束时间不含,跨度不超过 31 天', () => {
|
||||
assert.deepEqual(utils.toTimeQuery(['2026-11-01 00:00:00', '2026-11-02 00:00:00']), {
|
||||
start_time: '2026-11-01 00:00:00',
|
||||
end_time: '2026-11-02 00:00:00'
|
||||
})
|
||||
assert.doesNotThrow(() => utils.toTimeQuery(['2026-10-01 00:00:00', '2026-11-01 00:00:00']))
|
||||
assert.throws(
|
||||
() => utils.toTimeQuery(['2026-10-01 00:00:00', '2026-11-06 00:00:00']),
|
||||
/时间跨度不能超过 31 天/
|
||||
)
|
||||
assert.throws(
|
||||
() => utils.toTimeQuery(['2026-11-02 00:00:00', '2026-11-01 00:00:00']),
|
||||
/结束时间必须晚于开始时间/
|
||||
)
|
||||
assert.throws(() => utils.toTimeQuery(null), /请选择完整的时间范围/)
|
||||
assert.deepEqual(utils.toTimeQuery(null, false), {})
|
||||
})
|
||||
|
||||
test('日期范围:含首尾,最多 31 天', () => {
|
||||
assert.deepEqual(utils.toDateQuery(['2026-10-01', '2026-10-31']), {
|
||||
start_date: '2026-10-01',
|
||||
end_date: '2026-10-31'
|
||||
})
|
||||
assert.throws(() => utils.toDateQuery(['2026-10-01', '2026-11-01']), /日期跨度不能超过 31 天/)
|
||||
assert.throws(() => utils.toDateQuery(['2026-10-02', '2026-10-01']), /结束日期不得早于开始日期/)
|
||||
})
|
||||
|
||||
test('非平台账号必须填资产标识', () => {
|
||||
assert.doesNotThrow(() => utils.requireIdentifierForNonPlatform('', 1))
|
||||
assert.doesNotThrow(() => utils.requireIdentifierForNonPlatform('', 2))
|
||||
assert.throws(() => utils.requireIdentifierForNonPlatform(' ', 3), /请先输入资产标识/)
|
||||
assert.doesNotThrow(() => utils.requireIdentifierForNonPlatform('898600', 3))
|
||||
assert.equal(utils.isEnterpriseAccount(4), true)
|
||||
assert.equal(utils.isPlatformAccount(3), false)
|
||||
})
|
||||
|
||||
test('筛选值处理', () => {
|
||||
assert.deepEqual(utils.compactQuery({ a: '', b: 0, c: null, d: undefined, e: false, f: 'x' }), {
|
||||
b: 0,
|
||||
e: false,
|
||||
f: 'x'
|
||||
})
|
||||
assert.equal(utils.optionalPositiveInt('', 'ID'), undefined)
|
||||
assert.equal(utils.optionalPositiveInt('12', 'ID'), 12)
|
||||
assert.throws(() => utils.optionalPositiveInt('-1', '运营商账户 ID'), /运营商账户 ID须为正整数/)
|
||||
assert.equal(utils.optionalBoolean('true'), true)
|
||||
assert.equal(utils.optionalBoolean('false'), false)
|
||||
assert.equal(utils.optionalBoolean(''), undefined)
|
||||
assert.equal(utils.formatMb(12), '12 MB')
|
||||
assert.equal(utils.formatMb(1.256), '1.26 MB')
|
||||
assert.equal(utils.formatMb(null), '-')
|
||||
})
|
||||
|
||||
test('资产同步后的流量入账结果文案', () => {
|
||||
assert.equal(utils.describeTrafficRefresh(undefined), '')
|
||||
assert.equal(
|
||||
utils.describeTrafficRefresh({
|
||||
result: 'ok',
|
||||
reading_mb: 1200,
|
||||
written: true,
|
||||
decision: 'written',
|
||||
delta_mb: 15
|
||||
}),
|
||||
'本次读数 1200 MB,已写入,增量 15 MB'
|
||||
)
|
||||
assert.equal(
|
||||
utils.describeTrafficRefresh({
|
||||
result: 'ok',
|
||||
reading_mb: 1200,
|
||||
written: false,
|
||||
decision: 'queue_not_full'
|
||||
}),
|
||||
'本次读数 1200 MB,未写入:采集队列未满'
|
||||
)
|
||||
assert.equal(utils.describeTrafficRefresh({ result: 'rate_limited' }), '流量读数限流,未写入')
|
||||
})
|
||||
|
||||
test('退款后处理状态与权限码常量', () => {
|
||||
assert.equal(constants.REFUND_ASSET_POST_STATUS.manualRequired, 3)
|
||||
assert.equal(constants.REFUND_ASSET_POST_STATUS_LABELS[3], '需人工处理')
|
||||
assert.equal(constants.REFUND_ASSET_POST_MAX_ATTEMPTS, 10)
|
||||
assert.equal(constants.TRAFFIC_RECORD_PERMISSIONS.refundAssetPostRetry, 'refund:asset_post_retry')
|
||||
assert.equal(constants.labelOf(constants.TRAFFIC_DECISION_LABELS, 'out_of_order'), '采集乱序')
|
||||
assert.equal(constants.labelOf(constants.TRAFFIC_DECISION_LABELS, 'new_value'), 'new_value')
|
||||
assert.equal(constants.labelOf(constants.TRAFFIC_DECISION_LABELS, ''), '-')
|
||||
})
|
||||
Reference in New Issue
Block a user