Files

49 lines
2.8 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const here = path.dirname(fileURLToPath(import.meta.url))
const acceptance = fs.readFileSync(path.join(here, '..', 'admin-test-env-acceptance.mjs'), 'utf8')
const finance = fs.readFileSync(path.join(here, 'finance.mjs'), 'utf8')
test('正式全量验收默认包含 Finance 模块', () => {
assert.match(acceptance, /CONFIGURED_MODULES\s*=\s*\[[\s\S]*['"]finance['"]/)
assert.match(acceptance, /DEFAULT_MODULES\s*=\s*normalizeModuleOrder\(CONFIGURED_MODULES\)/)
})
test('验收请求器支持并透传额外请求头', () => {
assert.match(acceptance, /async request\(method, path, body = undefined, token = this\.token, extraHeaders = \{\}\)/)
assert.match(acceptance, /Accept:\s*['"]application\/json['"][^\n]*\.\.\.extraHeaders/)
})
test('Finance 写操作统一使用 marker 派生的 Idempotency-Key', () => {
assert.match(finance, /function write\(context, method, path, body, action\)/)
assert.match(finance, /context\.request\(method, path, body, context\.token, \{\s*['"]Idempotency-Key['"]:\s*key\(context, action\)/)
assert.match(finance, /key\(context, action\).*context\.marker/)
})
test('Finance 不借用历史来源且缺 fixture 记录 coverage gap', () => {
assert.match(finance, /fixture\(context\)/)
assert.match(finance, /marker === context\.marker/)
assert.match(finance, /禁止借用历史费用来源执行不可逆财务写操作/)
assert.match(finance, /context\.addCoverageGap\(MODULE, ['"]finance-owned-fixture['"]/)
assert.match(finance, /context\.addCoverageGap\(MODULE, ['"]payable-payment['"]/)
assert.match(finance, /context\.addCoverageGap\(MODULE, ['"]receipt-three-settlements['"]/)
})
test('客户详情财务账单验收覆盖客户过滤、详情结构与查看权限链', () => {
assert.match(finance, /\/api\/platform\/v1\/iam\/authorization\/permissions/)
assert.match(finance, /\/statements\?customerId=\$\{encodeURIComponent\(customerId\)\}/)
assert.match(finance, /statementRows\.every\(\(item\) => id\(item\?\.customerId\) === customerId\)/)
assert.match(finance, /statementRows\.some\(\(item\) => statementId\(item\) === createdStatementId\)/)
assert.match(finance, /\/reconciliation-statements\/\$\{encodeURIComponent\(createdStatementId\)\}/)
assert.match(finance, /id\(statementDetail\?\.customerId\) === customerId/)
assert.match(finance, /statementId\(statementDetail\) === createdStatementId/)
assert.match(finance, /Array\.isArray\(statementDetail\?\.lines\)/)
assert.match(finance, /Array\.isArray\(statementDetail\?\.revisions\)/)
assert.match(finance, /grantedPermissions\.has\(['"]platform:finance:customer-statement:list['"]\)/)
assert.doesNotMatch(finance, /platform:finance:bill:view/)
})