fix
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
* Configures global test environment, mocks, and utilities
|
||||
*/
|
||||
|
||||
import { jest } from '@jest/globals';
|
||||
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';
|
||||
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";
|
||||
|
||||
// Mock console methods to reduce noise in tests
|
||||
const originalConsole = global.console;
|
||||
@@ -20,7 +19,7 @@ global.console = {
|
||||
info: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
error: jest.fn(),
|
||||
debug: jest.fn()
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
// Global test utilities
|
||||
@@ -36,10 +35,10 @@ global.testUtils = {
|
||||
status,
|
||||
data,
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
...headers
|
||||
"content-type": "application/json",
|
||||
...headers,
|
||||
},
|
||||
statusText: status === 200 ? 'OK' : 'Error'
|
||||
statusText: status === 200 ? "OK" : "Error",
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -47,26 +46,27 @@ global.testUtils = {
|
||||
* @param {string} authType - Authentication type
|
||||
* @returns {string} Mock token
|
||||
*/
|
||||
createMockToken: (authType = 'provider') => `mock_${authType}_token_${Date.now()}`,
|
||||
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
|
||||
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,
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -74,18 +74,18 @@ global.testUtils = {
|
||||
* @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',
|
||||
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
|
||||
}
|
||||
patientPortal: false,
|
||||
},
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -93,14 +93,14 @@ global.testUtils = {
|
||||
* @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'
|
||||
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",
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -108,13 +108,13 @@ global.testUtils = {
|
||||
* @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'
|
||||
id: "test-appointment-101",
|
||||
patientId: "test-patient-123",
|
||||
providerId: "test-provider-456",
|
||||
date: "2025-07-15",
|
||||
time: "10:00",
|
||||
type: "consultation",
|
||||
status: "scheduled",
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -122,7 +122,7 @@ global.testUtils = {
|
||||
* @param {number} ms - Milliseconds to wait
|
||||
* @returns {Promise} Promise that resolves after the specified time
|
||||
*/
|
||||
wait: (ms) => new Promise(resolve => setTimeout(resolve, ms)),
|
||||
wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
||||
|
||||
/**
|
||||
* Generate a random string for testing
|
||||
@@ -130,26 +130,27 @@ global.testUtils = {
|
||||
* @returns {string} Random string
|
||||
*/
|
||||
randomString: (length = 10) => {
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let result = '';
|
||||
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'
|
||||
PUBLIC: "public",
|
||||
PROVIDER: "provider",
|
||||
PATIENT: "patient",
|
||||
PARTNER: "partner",
|
||||
AFFILIATE: "affiliate",
|
||||
NETWORK: "network",
|
||||
},
|
||||
|
||||
|
||||
HTTP_STATUS: {
|
||||
OK: 200,
|
||||
CREATED: 201,
|
||||
@@ -157,21 +158,21 @@ global.testConstants = {
|
||||
UNAUTHORIZED: 401,
|
||||
FORBIDDEN: 403,
|
||||
NOT_FOUND: 404,
|
||||
INTERNAL_SERVER_ERROR: 500
|
||||
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'
|
||||
}
|
||||
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);
|
||||
process.on("unhandledRejection", (reason, promise) => {
|
||||
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
||||
});
|
||||
|
||||
// Cleanup after each test
|
||||
|
Reference in New Issue
Block a user