Files
one-pipe-system/scripts/tests/refundMethodOptions.test.mjs
luo ecce4f6e7b
All checks were successful
构建并部署前端到测试环境 / deploy (push) Successful in 55s
fix: some
2026-10-24 14:56:32 +08:00

66 lines
2.5 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import ts from 'typescript'
function evaluate(source, imports = {}) {
const compiled = ts.transpileModule(source, {
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 types = evaluate(readFileSync('src/types/api/refund.ts', 'utf8'))
const { RefundMethod } = types
const { RefundMethodOptions, RefundMethodNameMap } = evaluate(
readFileSync('src/config/constants/refund.ts', 'utf8'),
{ '@/types/api/refund': types }
)
const dialogSource = readFileSync('src/components/business/CreateRefundDialog.vue', 'utf8')
test('refund forms hide original route while preserving historical labels', () => {
assert.deepEqual(
RefundMethodOptions.map((option) => option.value),
[RefundMethod.CUSTOMER_ACCOUNT, RefundMethod.ASSET_WALLET, RefundMethod.AGENT_WALLET]
)
assert.equal(RefundMethodNameMap[RefundMethod.ORIGINAL_ROUTE], '原路退回')
for (const path of [
'src/components/business/CreateRefundDialog.vue',
'src/views/finance/refund/index.vue',
'src/views/finance/refund/detail.vue'
]) {
assert.match(readFileSync(path, 'utf8'), /v-for="opt in RefundMethodOptions"/)
}
})
test('creation defaults and reset never select the hidden original route', () => {
assert.match(dialogSource, /method: RefundMethod\.CUSTOMER_ACCOUNT/)
assert.match(dialogSource, /formData\.method = RefundMethod\.CUSTOMER_ACCOUNT/)
assert.doesNotMatch(dialogSource, /RefundMethod\.ORIGINAL_ROUTE/)
const resolver = dialogSource.match(/const resolveRefundMethod = [\s\S]*?\n }/)[0]
const { resolveRefundMethod } = evaluate(
`const RefundMethod = ${JSON.stringify(RefundMethod)}; export ${resolver}`
)
for (const payment_method of ['wechat', 'alipay', 'fuiou', 'offline']) {
assert.equal(resolveRefundMethod({ payment_method }), RefundMethod.CUSTOMER_ACCOUNT)
}
assert.match(dialogSource, /fuiou: '富友支付'/)
assert.equal(
resolveRefundMethod({ payment_method: 'wallet', buyer_type: 'agent' }),
RefundMethod.AGENT_WALLET
)
assert.equal(
resolveRefundMethod({ payment_method: 'wallet', buyer_type: 'customer' }),
RefundMethod.ASSET_WALLET
)
})