feat: 接入微信H5与Native充值支付
This commit is contained in:
63
src/services/payment/paymentPlatform.test.ts
Normal file
63
src/services/payment/paymentPlatform.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import {
|
||||
resolveProfileRechargePaymentChannel,
|
||||
WECHAT_H5_PAYMENT_CHANNEL,
|
||||
WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL,
|
||||
WECHAT_NATIVE_PAYMENT_CHANNEL,
|
||||
} from './paymentPlatform';
|
||||
|
||||
describe('resolveProfileRechargePaymentChannel', () => {
|
||||
test('小程序运行态选择 wechat_mp', () => {
|
||||
expect(
|
||||
resolveProfileRechargePaymentChannel({
|
||||
location: { search: '?clientRuntime=wechat_mini_program' },
|
||||
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
|
||||
}),
|
||||
).toBe(WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL);
|
||||
});
|
||||
|
||||
test('移动网页选择 wechat_h5', () => {
|
||||
expect(
|
||||
resolveProfileRechargePaymentChannel({
|
||||
location: { search: '' },
|
||||
navigator: {
|
||||
userAgent:
|
||||
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) Mobile',
|
||||
},
|
||||
}),
|
||||
).toBe(WECHAT_H5_PAYMENT_CHANNEL);
|
||||
});
|
||||
|
||||
test('微信内 H5 首版仍选择 wechat_h5', () => {
|
||||
expect(
|
||||
resolveProfileRechargePaymentChannel({
|
||||
location: { search: '' },
|
||||
navigator: {
|
||||
userAgent:
|
||||
'Mozilla/5.0 (Linux; Android 14) AppleWebKit MicroMessenger/8.0 Mobile',
|
||||
},
|
||||
}),
|
||||
).toBe(WECHAT_H5_PAYMENT_CHANNEL);
|
||||
});
|
||||
|
||||
test('桌面网页选择 wechat_native', () => {
|
||||
expect(
|
||||
resolveProfileRechargePaymentChannel({
|
||||
location: { search: '' },
|
||||
navigator: { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' },
|
||||
matchMedia: () => ({ matches: false }) as unknown as MediaQueryList,
|
||||
}),
|
||||
).toBe(WECHAT_NATIVE_PAYMENT_CHANNEL);
|
||||
});
|
||||
|
||||
test('默认路径永远不会解析成 mock', () => {
|
||||
expect(
|
||||
resolveProfileRechargePaymentChannel({
|
||||
location: { search: '' },
|
||||
navigator: { userAgent: '' },
|
||||
matchMedia: () => ({ matches: false }) as unknown as MediaQueryList,
|
||||
}),
|
||||
).not.toBe('mock');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user