Refactor tests and API context integration
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 5m55s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 5m55s
- Updated tests in `useShoppingLists`, `useWatchedItems`, and various components to use `waitFor` for asynchronous assertions. - Enhanced error handling in `errorHandler` middleware tests to include validation errors and status codes. - Modified `AuthView`, `ProfileManager.Auth`, and `ProfileManager.Authenticated` tests to check for `AbortSignal` in API calls. - Removed duplicate assertions in `auth.routes.test`, `budget.routes.test`, and `gamification.routes.test`. - Introduced reusable logger matcher in `budget.routes.test`, `deals.routes.test`, `flyer.routes.test`, and `user.routes.test`. - Simplified API client mock in `aiApiClient.test` to handle token overrides correctly. - Removed unused `apiUtils.ts` file. - Added `ApiContext` and `ApiProvider` for better API client management in React components.
This commit is contained in:
@@ -63,7 +63,7 @@ describe('AuthView', () => {
|
||||
fireEvent.submit(screen.getByTestId('auth-form'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockedApiClient.loginUser).toHaveBeenCalledWith('test@example.com', 'password123', true);
|
||||
expect(mockedApiClient.loginUser).toHaveBeenCalledWith('test@example.com', 'password123', true, expect.any(AbortSignal));
|
||||
expect(mockOnLoginSuccess).toHaveBeenCalledWith(
|
||||
{ user_id: '123', email: 'test@example.com' },
|
||||
'mock-token',
|
||||
@@ -105,7 +105,7 @@ describe('AuthView', () => {
|
||||
fireEvent.submit(screen.getByTestId('auth-form'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockedApiClient.registerUser).toHaveBeenCalledWith('new@example.com', 'newpassword', 'Test User', '');
|
||||
expect(mockedApiClient.registerUser).toHaveBeenCalledWith('new@example.com', 'newpassword', 'Test User', '', expect.any(AbortSignal));
|
||||
expect(mockOnLoginSuccess).toHaveBeenCalledWith(
|
||||
{ user_id: '123', email: 'test@example.com' },
|
||||
'mock-token',
|
||||
@@ -144,7 +144,7 @@ describe('AuthView', () => {
|
||||
fireEvent.submit(screen.getByTestId('reset-password-form'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockedApiClient.requestPasswordReset).toHaveBeenCalledWith('forgot@example.com');
|
||||
expect(mockedApiClient.requestPasswordReset).toHaveBeenCalledWith('forgot@example.com', expect.any(AbortSignal));
|
||||
expect(notifySuccess).toHaveBeenCalledWith('Password reset email sent.');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user