fc0dcb0782
refactor: - 主站复用game agent的zustand store fix: - 修复旧请求覆盖问题 - 修复账号切换问题 - 主站原本已经每 4 秒轮询 external generation 任务状态, 在这里补充触发余额刷新的时机 --------- Co-authored-by: 段舒康 <kdletters@qq.com> Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/138 Co-authored-by: 王德宇 <kvtodev@outlook.com> Co-committed-by: 王德宇 <kvtodev@outlook.com>
103 lines
2.8 KiB
TypeScript
103 lines
2.8 KiB
TypeScript
/* @vitest-environment jsdom */
|
|
|
|
import { renderHook } from '@testing-library/react';
|
|
import { vi } from 'vitest';
|
|
|
|
import type { AuthUser } from '../../services/authService';
|
|
|
|
const profileClientMocks = vi.hoisted(() => ({
|
|
confirmWechatPlatformProfileRechargeOrder: vi.fn(),
|
|
createPlatformProfileRechargeOrder: vi.fn(),
|
|
getPlatformProfileRechargeCenter: vi.fn(),
|
|
getPlatformProfileReferralInviteCenter: vi.fn(),
|
|
getPlatformProfileWalletLedger: vi.fn(),
|
|
redeemPlatformProfileReferralInviteCode: vi.fn(),
|
|
redeemPlatformProfileRewardCode: vi.fn(),
|
|
watchWechatPlatformProfileRechargeOrder: vi.fn(),
|
|
}));
|
|
|
|
const apiClientMocks = vi.hoisted(() => ({
|
|
clearStoredAccessToken: vi.fn(),
|
|
}));
|
|
|
|
const hostBridgeMocks = vi.hoisted(() => ({
|
|
getHostRuntime: vi.fn(() => ({ kind: 'browser' })),
|
|
requestHostLogin: vi.fn(),
|
|
requestHostPayment: vi.fn(),
|
|
}));
|
|
|
|
const paymentPlatformMocks = vi.hoisted(() => ({
|
|
resolveProfileRechargeProductPaymentChannel: vi.fn(() => 'wechat_native'),
|
|
}));
|
|
|
|
vi.mock(
|
|
'../../services/platform-entry/platformProfileClient',
|
|
() => profileClientMocks,
|
|
);
|
|
|
|
vi.mock('../../services/apiClient', async () => {
|
|
const actual = await vi.importActual<
|
|
typeof import('../../services/apiClient')
|
|
>('../../services/apiClient');
|
|
return { ...actual, ...apiClientMocks };
|
|
});
|
|
|
|
vi.mock('../../services/host-bridge/hostBridge', async () => {
|
|
const actual = await vi.importActual<
|
|
typeof import('../../services/host-bridge/hostBridge')
|
|
>('../../services/host-bridge/hostBridge');
|
|
return { ...actual, ...hostBridgeMocks };
|
|
});
|
|
|
|
vi.mock('../../services/payment/paymentPlatform', async () => {
|
|
const actual = await vi.importActual<
|
|
typeof import('../../services/payment/paymentPlatform')
|
|
>('../../services/payment/paymentPlatform');
|
|
return { ...actual, ...paymentPlatformMocks };
|
|
});
|
|
|
|
export {
|
|
apiClientMocks,
|
|
hostBridgeMocks,
|
|
paymentPlatformMocks,
|
|
profileClientMocks,
|
|
};
|
|
|
|
import { usePlatformProfileCenterController } from './usePlatformProfileCenterController';
|
|
|
|
const baseUser = {
|
|
publicUserCode: '100001',
|
|
displayName: '测试用户',
|
|
avatarUrl: null,
|
|
phoneNumberMasked: null,
|
|
loginMethod: 'password',
|
|
bindingStatus: 'active',
|
|
wechatBound: false,
|
|
} satisfies Omit<AuthUser, 'id'>;
|
|
|
|
export const userA = { ...baseUser, id: 'user-a' } satisfies AuthUser;
|
|
export const userB = {
|
|
...baseUser,
|
|
id: 'user-b',
|
|
publicUserCode: '100002',
|
|
} satisfies AuthUser;
|
|
|
|
export function renderController(
|
|
currentUser: AuthUser,
|
|
onRechargeSuccess = vi.fn(),
|
|
) {
|
|
const requestLogin = vi.fn();
|
|
return renderHook(
|
|
({ user }) =>
|
|
usePlatformProfileCenterController({
|
|
activeTab: 'settings',
|
|
isAuthenticated: true,
|
|
showRechargeEntry: true,
|
|
onRechargeSuccess,
|
|
requestLogin,
|
|
currentUser: user,
|
|
}),
|
|
{ initialProps: { user: currentUser } },
|
|
);
|
|
}
|