Adopt TanStack Query fixes
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 14m41s

This commit is contained in:
2026-01-10 17:42:45 -08:00
parent d8aa19ac40
commit 503e7084da
25 changed files with 1887 additions and 395 deletions

View File

@@ -2,6 +2,7 @@
import React, { useContext, useState } from 'react';
import { render, screen, waitFor, fireEvent, act } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach, type Mocked } from 'vitest';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { AuthProvider } from './AuthProvider';
import { AuthContext } from '../contexts/AuthContext';
import * as tokenStorage from '../services/tokenStorage';
@@ -59,11 +60,28 @@ const TestConsumer = () => {
);
};
// Create a fresh QueryClient for each test to ensure isolation
const createTestQueryClient = () =>
new QueryClient({
defaultOptions: {
queries: {
retry: false,
gcTime: 0,
},
mutations: {
retry: false,
},
},
});
const renderWithProvider = () => {
const testQueryClient = createTestQueryClient();
return render(
<AuthProvider>
<TestConsumer />
</AuthProvider>,
<QueryClientProvider client={testQueryClient}>
<AuthProvider>
<TestConsumer />
</AuthProvider>
</QueryClientProvider>,
);
};
@@ -198,7 +216,7 @@ describe('AuthProvider', () => {
await waitFor(() => {
// The error is now caught and displayed by the TestConsumer
expect(screen.getByTestId('error-display')).toHaveTextContent(
'Login succeeded, but failed to fetch your data: Received null or undefined profile from API.',
'Login succeeded, but failed to fetch your data: API is down',
);
expect(mockedTokenStorage.setToken).toHaveBeenCalledWith('test-token-no-profile');

View File

@@ -45,6 +45,12 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
removeToken();
setUserProfile(null);
setAuthStatus('SIGNED_OUT');
} else if (token && isFetched && !fetchedProfile) {
// Token exists, query completed, but profile is null - sign out
logger.warn('[AuthProvider] Token was present but profile is null. Signing out.');
removeToken();
setUserProfile(null);
setAuthStatus('SIGNED_OUT');
} else if (!token) {
logger.info('[AuthProvider] No auth token found. Setting state to SIGNED_OUT.');
setAuthStatus('SIGNED_OUT');