import { DashboardEventPublisher, DashboardAccessedEvent, DashboardErrorEvent, } from '../../core/dashboard/application/ports/DashboardEventPublisher'; import { LeagueEventPublisher, LeagueCreatedEvent, LeagueUpdatedEvent, LeagueDeletedEvent, LeagueAccessedEvent, LeagueRosterAccessedEvent, } from '../../core/leagues/application/ports/LeagueEventPublisher'; export class InMemoryEventPublisher implements DashboardEventPublisher, LeagueEventPublisher { private dashboardAccessedEvents: DashboardAccessedEvent[] = []; private dashboardErrorEvents: DashboardErrorEvent[] = []; private leagueCreatedEvents: LeagueCreatedEvent[] = []; private leagueUpdatedEvents: LeagueUpdatedEvent[] = []; private leagueDeletedEvents: LeagueDeletedEvent[] = []; private leagueAccessedEvents: LeagueAccessedEvent[] = []; private leagueRosterAccessedEvents: LeagueRosterAccessedEvent[] = []; private shouldFail: boolean = false; async publishDashboardAccessed(event: DashboardAccessedEvent): Promise { if (this.shouldFail) throw new Error('Event publisher failed'); this.dashboardAccessedEvents.push(event); } async publishDashboardError(event: DashboardErrorEvent): Promise { if (this.shouldFail) throw new Error('Event publisher failed'); this.dashboardErrorEvents.push(event); } async emitLeagueCreated(event: LeagueCreatedEvent): Promise { if (this.shouldFail) throw new Error('Event publisher failed'); this.leagueCreatedEvents.push(event); } async emitLeagueUpdated(event: LeagueUpdatedEvent): Promise { if (this.shouldFail) throw new Error('Event publisher failed'); this.leagueUpdatedEvents.push(event); } async emitLeagueDeleted(event: LeagueDeletedEvent): Promise { if (this.shouldFail) throw new Error('Event publisher failed'); this.leagueDeletedEvents.push(event); } async emitLeagueAccessed(event: LeagueAccessedEvent): Promise { if (this.shouldFail) throw new Error('Event publisher failed'); this.leagueAccessedEvents.push(event); } async emitLeagueRosterAccessed(event: LeagueRosterAccessedEvent): Promise { if (this.shouldFail) throw new Error('Event publisher failed'); this.leagueRosterAccessedEvents.push(event); } getDashboardAccessedEventCount(): number { return this.dashboardAccessedEvents.length; } getDashboardErrorEventCount(): number { return this.dashboardErrorEvents.length; } getLeagueCreatedEventCount(): number { return this.leagueCreatedEvents.length; } getLeagueUpdatedEventCount(): number { return this.leagueUpdatedEvents.length; } getLeagueDeletedEventCount(): number { return this.leagueDeletedEvents.length; } getLeagueAccessedEventCount(): number { return this.leagueAccessedEvents.length; } getLeagueRosterAccessedEventCount(): number { return this.leagueRosterAccessedEvents.length; } getLeagueRosterAccessedEvents(): LeagueRosterAccessedEvent[] { return [...this.leagueRosterAccessedEvents]; } getLeagueCreatedEvents(): LeagueCreatedEvent[] { return [...this.leagueCreatedEvents]; } clear(): void { this.dashboardAccessedEvents = []; this.dashboardErrorEvents = []; this.leagueCreatedEvents = []; this.leagueUpdatedEvents = []; this.leagueDeletedEvents = []; this.leagueAccessedEvents = []; this.leagueRosterAccessedEvents = []; this.shouldFail = false; } setShouldFail(shouldFail: boolean): void { this.shouldFail = shouldFail; } }