This commit is contained in:
64
scripts/tests/refundMethodOptions.test.mjs
Normal file
64
scripts/tests/refundMethodOptions.test.mjs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
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', 'offline']) {
|
||||||
|
assert.equal(resolveRefundMethod({ payment_method }), RefundMethod.CUSTOMER_ACCOUNT)
|
||||||
|
}
|
||||||
|
assert.equal(
|
||||||
|
resolveRefundMethod({ payment_method: 'wallet', buyer_type: 'agent' }),
|
||||||
|
RefundMethod.AGENT_WALLET
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
resolveRefundMethod({ payment_method: 'wallet', buyer_type: 'customer' }),
|
||||||
|
RefundMethod.ASSET_WALLET
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -165,7 +165,7 @@
|
|||||||
}>({
|
}>({
|
||||||
order_id: null,
|
order_id: null,
|
||||||
package_usage_id: undefined,
|
package_usage_id: undefined,
|
||||||
method: RefundMethod.ORIGINAL_ROUTE,
|
method: RefundMethod.CUSTOMER_ACCOUNT,
|
||||||
requested_refund_amount: undefined,
|
requested_refund_amount: undefined,
|
||||||
actual_received_amount: 0,
|
actual_received_amount: 0,
|
||||||
refund_reason: '',
|
refund_reason: '',
|
||||||
@@ -258,8 +258,7 @@
|
|||||||
if (order.payment_method === 'wallet') {
|
if (order.payment_method === 'wallet') {
|
||||||
return order.buyer_type === 'agent' ? RefundMethod.AGENT_WALLET : RefundMethod.ASSET_WALLET
|
return order.buyer_type === 'agent' ? RefundMethod.AGENT_WALLET : RefundMethod.ASSET_WALLET
|
||||||
}
|
}
|
||||||
if (order.payment_method === 'offline') return RefundMethod.CUSTOMER_ACCOUNT
|
return RefundMethod.CUSTOMER_ACCOUNT
|
||||||
return RefundMethod.ORIGINAL_ROUTE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchOrders = async (query: string) => {
|
const searchOrders = async (query: string) => {
|
||||||
@@ -320,7 +319,7 @@
|
|||||||
voucherUploading.value = false
|
voucherUploading.value = false
|
||||||
formData.order_id = null
|
formData.order_id = null
|
||||||
formData.package_usage_id = undefined
|
formData.package_usage_id = undefined
|
||||||
formData.method = RefundMethod.ORIGINAL_ROUTE
|
formData.method = RefundMethod.CUSTOMER_ACCOUNT
|
||||||
formData.requested_refund_amount = undefined
|
formData.requested_refund_amount = undefined
|
||||||
formData.actual_received_amount = 0
|
formData.actual_received_amount = 0
|
||||||
formData.refund_reason = ''
|
formData.refund_reason = ''
|
||||||
|
|||||||
@@ -59,9 +59,8 @@ export const RefundFailureReasonNameMap: Record<RefundFailureReason, string> = {
|
|||||||
[RefundFailureReason.PAYMENT_FACT_INVALID]: '本地原支付事实不可用'
|
[RefundFailureReason.PAYMENT_FACT_INVALID]: '本地原支付事实不可用'
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 退款方式选项(表单用) */
|
/** 退款方式选项(表单用,原路退回暂不开放;历史记录仍保留名称映射) */
|
||||||
export const RefundMethodOptions = [
|
export const RefundMethodOptions = [
|
||||||
{ label: '原路退回', value: RefundMethod.ORIGINAL_ROUTE },
|
|
||||||
{ label: '线下退款', value: RefundMethod.CUSTOMER_ACCOUNT },
|
{ label: '线下退款', value: RefundMethod.CUSTOMER_ACCOUNT },
|
||||||
{ label: '资产钱包', value: RefundMethod.ASSET_WALLET },
|
{ label: '资产钱包', value: RefundMethod.ASSET_WALLET },
|
||||||
{ label: '代理钱包', value: RefundMethod.AGENT_WALLET }
|
{ label: '代理钱包', value: RefundMethod.AGENT_WALLET }
|
||||||
|
|||||||
Reference in New Issue
Block a user