fix wechat virtual payment coin flow

This commit is contained in:
kdletters
2026-05-30 16:42:25 +08:00
parent e941ac4539
commit aaaba77c3a
8 changed files with 496 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ const {
describe('wechat-pay mini program payment bridge', () => {
beforeEach(() => {
vi.spyOn(console, 'error').mockImplementation(() => {});
globalThis.wx = {
requestPayment: vi.fn(),
requestVirtualPayment: vi.fn(),
@@ -100,8 +101,12 @@ describe('wechat-pay mini program payment bridge', () => {
});
test('maps virtual payment cancel errCode to cancel result', async () => {
const payError = {
errCode: -2,
errMsg: 'requestVirtualPayment:fail cancel',
};
globalThis.wx.requestVirtualPayment.mockImplementationOnce((options) => {
options.fail?.({ errCode: -2, errMsg: 'requestVirtualPayment:fail cancel' });
options.fail?.(payError);
});
await expect(
@@ -118,6 +123,10 @@ describe('wechat-pay mini program payment bridge', () => {
errMsg: 'requestVirtualPayment:fail cancel',
}),
});
expect(console.error).toHaveBeenCalledWith(
'[wechat-pay] requestVirtualPayment failed',
payError,
);
});
test('page notifies previous web-view after virtual payment', async () => {