Skip to content

Commit d69bbc5

Browse files
arbrandesclaude
andcommitted
test: add normal user happy path test for useInitializeLearnerHome
Verifies the basic flow: API is called without masquerade user, data is returned with coursesByCardId transformation applied. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 11755a8 commit d69bbc5

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/data/hooks/queryHooks.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ describe('queryHooks', () => {
6666
const mockQueryData = { courses: ['query-course'], user: 'query-user' };
6767
const mockNormalUserData = { courses: ['normal-course'], user: 'normal-user', coursesByCardId: {} };
6868

69+
it('should fetch and return data with coursesByCardId for normal user', async () => {
70+
mockUseMasquerade.mockReturnValue({
71+
masqueradeUser: undefined,
72+
setMasqueradeUser(): void { throw new Error('Function not implemented.'); },
73+
});
74+
const mockApiData = {
75+
courses: [{ id: 'course-1' }, { id: 'course-2' }],
76+
emailConfirmation: { isNeeded: false },
77+
platformSettings: { supportEmail: 'test@example.com' },
78+
};
79+
(api.initializeList as jest.Mock).mockResolvedValue(mockApiData);
80+
81+
const { result } = renderHook(() => useInitializeLearnerHome(), {
82+
wrapper: createWrapper(),
83+
});
84+
85+
await waitFor(() => {
86+
expect(result.current.isSuccess).toBe(true);
87+
});
88+
89+
expect(api.initializeList).toHaveBeenCalledWith(undefined);
90+
expect(result.current.data).toMatchObject(mockApiData);
91+
expect(result.current.data?.coursesByCardId).toEqual({
92+
'card-0': { id: 'course-1', cardId: 'card-0' },
93+
'card-1': { id: 'course-2', cardId: 'card-1' },
94+
});
95+
});
96+
6997
it('should use query data when masquerading and query succeeds', async () => {
7098
const masqueradeUser = 'test-user';
7199
mockUseMasquerade.mockReturnValue({

0 commit comments

Comments
 (0)