修复充值中心请求取消

通过现有请求选项透传 AbortSignal,确保共享钱包切换账号时可以中止旧请求。

新增充值中心信号透传回归测试并纳入 Vitest。
This commit is contained in:
2026-08-05 17:40:08 +08:00
parent eaaa5f250b
commit 84e0fa82e6
4 changed files with 40 additions and 3 deletions
@@ -0,0 +1,37 @@
import { beforeEach, describe, expect, test, vi } from 'vitest';
const apiClientMocks = vi.hoisted(() => ({
fetchWithApiAuth: vi.fn(),
requestJson: vi.fn(),
}));
vi.mock('../apiClient', () => apiClientMocks);
import { getPlatformProfileRechargeCenter } from './platformProfileClient';
describe('platformProfileClient', () => {
beforeEach(() => {
apiClientMocks.requestJson.mockReset();
apiClientMocks.requestJson.mockResolvedValue({});
});
test('forwards the recharge-center abort signal through request options', async () => {
const abortController = new AbortController();
await getPlatformProfileRechargeCenter({
signal: abortController.signal,
});
expect(apiClientMocks.requestJson).toHaveBeenCalledWith(
'/api/profile/recharge-center',
{
method: 'GET',
signal: abortController.signal,
},
'读取泥点购买信息失败',
expect.objectContaining({
retry: expect.any(Object),
}),
);
});
});
@@ -142,11 +142,10 @@ export function revokePlatformProfileExternalApiKey(
export function getPlatformProfileRechargeCenter(
options: PlatformProfileRequestOptions = {},
signal?: AbortSignal,
) {
return requestPlatformProfileJson<ProfileRechargeCenterResponse>(
'/recharge-center',
{ method: 'GET', signal },
{ method: 'GET' },
'读取泥点购买信息失败',
options,
);
+1 -1
View File
@@ -5,7 +5,7 @@ import { getPlatformProfileRechargeCenter } from '@/src/services/platform-entry/
export const usePlatformWalletStore = createProfileWalletStore({
getRechargeCenter: (signal) =>
getPlatformProfileRechargeCenter({}, signal),
getPlatformProfileRechargeCenter({ signal }),
});
export function usePlatformWalletLifecycle(
+1
View File
@@ -46,6 +46,7 @@ export default defineConfig({
'src/services/image-editor/**/*.test.ts',
'src/services/external-generation/**/*.test.ts',
'src/services/payment/**/*.test.ts',
'src/services/platform-entry/platformProfileClient.test.ts',
'src/components/auth/**/*.test.ts',
'src/components/auth/**/*.test.tsx',
'src/components/creation-home/**/*.test.ts',