integration tests
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
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
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { HealthTestContext } from '../HealthTestContext';
|
||||
|
||||
describe('CheckApiHealthUseCase', () => {
|
||||
let context: HealthTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
context = HealthTestContext.create();
|
||||
context.reset();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
context.teardown();
|
||||
});
|
||||
|
||||
describe('Success Path', () => {
|
||||
it('should perform health check and return healthy status', async () => {
|
||||
context.healthCheckAdapter.setResponseTime(50);
|
||||
|
||||
const result = await context.checkApiHealthUseCase.execute();
|
||||
|
||||
expect(result.healthy).toBe(true);
|
||||
expect(result.responseTime).toBeGreaterThanOrEqual(50);
|
||||
expect(result.timestamp).toBeInstanceOf(Date);
|
||||
expect(context.eventPublisher.getEventCountByType('HealthCheckCompleted')).toBe(1);
|
||||
});
|
||||
|
||||
it('should handle health check with custom endpoint', async () => {
|
||||
context.healthCheckAdapter.configureResponse('/custom/health', {
|
||||
healthy: true,
|
||||
responseTime: 50,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
|
||||
const result = await context.checkApiHealthUseCase.execute();
|
||||
|
||||
expect(result.healthy).toBe(true);
|
||||
expect(context.eventPublisher.getEventCountByType('HealthCheckCompleted')).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Failure Path', () => {
|
||||
it('should handle failed health check and return unhealthy status', async () => {
|
||||
context.healthCheckAdapter.setShouldFail(true, 'ECONNREFUSED');
|
||||
|
||||
const result = await context.checkApiHealthUseCase.execute();
|
||||
|
||||
expect(result.healthy).toBe(false);
|
||||
expect(result.error).toBeDefined();
|
||||
expect(context.eventPublisher.getEventCountByType('HealthCheckFailed')).toBe(1);
|
||||
});
|
||||
|
||||
it('should handle timeout during health check', async () => {
|
||||
context.healthCheckAdapter.setShouldFail(true, 'Timeout');
|
||||
|
||||
const result = await context.checkApiHealthUseCase.execute();
|
||||
|
||||
expect(result.healthy).toBe(false);
|
||||
expect(result.error).toContain('Timeout');
|
||||
// Note: CheckApiHealthUseCase might not emit HealthCheckTimeoutEvent if it just catches the error
|
||||
// and emits HealthCheckFailedEvent instead. Let's check what it actually does.
|
||||
expect(context.eventPublisher.getEventCountByType('HealthCheckFailed')).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user