Files
gridpilot.gg/adapters/bootstrap/racing/RacingDriverFactory.ts
2025-12-29 19:44:11 +01:00

28 lines
974 B
TypeScript

import { Driver } from '@core/racing/domain/entities/Driver';
import { faker } from '@faker-js/faker';
import { seedId } from './SeedIdHelper';
export class RacingDriverFactory {
constructor(
private readonly driverCount: number,
private readonly baseDate: Date,
private readonly persistence: 'postgres' | 'inmemory' = 'inmemory',
) {}
create(): Driver[] {
const countries = ['DE', 'NL', 'FR', 'GB', 'US', 'CA', 'SE', 'NO', 'IT', 'ES', 'AU', 'BR', 'JP', 'KR', 'RU', 'PL', 'CZ', 'HU', 'AT', 'CH'] as const;
return Array.from({ length: this.driverCount }, (_, idx) => {
const i = idx + 1;
return Driver.create({
id: seedId(`driver-${i}`, this.persistence),
iracingId: String(100000 + i),
name: faker.person.fullName(),
country: faker.helpers.arrayElement(countries),
bio: faker.lorem.sentences(2),
joinedAt: faker.date.past({ years: 2, refDate: this.baseDate }),
});
});
}
}