Files
baiyue-firstleg/scripts/admin-test-env-modules/finance-contract.test.mjs
T
2026-08-12 09:25:53 +08:00

34 lines
1.7 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, /DEFAULT_MODULES\s*=\s*\[[\s\S]*['"]finance['"]/)
})
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['"]/)
})