fix: harden easypay custom method validation

This commit is contained in:
Albert Coady
2026-07-06 15:00:29 +08:00
parent bf76168ba5
commit 0dc6e56aae
4 changed files with 108 additions and 4 deletions
+1
View File
@@ -1119,6 +1119,7 @@ onMounted(async () => {
paymentState.value = restored
paymentPhase.value = 'paying'
const restoredMethod = normalizeVisibleMethod(restored.paymentType)
|| (visibleMethods.value[restored.paymentType] ? restored.paymentType : '')
if (restoredMethod) {
selectedMethod.value = restoredMethod
}
@@ -326,6 +326,88 @@ describe('PaymentView subscription confirmation amounts', () => {
})
})
describe('PaymentView payment recovery', () => {
beforeEach(() => {
vi.useRealTimers()
routeState.path = '/purchase'
routeState.query = {}
routerReplace.mockReset().mockResolvedValue(undefined)
routerPush.mockReset().mockResolvedValue(undefined)
routerResolve.mockClear()
createOrder.mockReset()
refreshUser.mockReset()
fetchActiveSubscriptions.mockReset().mockResolvedValue(undefined)
showError.mockReset()
showInfo.mockReset()
showWarning.mockReset()
bridgeInvoke.mockReset()
window.localStorage.clear()
;(window as Window & { WeixinJSBridge?: { invoke: typeof bridgeInvoke } }).WeixinJSBridge = undefined
})
it('restores a custom EasyPay method as the selected payment method', async () => {
getCheckoutInfo.mockResolvedValue(checkoutInfoFixture({
methods: {
wxpay: checkoutInfoFixture().data.methods.wxpay,
ldc: {
daily_limit: 0,
daily_used: 0,
daily_remaining: 0,
single_min: 0,
single_max: 0,
fee_rate: 0,
available: true,
display_name: 'LDC Pay',
},
},
}))
window.localStorage.setItem(PAYMENT_RECOVERY_STORAGE_KEY, JSON.stringify({
orderId: 888,
amount: 66,
qrCode: 'ldc-qr',
expiresAt: '2099-01-01T00:10:00.000Z',
paymentType: 'ldc',
payUrl: 'https://pay.example.com/ldc',
outTradeNo: 'sub2_ldc_888',
clientSecret: '',
intentId: '',
currency: '',
countryCode: '',
paymentEnv: '',
payAmount: 66,
orderType: 'balance',
paymentMode: 'popup',
resumeToken: '',
createdAt: Date.now(),
}))
const wrapper = shallowMount(PaymentView, {
global: {
stubs: {
AppLayout: {
template: '<div><slot /></div>',
},
PaymentStatusPanel: {
template: '<button data-test="payment-done" @click="$emit(\'done\')" />',
},
PaymentMethodSelector: {
props: ['selected'],
template: '<div data-test="method-selector">{{ selected }}</div>',
},
Teleport: true,
Transition: false,
},
},
})
await flushPromises()
await flushPromises()
await wrapper.find('[data-test="payment-done"]').trigger('click')
await flushPromises()
expect(wrapper.find('[data-test="method-selector"]').text()).toBe('ldc')
})
})
describe('PaymentView WeChat JSAPI flow', () => {
beforeEach(() => {
routeState.path = '/purchase'