mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
fix: harden easypay custom method validation
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user