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:
77
adapters/events/InMemoryEventPublisher.test.ts
Normal file
77
adapters/events/InMemoryEventPublisher.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { InMemoryEventPublisher } from './InMemoryEventPublisher';
|
||||
import { DashboardAccessedEvent } from '../../core/dashboard/application/ports/DashboardEventPublisher';
|
||||
import { LeagueCreatedEvent } from '../../core/leagues/application/ports/LeagueEventPublisher';
|
||||
|
||||
describe('InMemoryEventPublisher', () => {
|
||||
let publisher: InMemoryEventPublisher;
|
||||
|
||||
beforeEach(() => {
|
||||
publisher = new InMemoryEventPublisher();
|
||||
});
|
||||
|
||||
describe('Dashboard Events', () => {
|
||||
it('should publish and track dashboard accessed events', async () => {
|
||||
// Given
|
||||
const event: DashboardAccessedEvent = { userId: 'user-1', timestamp: new Date() };
|
||||
|
||||
// When
|
||||
await publisher.publishDashboardAccessed(event);
|
||||
|
||||
// Then
|
||||
expect(publisher.getDashboardAccessedEventCount()).toBe(1);
|
||||
});
|
||||
|
||||
it('should throw error when configured to fail', async () => {
|
||||
// Given
|
||||
publisher.setShouldFail(true);
|
||||
const event: DashboardAccessedEvent = { userId: 'user-1', timestamp: new Date() };
|
||||
|
||||
// When & Then
|
||||
await expect(publisher.publishDashboardAccessed(event)).rejects.toThrow('Event publisher failed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('League Events', () => {
|
||||
it('should publish and track league created events', async () => {
|
||||
// Given
|
||||
const event: LeagueCreatedEvent = { leagueId: 'league-1', name: 'Test League', timestamp: new Date() };
|
||||
|
||||
// When
|
||||
await publisher.emitLeagueCreated(event);
|
||||
|
||||
// Then
|
||||
expect(publisher.getLeagueCreatedEventCount()).toBe(1);
|
||||
expect(publisher.getLeagueCreatedEvents()).toContainEqual(event);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Generic Domain Events', () => {
|
||||
it('should publish and track generic domain events', async () => {
|
||||
// Given
|
||||
const event = { type: 'TestEvent', timestamp: new Date() };
|
||||
|
||||
// When
|
||||
await publisher.publish(event);
|
||||
|
||||
// Then
|
||||
expect(publisher.getEvents()).toContainEqual(event);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Maintenance', () => {
|
||||
it('should clear all events', async () => {
|
||||
// Given
|
||||
await publisher.publishDashboardAccessed({ userId: 'u1', timestamp: new Date() });
|
||||
await publisher.emitLeagueCreated({ leagueId: 'l1', name: 'L1', timestamp: new Date() });
|
||||
await publisher.publish({ type: 'Generic', timestamp: new Date() });
|
||||
|
||||
// When
|
||||
publisher.clear();
|
||||
|
||||
// Then
|
||||
expect(publisher.getDashboardAccessedEventCount()).toBe(0);
|
||||
expect(publisher.getLeagueCreatedEventCount()).toBe(0);
|
||||
expect(publisher.getEvents().length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user