add tests
This commit is contained in:
39
adapters/events/InMemoryEventPublisher.ts
Normal file
39
adapters/events/InMemoryEventPublisher.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
DashboardEventPublisher,
|
||||
DashboardAccessedEvent,
|
||||
DashboardErrorEvent,
|
||||
} from '../../core/dashboard/application/ports/DashboardEventPublisher';
|
||||
|
||||
export class InMemoryEventPublisher implements DashboardEventPublisher {
|
||||
private dashboardAccessedEvents: DashboardAccessedEvent[] = [];
|
||||
private dashboardErrorEvents: DashboardErrorEvent[] = [];
|
||||
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);
|
||||
}
|
||||
|
||||
getDashboardAccessedEventCount(): number {
|
||||
return this.dashboardAccessedEvents.length;
|
||||
}
|
||||
|
||||
getDashboardErrorEventCount(): number {
|
||||
return this.dashboardErrorEvents.length;
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.dashboardAccessedEvents = [];
|
||||
this.dashboardErrorEvents = [];
|
||||
this.shouldFail = false;
|
||||
}
|
||||
|
||||
setShouldFail(shouldFail: boolean): void {
|
||||
this.shouldFail = shouldFail;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user