Files
fast-next-template/frontend/tests/lib/api/client.test.ts
Felipe Cardoso ee938ce6a6 Add extensive form tests and enhanced error handling for auth components.
- Introduced comprehensive tests for `RegisterForm`, `PasswordResetRequestForm`, and `PasswordResetConfirmForm` covering successful submissions, validation errors, and API error handling.
- Refactored forms to handle unexpected errors gracefully and improve test coverage for edge cases.
- Updated `crypto` and `storage` modules with robust error handling for storage issues and encryption key management.
- Removed unused `axios-mock-adapter` dependency for cleaner dependency management.
2025-11-01 05:24:26 +01:00

44 lines
1.5 KiB
TypeScript

/**
* Tests for API client configuration
*
* Tests ensure the client module loads and is configured correctly.
* Note: Interceptor behavior testing requires actual HTTP calls, which is
* better suited for integration/E2E tests. These unit tests verify setup.
*/
import { apiClient } from '@/lib/api/client';
import config from '@/config/app.config';
describe('API Client Configuration', () => {
it('should export apiClient instance', () => {
expect(apiClient).toBeDefined();
expect(apiClient.instance).toBeDefined();
});
it('should have correct baseURL', () => {
// Generated client already has /api/v1 in baseURL
expect(apiClient.instance.defaults.baseURL).toContain(config.api.url);
expect(apiClient.instance.defaults.baseURL).toContain('/api/v1');
});
it('should have correct timeout', () => {
expect(apiClient.instance.defaults.timeout).toBe(config.api.timeout);
});
it('should have correct default headers', () => {
expect(apiClient.instance.defaults.headers['Content-Type']).toBe('application/json');
});
it('should have request interceptors registered', () => {
expect(apiClient.instance.interceptors.request.handlers.length).toBeGreaterThan(0);
});
it('should have response interceptors registered', () => {
expect(apiClient.instance.interceptors.response.handlers.length).toBeGreaterThan(0);
});
it('should have setConfig method', () => {
expect(typeof apiClient.setConfig).toBe('function');
});
});