Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
Health Integration Tests
This directory contains integration tests for health-related functionality in the GridPilot project.
Purpose
These tests verify the orchestration logic of health-related Use Cases and their interactions with Ports using In-Memory adapters. They focus on business logic, not UI rendering.
Test Structure
1. API Connection Monitor Tests (api-connection-monitor.integration.test.ts)
Tests the ApiConnectionMonitor class which handles:
- Health check execution: Performing HTTP health checks against API endpoints
- Connection status tracking: Managing connection states (connected, degraded, disconnected, checking)
- Metrics calculation: Tracking success/failure rates, response times, and reliability
- Event emission: Emitting events for status changes and health check results
Key Scenarios:
- Successful health checks with varying response times
- Failed health checks (network errors, timeouts)
- Connection status transitions (disconnected → connected, connected → degraded)
- Reliability and average response time calculations
- Multiple endpoint fallback strategies
- Event emission patterns
2. Health Check Use Cases Tests (health-check-use-cases.integration.test.ts)
Tests the health-related Use Cases:
- CheckApiHealthUseCase: Executes health checks and returns status
- GetConnectionStatusUseCase: Retrieves current connection status and metrics
Key Scenarios:
- Successful health check execution
- Failed health check handling
- Connection status retrieval (connected, degraded, disconnected, checking)
- Metrics calculation and formatting
- Event emission for status changes
- Error handling and validation
Testing Philosophy
These tests follow the Clean Integration Strategy:
- Focus on Use Case Orchestration: Tests verify how Use Cases interact with their Ports (Repositories, Adapters, Event Publishers)
- In-Memory Adapters: Use in-memory implementations for speed and determinism
- Business Logic Only: Tests verify business logic, not UI rendering or external dependencies
- Given/When/Then Structure: Clear test scenarios with explicit preconditions and expected outcomes
Test Categories
Success Path Tests
- Verify correct behavior when all operations succeed
- Test with various data scenarios (minimal data, complete data, edge cases)
Failure Path Tests
- Verify error handling for network failures
- Test timeout scenarios
- Handle malformed responses
Edge Case Tests
- Empty or missing data
- Concurrent operations
- Invalid inputs
Metrics Calculation Tests
- Reliability percentage calculation
- Average response time calculation
- Status transition logic
Running Tests
# Run all health integration tests
npm test -- tests/integration/health/
# Run specific test file
npm test -- tests/integration/health/api-connection-monitor.integration.test.ts
Implementation Notes
These are placeholder tests with TODO comments. They define the test structure and scenarios but do not contain actual implementation. When implementing:
- Create the necessary In-Memory adapters in
adapters/health/persistence/inmemory/ - Create the Use Cases in
core/health/use-cases/ - Create the Ports in
core/health/ports/ - Implement the test logic following the Given/When/Then patterns defined in each test