542fb09365
调整网页端充值渠道,微信内浏览器在开放平台接入前走 Native 支付。 拆分 Native 支付二维码弹窗,展示金额和充值内容并取消无效 code_url 跳转。 修复微信 Native 下单 time_expire 秒级 RFC3339 格式,避免小数秒参数错误。 新增充值订单 5 分钟过期调度,过期前查询微信真实订单状态。 补充微信授权绑定、路由加载恢复和后台表时间显示等配套逻辑。 更新 SpacetimeDB schema、绑定和相关文档测试。
86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
/* @vitest-environment jsdom */
|
|
|
|
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
|
|
import { requestWechatJsapiPayment } from './wechatJsapiPayment';
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe('requestWechatJsapiPayment', () => {
|
|
test('resolves when WeixinJSBridge reports payment success', async () => {
|
|
const invoke = vi.fn(
|
|
(
|
|
_method: string,
|
|
_params: Record<string, string>,
|
|
callback: (result: { err_msg: string }) => void,
|
|
) => {
|
|
callback({ err_msg: 'get_brand_wcpay_request:ok' });
|
|
},
|
|
);
|
|
vi.stubGlobal('WeixinJSBridge', { invoke });
|
|
|
|
await expect(
|
|
requestWechatJsapiPayment({
|
|
appId: 'wx-app',
|
|
timeStamp: '1770000000',
|
|
nonceStr: 'nonce',
|
|
package: 'prepay_id=wx',
|
|
signType: 'RSA',
|
|
paySign: 'pay-sign',
|
|
}),
|
|
).resolves.toBeUndefined();
|
|
|
|
expect(invoke).toHaveBeenCalledWith(
|
|
'getBrandWCPayRequest',
|
|
{
|
|
appId: 'wx-app',
|
|
timeStamp: '1770000000',
|
|
nonceStr: 'nonce',
|
|
package: 'prepay_id=wx',
|
|
signType: 'RSA',
|
|
paySign: 'pay-sign',
|
|
},
|
|
expect.any(Function),
|
|
);
|
|
});
|
|
|
|
test('rejects when user cancels the WeChat payment sheet', async () => {
|
|
vi.stubGlobal('WeixinJSBridge', {
|
|
invoke: vi.fn(
|
|
(
|
|
_method: string,
|
|
_params: Record<string, string>,
|
|
callback: (result: { err_msg: string }) => void,
|
|
) => {
|
|
callback({ err_msg: 'get_brand_wcpay_request:cancel' });
|
|
},
|
|
),
|
|
});
|
|
|
|
await expect(
|
|
requestWechatJsapiPayment({
|
|
appId: 'wx-app',
|
|
timeStamp: '1770000000',
|
|
nonceStr: 'nonce',
|
|
package: 'prepay_id=wx',
|
|
signType: 'RSA',
|
|
paySign: 'pay-sign',
|
|
}),
|
|
).rejects.toThrow('微信支付已取消');
|
|
});
|
|
|
|
test('rejects when appId is missing', async () => {
|
|
await expect(
|
|
requestWechatJsapiPayment({
|
|
timeStamp: '1770000000',
|
|
nonceStr: 'nonce',
|
|
package: 'prepay_id=wx',
|
|
signType: 'RSA',
|
|
paySign: 'pay-sign',
|
|
}),
|
|
).rejects.toThrow('微信 JSAPI 支付参数缺少 appId');
|
|
});
|
|
});
|