10 KiB
Laravel Healthcare MCP Server - Testing Guide
Overview
This document provides comprehensive guidance for testing the Laravel Healthcare MCP Server. The test suite includes over 1000+ tests covering all authentication types, healthcare-specific scenarios, HIPAA compliance, and error handling.
Test Structure
Test Organization
tests/
├── mocks/ # Mock utilities and factories
│ ├── httpMocks.js # HTTP request/response mocking
│ ├── authMocks.js # Authentication mocking
│ ├── healthcareDataMocks.js # Healthcare data generation
│ └── mockFactory.js # Centralized mock factory
├── public/ # Public tools tests (77 tools)
│ ├── login.test.js # Login and authentication
│ ├── registration.test.js # User registration
│ ├── password-management.test.js # Password operations
│ ├── data-access.test.js # Public data access
│ └── index.test.js # Integration tests
├── provider/ # Provider tools tests (400+ tools)
│ ├── emr-patient-management.test.js # EMR and patient data
│ ├── prescription-management.test.js # Prescriptions and medications
│ └── appointment-scheduling.test.js # Appointments and scheduling
├── patient/ # Patient tools tests (200+ tools)
│ ├── portal-authentication.test.js # Patient portal access
│ └── data-management.test.js # Patient data operations
├── partner-affiliate-network/ # Business tools tests (300+ tools)
│ └── business-operations.test.js # Business operations
├── healthcare-specific/ # Healthcare compliance tests
│ ├── hipaa-compliance.test.js # HIPAA compliance validation
│ └── clinical-workflows.test.js # Clinical decision support
├── error-handling/ # Error handling tests
│ ├── authentication-errors.test.js # Auth error scenarios
│ └── api-network-errors.test.js # API and network errors
└── coverage/ # Test coverage and reporting
└── test-runner.js # Comprehensive test runner
Running Tests
Quick Start
# Run all tests with coverage
npm test
# Run quick test suite (essential tests only)
npm run test:quick
# Run tests with watch mode
npm run test:watch
Test Suites
# Public tools (login, registration, password management)
npm run test:public
# Provider tools (EMR, prescriptions, appointments)
npm run test:provider
# Patient tools (portal, data management)
npm run test:patient
# Business tools (partner, affiliate, network)
npm run test:business
# Healthcare-specific tests (HIPAA, clinical workflows)
npm run test:healthcare
# Error handling tests
npm run test:errors
Coverage and Reporting
# Generate coverage report only
npm run test:coverage
# Healthcare compliance validation
npm run test:compliance
# CI/CD pipeline tests (all reports)
npm run test:ci
Advanced Test Execution
# Run specific test suite with options
node run-tests.js suite provider --coverage --verbose
# Run all tests in parallel with detailed reporting
node run-tests.js all --parallel --format=detailed
# Generate compliance report
node run-tests.js compliance
Test Categories
1. Public Tools Tests (77 tools)
Coverage: All public authentication and registration endpoints
Key Test Areas:
- Login endpoints (9 different auth types)
- Registration workflows (8 user types)
- Password management (10 operations)
- Email verification and validation
- Public data access endpoints
Example Test:
test('should successfully login with valid credentials', async () => {
const result = await toolGenerator.executeTool('public_create_login', {
username: 'testuser',
password: 'testpassword'
});
expect(result.success).toBe(true);
expect(result.data.token).toBeDefined();
});
2. Provider Tools Tests (400+ tools)
Coverage: EMR, clinical data, prescriptions, appointments
Key Test Areas:
- Patient registration and management
- Medical records creation and updates
- Prescription management with drug interactions
- Appointment scheduling and cancellation
- Vital signs recording and validation
- Clinical decision support
HIPAA Compliance:
- PHI data encryption and access controls
- Audit trail generation
- Minimum necessary standard
- Provider authentication requirements
3. Patient Tools Tests (200+ tools)
Coverage: Patient portal and self-service operations
Key Test Areas:
- Patient portal authentication
- Profile management and updates
- Medical record access (own data only)
- Appointment scheduling and cancellation
- Prescription viewing
- Consent management
Security Features:
- Patient data isolation
- Access scope validation
- Session management
- Two-factor authentication
4. Business Tools Tests (300+ tools)
Coverage: Partner, affiliate, and network operations
Key Test Areas:
- Business data analytics
- Referral management
- Commission tracking
- Network status monitoring
- Member directory access
- Performance metrics
5. Healthcare-Specific Tests
HIPAA Compliance Validation:
- PHI handling and encryption
- Access controls and authorization
- Audit trails and logging
- Data breach prevention
- Business Associate Agreements
Clinical Workflows:
- Clinical Decision Support System (CDSS)
- Drug interaction alerts
- Medical coding validation (ICD-10, CPT)
- Care coordination workflows
- Quality measures tracking
6. Error Handling Tests
Authentication Errors:
- Invalid credentials
- Account lockout scenarios
- Token expiration
- Session conflicts
- Permission violations
API and Network Errors:
- Network connectivity issues
- HTTP status code handling
- Timeout scenarios
- Retry mechanisms
- Circuit breaker patterns
Mock System
HTTP Mocking
// Mock successful API response
mockFactory.httpMocks.mockRequest('POST', '/api/endpoint', {
status: 200,
data: { success: true, result: 'data' }
});
// Mock error response
mockFactory.httpMocks.mockRequest('POST', '/api/endpoint', null, true, {
response: { status: 401, data: { error: 'Unauthorized' } }
});
Authentication Mocking
// Setup mock credentials
mockFactory.authMocks.setMockCredentials('provider', {
username: 'test_provider',
password: 'test_password'
});
// Create HIPAA-compliant mock data
const mockPatient = mockFactory.healthcareMocks.createHIPAACompliantData(
'patient', 'provider'
);
Coverage Requirements
Minimum Coverage Thresholds
- Lines: 80%
- Functions: 80%
- Branches: 80%
- Statements: 80%
Per-File Thresholds
- Lines: 70%
- Functions: 70%
- Branches: 70%
- Statements: 70%
Healthcare Compliance Testing
HIPAA Compliance Checklist
- ✅ PHI data encryption (AES-256)
- ✅ Access controls and RBAC
- ✅ Comprehensive audit trails
- ✅ Minimum necessary standard
- ✅ Data breach prevention
- ✅ Patient consent verification
- ✅ Business Associate Agreement validation
Clinical Workflow Validation
- ✅ Drug interaction checking
- ✅ Allergy contraindication alerts
- ✅ Dosage adjustment recommendations
- ✅ Medical coding validation
- ✅ Care team coordination
- ✅ Quality measures tracking
Continuous Integration
CI/CD Pipeline Integration
# Example GitHub Actions workflow
- name: Run Healthcare MCP Tests
run: npm run test:ci
- name: Upload Coverage Reports
uses: codecov/codecov-action@v3
with:
file: ./coverage/lcov.info
- name: Generate Compliance Report
run: npm run test:compliance
Test Reports
The test suite generates multiple report formats:
- Detailed Report: Complete test results with metadata
- Summary Report: High-level overview and statistics
- Coverage Report: Code coverage analysis
- Compliance Report: Healthcare compliance validation
Best Practices
Writing Tests
- Use descriptive test names that explain the scenario
- Follow AAA pattern: Arrange, Act, Assert
- Mock external dependencies using the provided mock system
- Test both success and failure scenarios
- Include HIPAA compliance validation for healthcare data
- Verify audit trails for sensitive operations
Healthcare-Specific Testing
- Always test PHI handling with proper encryption
- Validate access controls for different user roles
- Test audit trail generation for compliance
- Include clinical decision support validation
- Test emergency access scenarios (break-glass)
- Validate medical coding accuracy
Error Handling
- Test all error scenarios including edge cases
- Validate error messages are user-friendly
- Test retry mechanisms and circuit breakers
- Include security incident handling
- Test graceful degradation scenarios
Troubleshooting
Common Issues
- Mock not working: Ensure mock is set up before test execution
- Authentication failures: Verify mock credentials are configured
- Coverage gaps: Check for untested code paths
- Flaky tests: Review async operations and timing
Debug Mode
# Run tests with verbose output
npm run test:jest -- --verbose
# Run specific test file
npm run test:jest -- tests/public/login.test.js
# Debug with Node.js inspector
node --inspect-brk run-tests.js all
Contributing
When adding new tests:
- Follow the existing test structure and naming conventions
- Include both positive and negative test cases
- Add appropriate mocks for external dependencies
- Ensure HIPAA compliance for healthcare-related tests
- Update this documentation for new test categories
- Maintain minimum coverage thresholds
Support
For testing support and questions:
- Review existing test examples in the test suites
- Check the mock factory for available utilities
- Refer to Jest documentation for advanced features
- Contact the development team for healthcare compliance questions