integration 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

This commit is contained in:
2026-01-24 01:13:49 +01:00
parent 9bb6b228f1
commit 9ccecbf3bb
25 changed files with 895 additions and 2688 deletions

View File

@@ -51,6 +51,9 @@ export class RacingResultFactory {
? 2
: 3 + Math.floor(rng() * 6);
// Calculate points based on position
const points = this.calculatePoints(position);
results.push(
RaceResult.create({
id: seedId(`${race.id}:${driver.id}`, this.persistence),
@@ -60,6 +63,7 @@ export class RacingResultFactory {
startPosition: Math.max(1, startPosition),
fastestLap,
incidents,
points,
}),
);
}
@@ -96,4 +100,21 @@ export class RacingResultFactory {
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
private calculatePoints(position: number): number {
// Standard F1-style points system
const pointsMap: Record<number, number> = {
1: 25,
2: 18,
3: 15,
4: 12,
5: 10,
6: 8,
7: 6,
8: 4,
9: 2,
10: 1,
};
return pointsMap[position] || 0;
}
}

View File

@@ -11,8 +11,9 @@ import {
LeagueAccessedEvent,
LeagueRosterAccessedEvent,
} from '../../core/leagues/application/ports/LeagueEventPublisher';
import { EventPublisher, DomainEvent } from '../../core/shared/ports/EventPublisher';
export class InMemoryEventPublisher implements DashboardEventPublisher, LeagueEventPublisher {
export class InMemoryEventPublisher implements DashboardEventPublisher, LeagueEventPublisher, EventPublisher {
private dashboardAccessedEvents: DashboardAccessedEvent[] = [];
private dashboardErrorEvents: DashboardErrorEvent[] = [];
private leagueCreatedEvents: LeagueCreatedEvent[] = [];
@@ -20,6 +21,7 @@ export class InMemoryEventPublisher implements DashboardEventPublisher, LeagueEv
private leagueDeletedEvents: LeagueDeletedEvent[] = [];
private leagueAccessedEvents: LeagueAccessedEvent[] = [];
private leagueRosterAccessedEvents: LeagueRosterAccessedEvent[] = [];
private events: DomainEvent[] = [];
private shouldFail: boolean = false;
async publishDashboardAccessed(event: DashboardAccessedEvent): Promise<void> {
@@ -101,10 +103,20 @@ export class InMemoryEventPublisher implements DashboardEventPublisher, LeagueEv
this.leagueDeletedEvents = [];
this.leagueAccessedEvents = [];
this.leagueRosterAccessedEvents = [];
this.events = [];
this.shouldFail = false;
}
setShouldFail(shouldFail: boolean): void {
this.shouldFail = shouldFail;
}
async publish(event: DomainEvent): Promise<void> {
if (this.shouldFail) throw new Error('Event publisher failed');
this.events.push(event);
}
getEvents(): DomainEvent[] {
return [...this.events];
}
}

View File

@@ -128,8 +128,12 @@ export class InMemoryHealthCheckAdapter implements HealthCheckQuery {
// Update average response time
const total = this.health.successfulRequests;
this.health.averageResponseTime =
((this.health.averageResponseTime * (total - 1)) + responseTime) / total;
if (total === 1) {
this.health.averageResponseTime = responseTime;
} else {
this.health.averageResponseTime =
((this.health.averageResponseTime * (total - 1)) + responseTime) / total;
}
this.updateStatus();
}

View File

@@ -0,0 +1,38 @@
/**
* In-Memory Rating Repository
*
* In-memory implementation of RatingRepository for testing purposes.
*/
import { RatingRepository } from '../../../../core/rating/ports/RatingRepository';
import { Rating } from '../../../../core/rating/domain/Rating';
export class InMemoryRatingRepository implements RatingRepository {
private ratings: Map<string, Rating> = new Map();
async save(rating: Rating): Promise<void> {
const key = `${rating.driverId.toString()}-${rating.raceId.toString()}`;
this.ratings.set(key, rating);
}
async findByDriverAndRace(driverId: string, raceId: string): Promise<Rating | null> {
const key = `${driverId}-${raceId}`;
return this.ratings.get(key) || null;
}
async findByDriver(driverId: string): Promise<Rating[]> {
return Array.from(this.ratings.values()).filter(
rating => rating.driverId.toString() === driverId
);
}
async findByRace(raceId: string): Promise<Rating[]> {
return Array.from(this.ratings.values()).filter(
rating => rating.raceId.toString() === raceId
);
}
async clear(): Promise<void> {
this.ratings.clear();
}
}