From c706f543a413f75db3fb43b71ef5b935ee870f23 Mon Sep 17 00:00:00 2001 From: luo Date: Fri, 23 Oct 2026 16:38:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9A=90=E8=97=8F=E5=8E=9F=E8=B7=AF?= =?UTF-8?q?=E9=80=80=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/refundMethodOptions.test.mjs | 64 +++++++++++++++++++ .../business/CreateRefundDialog.vue | 7 +- src/config/constants/refund.ts | 3 +- 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 scripts/tests/refundMethodOptions.test.mjs diff --git a/scripts/tests/refundMethodOptions.test.mjs b/scripts/tests/refundMethodOptions.test.mjs new file mode 100644 index 0000000..4a4dbff --- /dev/null +++ b/scripts/tests/refundMethodOptions.test.mjs @@ -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 + ) +}) diff --git a/src/components/business/CreateRefundDialog.vue b/src/components/business/CreateRefundDialog.vue index c704047..dca7e57 100644 --- a/src/components/business/CreateRefundDialog.vue +++ b/src/components/business/CreateRefundDialog.vue @@ -165,7 +165,7 @@ }>({ order_id: null, package_usage_id: undefined, - method: RefundMethod.ORIGINAL_ROUTE, + method: RefundMethod.CUSTOMER_ACCOUNT, requested_refund_amount: undefined, actual_received_amount: 0, refund_reason: '', @@ -258,8 +258,7 @@ if (order.payment_method === 'wallet') { return order.buyer_type === 'agent' ? RefundMethod.AGENT_WALLET : RefundMethod.ASSET_WALLET } - if (order.payment_method === 'offline') return RefundMethod.CUSTOMER_ACCOUNT - return RefundMethod.ORIGINAL_ROUTE + return RefundMethod.CUSTOMER_ACCOUNT } const searchOrders = async (query: string) => { @@ -320,7 +319,7 @@ voucherUploading.value = false formData.order_id = null formData.package_usage_id = undefined - formData.method = RefundMethod.ORIGINAL_ROUTE + formData.method = RefundMethod.CUSTOMER_ACCOUNT formData.requested_refund_amount = undefined formData.actual_received_amount = 0 formData.refund_reason = '' diff --git a/src/config/constants/refund.ts b/src/config/constants/refund.ts index 57cac0c..95a0aa8 100644 --- a/src/config/constants/refund.ts +++ b/src/config/constants/refund.ts @@ -59,9 +59,8 @@ export const RefundFailureReasonNameMap: Record = { [RefundFailureReason.PAYMENT_FACT_INVALID]: '本地原支付事实不可用' } -/** 退款方式选项(表单用) */ +/** 退款方式选项(表单用,原路退回暂不开放;历史记录仍保留名称映射) */ export const RefundMethodOptions = [ - { label: '原路退回', value: RefundMethod.ORIGINAL_ROUTE }, { label: '线下退款', value: RefundMethod.CUSTOMER_ACCOUNT }, { label: '资产钱包', value: RefundMethod.ASSET_WALLET }, { label: '代理钱包', value: RefundMethod.AGENT_WALLET }