integration tests
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 4m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-22 17:29:06 +01:00
parent f61ebda9b7
commit 597bb48248
68 changed files with 11832 additions and 3498 deletions

View File

@@ -0,0 +1,70 @@
/**
* Infrastructure Adapter: InMemoryLeaderboardsEventPublisher
*
* In-memory implementation of LeaderboardsEventPublisher.
* Stores events in arrays for testing purposes.
*/
import {
LeaderboardsEventPublisher,
GlobalLeaderboardsAccessedEvent,
DriverRankingsAccessedEvent,
TeamRankingsAccessedEvent,
LeaderboardsErrorEvent,
} from '../../../core/leaderboards/application/ports/LeaderboardsEventPublisher';
export class InMemoryLeaderboardsEventPublisher implements LeaderboardsEventPublisher {
private globalLeaderboardsAccessedEvents: GlobalLeaderboardsAccessedEvent[] = [];
private driverRankingsAccessedEvents: DriverRankingsAccessedEvent[] = [];
private teamRankingsAccessedEvents: TeamRankingsAccessedEvent[] = [];
private leaderboardsErrorEvents: LeaderboardsErrorEvent[] = [];
private shouldFail: boolean = false;
async publishGlobalLeaderboardsAccessed(event: GlobalLeaderboardsAccessedEvent): Promise<void> {
if (this.shouldFail) throw new Error('Event publisher failed');
this.globalLeaderboardsAccessedEvents.push(event);
}
async publishDriverRankingsAccessed(event: DriverRankingsAccessedEvent): Promise<void> {
if (this.shouldFail) throw new Error('Event publisher failed');
this.driverRankingsAccessedEvents.push(event);
}
async publishTeamRankingsAccessed(event: TeamRankingsAccessedEvent): Promise<void> {
if (this.shouldFail) throw new Error('Event publisher failed');
this.teamRankingsAccessedEvents.push(event);
}
async publishLeaderboardsError(event: LeaderboardsErrorEvent): Promise<void> {
if (this.shouldFail) throw new Error('Event publisher failed');
this.leaderboardsErrorEvents.push(event);
}
getGlobalLeaderboardsAccessedEventCount(): number {
return this.globalLeaderboardsAccessedEvents.length;
}
getDriverRankingsAccessedEventCount(): number {
return this.driverRankingsAccessedEvents.length;
}
getTeamRankingsAccessedEventCount(): number {
return this.teamRankingsAccessedEvents.length;
}
getLeaderboardsErrorEventCount(): number {
return this.leaderboardsErrorEvents.length;
}
clear(): void {
this.globalLeaderboardsAccessedEvents = [];
this.driverRankingsAccessedEvents = [];
this.teamRankingsAccessedEvents = [];
this.leaderboardsErrorEvents = [];
this.shouldFail = false;
}
setShouldFail(shouldFail: boolean): void {
this.shouldFail = shouldFail;
}
}

View File

@@ -0,0 +1,44 @@
/**
* Infrastructure Adapter: InMemoryLeaderboardsRepository
*
* In-memory implementation of LeaderboardsRepository.
* Stores data in a Map structure.
*/
import {
LeaderboardsRepository,
LeaderboardDriverData,
LeaderboardTeamData,
} from '../../../../core/leaderboards/application/ports/LeaderboardsRepository';
export class InMemoryLeaderboardsRepository implements LeaderboardsRepository {
private drivers: Map<string, LeaderboardDriverData> = new Map();
private teams: Map<string, LeaderboardTeamData> = new Map();
async findAllDrivers(): Promise<LeaderboardDriverData[]> {
return Array.from(this.drivers.values());
}
async findAllTeams(): Promise<LeaderboardTeamData[]> {
return Array.from(this.teams.values());
}
async findDriversByTeamId(teamId: string): Promise<LeaderboardDriverData[]> {
return Array.from(this.drivers.values()).filter(
(driver) => driver.teamId === teamId,
);
}
addDriver(driver: LeaderboardDriverData): void {
this.drivers.set(driver.id, driver);
}
addTeam(team: LeaderboardTeamData): void {
this.teams.set(team.id, team);
}
clear(): void {
this.drivers.clear();
this.teams.clear();
}
}