Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
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
111 lines
3.5 KiB
TypeScript
111 lines
3.5 KiB
TypeScript
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<void> {
|
|
if (this.shouldFail) throw new Error('Event publisher failed');
|
|
this.dashboardAccessedEvents.push(event);
|
|
}
|
|
|
|
async publishDashboardError(event: DashboardErrorEvent): Promise<void> {
|
|
if (this.shouldFail) throw new Error('Event publisher failed');
|
|
this.dashboardErrorEvents.push(event);
|
|
}
|
|
|
|
async emitLeagueCreated(event: LeagueCreatedEvent): Promise<void> {
|
|
if (this.shouldFail) throw new Error('Event publisher failed');
|
|
this.leagueCreatedEvents.push(event);
|
|
}
|
|
|
|
async emitLeagueUpdated(event: LeagueUpdatedEvent): Promise<void> {
|
|
if (this.shouldFail) throw new Error('Event publisher failed');
|
|
this.leagueUpdatedEvents.push(event);
|
|
}
|
|
|
|
async emitLeagueDeleted(event: LeagueDeletedEvent): Promise<void> {
|
|
if (this.shouldFail) throw new Error('Event publisher failed');
|
|
this.leagueDeletedEvents.push(event);
|
|
}
|
|
|
|
async emitLeagueAccessed(event: LeagueAccessedEvent): Promise<void> {
|
|
if (this.shouldFail) throw new Error('Event publisher failed');
|
|
this.leagueAccessedEvents.push(event);
|
|
}
|
|
|
|
async emitLeagueRosterAccessed(event: LeagueRosterAccessedEvent): Promise<void> {
|
|
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;
|
|
}
|
|
}
|