/** * @fileoverview Jest setup configuration for Laravel Healthcare MCP Server tests * Configures global test environment, mocks, and utilities */ import { jest } from '@jest/globals'; // Set test environment variables process.env.NODE_ENV = 'test'; process.env.LARAVEL_API_BASE_URL = 'https://test-api.example.com'; process.env.LARAVEL_API_TIMEOUT = '5000'; process.env.LARAVEL_API_RETRY_ATTEMPTS = '2'; process.env.TOKEN_CACHE_DURATION = '300'; // Mock console methods to reduce noise in tests const originalConsole = global.console; global.console = { ...originalConsole, log: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn(), debug: jest.fn() }; // Global test utilities global.testUtils = { /** * Create a mock HTTP response * @param {number} status - HTTP status code * @param {Object} data - Response data * @param {Object} headers - Response headers * @returns {Object} Mock response object */ createMockResponse: (status = 200, data = {}, headers = {}) => ({ status, data, headers: { 'content-type': 'application/json', ...headers }, statusText: status === 200 ? 'OK' : 'Error' }), /** * Create a mock authentication token * @param {string} authType - Authentication type * @returns {string} Mock token */ createMockToken: (authType = 'provider') => `mock_${authType}_token_${Date.now()}`, /** * Create mock patient data for HIPAA-compliant testing * @returns {Object} Mock patient data */ createMockPatientData: () => ({ id: 'test-patient-123', firstName: 'John', lastName: 'Doe', email: 'john.doe@test.example.com', dateOfBirth: '1990-01-01', genderIdentity: 'Male', preferredPhone: '555-0123', address: '123 Test St', city: 'Test City', state: 'TS', zipcode: '12345', status: 'active', isPortalAccess: true }), /** * Create mock provider data * @returns {Object} Mock provider data */ createMockProviderData: () => ({ id: 'test-provider-456', firstName: 'Dr. Jane', lastName: 'Smith', emailAddress: 'dr.smith@test.example.com', textMessageNumber: '555-0456', username: 'drsmith', company_name: 'Test Medical Center', accessRights: { admin: true, practitioner: true, patientPortal: false } }), /** * Create mock prescription data * @returns {Object} Mock prescription data */ createMockPrescriptionData: () => ({ id: 'test-prescription-789', patientId: 'test-patient-123', providerId: 'test-provider-456', medication: 'Test Medication', dosage: '10mg', frequency: 'Once daily', duration: '30 days', status: 'active' }), /** * Create mock appointment data * @returns {Object} Mock appointment data */ createMockAppointmentData: () => ({ id: 'test-appointment-101', patientId: 'test-patient-123', providerId: 'test-provider-456', date: '2025-07-15', time: '10:00', type: 'consultation', status: 'scheduled' }), /** * Wait for a specified amount of time * @param {number} ms - Milliseconds to wait * @returns {Promise} Promise that resolves after the specified time */ wait: (ms) => new Promise(resolve => setTimeout(resolve, ms)), /** * Generate a random string for testing * @param {number} length - Length of the string * @returns {string} Random string */ randomString: (length = 10) => { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; let result = ''; for (let i = 0; i < length; i++) { result += chars.charAt(Math.floor(Math.random() * chars.length)); } return result; } }; // Global test constants global.testConstants = { AUTH_TYPES: { PUBLIC: 'public', PROVIDER: 'provider', PATIENT: 'patient', PARTNER: 'partner', AFFILIATE: 'affiliate', NETWORK: 'network' }, HTTP_STATUS: { OK: 200, CREATED: 201, BAD_REQUEST: 400, UNAUTHORIZED: 401, FORBIDDEN: 403, NOT_FOUND: 404, INTERNAL_SERVER_ERROR: 500 }, MOCK_ENDPOINTS: { LOGIN: '/api/login', PATIENT_LOGIN: '/api/frontend/login', PROVIDER_REGISTER: '/emr-api/provider-register', PATIENT_UPDATE: '/api/emr/update-patient', PRESCRIPTION_CREATE: '/api/emr/prescriptions' } }; // Setup global error handling for tests process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled Rejection at:', promise, 'reason:', reason); }); // Cleanup after each test afterEach(() => { jest.clearAllMocks(); }); // Global teardown afterAll(() => { // Restore original console global.console = originalConsole; });