00ff425e03
新增 SpacetimeDB 原生充值订单过期 timer 与 expired 状态。 移除 api-server 轮询 worker,改为 HTTP 角色订阅 Pending 到 Expired 事件并查单补偿。 统一微信下单 5 分钟 time_expire,并恢复前端支付通道选择与 expired 展示。 补齐生成绑定、前后端契约、测试和项目文档。
158 lines
4.7 KiB
TypeScript
158 lines
4.7 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import {
|
|
resolveProfileRechargePaymentChannel,
|
|
resolveProfileRechargeProductPaymentChannel,
|
|
shouldShowRechargeEntry,
|
|
WECHAT_H5_PAYMENT_CHANNEL,
|
|
WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL,
|
|
WECHAT_NATIVE_PAYMENT_CHANNEL,
|
|
} from './paymentPlatform';
|
|
|
|
describe('resolveProfileRechargePaymentChannel', () => {
|
|
test('小程序运行态基础通道选择 wechat_mp_virtual', () => {
|
|
expect(
|
|
resolveProfileRechargePaymentChannel({
|
|
location: { search: '?clientRuntime=wechat_mini_program' },
|
|
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
|
|
}),
|
|
).toBe(WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL);
|
|
});
|
|
|
|
test('点数商品在小程序运行态选择 wechat_mp_virtual', () => {
|
|
expect(
|
|
resolveProfileRechargeProductPaymentChannel(
|
|
{ kind: 'points' },
|
|
{
|
|
location: { search: '?clientRuntime=wechat_mini_program' },
|
|
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
|
|
},
|
|
),
|
|
).toBe(WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL);
|
|
});
|
|
|
|
test('会员商品在小程序运行态也选择 wechat_mp_virtual', () => {
|
|
expect(
|
|
resolveProfileRechargeProductPaymentChannel(
|
|
{ kind: 'membership' },
|
|
{
|
|
location: { search: '?clientRuntime=wechat_mini_program' },
|
|
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
|
|
},
|
|
),
|
|
).toBe(WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL);
|
|
});
|
|
|
|
test('小程序桥未就绪但 UA 已带 miniProgram 时选择 wechat_mp_virtual', () => {
|
|
expect(
|
|
resolveProfileRechargePaymentChannel({
|
|
location: { search: '' },
|
|
navigator: {
|
|
userAgent: 'Mozilla/5.0 iPhone MicroMessenger/8.0.49 miniProgram',
|
|
},
|
|
}),
|
|
).toBe(WECHAT_MINI_PROGRAM_VIRTUAL_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('桌面微信内网页也选择 wechat_native', () => {
|
|
expect(
|
|
resolveProfileRechargePaymentChannel({
|
|
location: { search: '' },
|
|
navigator: {
|
|
userAgent:
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit MicroMessenger/8.0',
|
|
},
|
|
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');
|
|
});
|
|
});
|
|
|
|
describe('shouldShowRechargeEntry', () => {
|
|
test('小程序运行态显示充值入口', () => {
|
|
expect(
|
|
shouldShowRechargeEntry({
|
|
location: { search: '?clientRuntime=wechat_mini_program' },
|
|
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
test('微信内网页显示充值入口', () => {
|
|
expect(
|
|
shouldShowRechargeEntry({
|
|
location: { search: '' },
|
|
navigator: {
|
|
userAgent:
|
|
'Mozilla/5.0 (Linux; Android 14) AppleWebKit MicroMessenger/8.0 Mobile',
|
|
},
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
test('普通移动浏览器也显示充值入口', () => {
|
|
expect(
|
|
shouldShowRechargeEntry({
|
|
location: { search: '' },
|
|
navigator: {
|
|
userAgent:
|
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) Mobile',
|
|
},
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
test('普通桌面浏览器也显示充值入口', () => {
|
|
expect(
|
|
shouldShowRechargeEntry({
|
|
location: { search: '' },
|
|
navigator: { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' },
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
});
|