保留充值响应余额兜底
共享泥点明细暂不可用时继续使用充值中心响应中的兼容总额与明细。 补充充值弹窗余额兜底回归测试。
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/* @vitest-environment jsdom */
|
||||
|
||||
import { act, waitFor } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { usePlatformWalletStore } from '../../stores/usePlatformWalletStore';
|
||||
import {
|
||||
profileClientMocks,
|
||||
renderController,
|
||||
userA,
|
||||
} from './usePlatformProfileCenterController.testSupport';
|
||||
|
||||
describe('usePlatformProfileCenterController recharge fallback', () => {
|
||||
beforeEach(() => {
|
||||
window.history.replaceState(null, '', '/profile');
|
||||
usePlatformWalletStore.getState().resetWalletBalance();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('keeps the response legacy balance when no shared snapshot exists', async () => {
|
||||
usePlatformWalletStore.getState().setWalletOwner('user-a');
|
||||
profileClientMocks.getPlatformProfileRechargeCenter.mockResolvedValue({
|
||||
walletBalance: 37,
|
||||
membership: null,
|
||||
pointProducts: [],
|
||||
membershipProducts: [],
|
||||
benefits: [],
|
||||
latestOrder: null,
|
||||
hasPointsRecharged: false,
|
||||
});
|
||||
const { result } = renderController(userA);
|
||||
|
||||
act(() => result.current.loadRechargeCenter());
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.rechargeCenter?.walletBalance).toBe(37);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
/* @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(),
|
||||
}));
|
||||
|
||||
vi.mock('../../services/platform-entry/platformProfileClient', () =>
|
||||
profileClientMocks,
|
||||
);
|
||||
|
||||
export { profileClientMocks };
|
||||
|
||||
import { usePlatformProfileCenterController } from './usePlatformProfileCenterController';
|
||||
|
||||
export const userA = { id: 'user-a' } as AuthUser;
|
||||
export const userB = { id: 'user-b' } as AuthUser;
|
||||
|
||||
export function renderController(
|
||||
currentUser: AuthUser,
|
||||
onRechargeSuccess = vi.fn(),
|
||||
) {
|
||||
return renderHook(
|
||||
({ user }) =>
|
||||
usePlatformProfileCenterController({
|
||||
activeTab: 'settings',
|
||||
isAuthenticated: true,
|
||||
showRechargeEntry: true,
|
||||
onRechargeSuccess,
|
||||
requestLogin: vi.fn(),
|
||||
currentUser: user,
|
||||
}),
|
||||
{ initialProps: { user: currentUser } },
|
||||
);
|
||||
}
|
||||
@@ -1175,8 +1175,9 @@ export function usePlatformProfileCenterController({
|
||||
}
|
||||
return {
|
||||
...rechargeCenter,
|
||||
walletBalance: mudPointBalance?.totalPoints ?? 0,
|
||||
mudPointBalance: mudPointBalance ?? undefined,
|
||||
walletBalance:
|
||||
mudPointBalance?.totalPoints ?? rechargeCenter.walletBalance,
|
||||
mudPointBalance: mudPointBalance ?? rechargeCenter.mudPointBalance,
|
||||
};
|
||||
}, [mudPointBalance, rechargeCenter, walletOwnerMatchesCurrentUser]);
|
||||
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ export default defineConfig({
|
||||
'src/components/platform-entry/PlatformProfileTaskCenterModal.test.tsx',
|
||||
'src/components/platform-entry/PlatformProfileWalletLedgerModal.test.tsx',
|
||||
'src/components/platform-entry/platformProfile*.test.ts',
|
||||
'src/components/platform-entry/usePlatformProfileCenterController.test.tsx',
|
||||
'src/components/platform-entry/usePlatformProfileCenterController*.test.tsx',
|
||||
'src/hooks/useHostNavigationCanGoBack.test.tsx',
|
||||
'apps/admin-web/src/**/*.test.ts',
|
||||
'apps/admin-web/src/**/*.test.tsx',
|
||||
|
||||
Reference in New Issue
Block a user