adapter 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:
103
adapters/events/InMemoryHealthEventPublisher.test.ts
Normal file
103
adapters/events/InMemoryHealthEventPublisher.test.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { InMemoryHealthEventPublisher } from './InMemoryHealthEventPublisher';
|
||||
|
||||
describe('InMemoryHealthEventPublisher', () => {
|
||||
let publisher: InMemoryHealthEventPublisher;
|
||||
|
||||
beforeEach(() => {
|
||||
publisher = new InMemoryHealthEventPublisher();
|
||||
});
|
||||
|
||||
describe('Health Check Events', () => {
|
||||
it('should publish and track health check completed events', async () => {
|
||||
// Given
|
||||
const event = {
|
||||
healthy: true,
|
||||
responseTime: 100,
|
||||
timestamp: new Date(),
|
||||
endpoint: 'http://api.test/health',
|
||||
};
|
||||
|
||||
// When
|
||||
await publisher.publishHealthCheckCompleted(event);
|
||||
|
||||
// Then
|
||||
expect(publisher.getEventCount()).toBe(1);
|
||||
expect(publisher.getEventCountByType('HealthCheckCompleted')).toBe(1);
|
||||
const events = publisher.getEventsByType('HealthCheckCompleted');
|
||||
expect(events[0]).toMatchObject({
|
||||
type: 'HealthCheckCompleted',
|
||||
...event,
|
||||
});
|
||||
});
|
||||
|
||||
it('should publish and track health check failed events', async () => {
|
||||
// Given
|
||||
const event = {
|
||||
error: 'Connection refused',
|
||||
timestamp: new Date(),
|
||||
endpoint: 'http://api.test/health',
|
||||
};
|
||||
|
||||
// When
|
||||
await publisher.publishHealthCheckFailed(event);
|
||||
|
||||
// Then
|
||||
expect(publisher.getEventCountByType('HealthCheckFailed')).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Connection Status Events', () => {
|
||||
it('should publish and track connected events', async () => {
|
||||
// Given
|
||||
const event = {
|
||||
timestamp: new Date(),
|
||||
responseTime: 50,
|
||||
};
|
||||
|
||||
// When
|
||||
await publisher.publishConnected(event);
|
||||
|
||||
// Then
|
||||
expect(publisher.getEventCountByType('Connected')).toBe(1);
|
||||
});
|
||||
|
||||
it('should publish and track disconnected events', async () => {
|
||||
// Given
|
||||
const event = {
|
||||
timestamp: new Date(),
|
||||
consecutiveFailures: 3,
|
||||
};
|
||||
|
||||
// When
|
||||
await publisher.publishDisconnected(event);
|
||||
|
||||
// Then
|
||||
expect(publisher.getEventCountByType('Disconnected')).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error Handling', () => {
|
||||
it('should throw error when configured to fail', async () => {
|
||||
// Given
|
||||
publisher.setShouldFail(true);
|
||||
const event = { timestamp: new Date() };
|
||||
|
||||
// When & Then
|
||||
await expect(publisher.publishChecking(event)).rejects.toThrow('Event publisher failed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Maintenance', () => {
|
||||
it('should clear all events', async () => {
|
||||
// Given
|
||||
await publisher.publishChecking({ timestamp: new Date() });
|
||||
await publisher.publishConnected({ timestamp: new Date(), responseTime: 10 });
|
||||
|
||||
// When
|
||||
publisher.clear();
|
||||
|
||||
// Then
|
||||
expect(publisher.getEventCount()).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user