inmemory to postgres
This commit is contained in:
@@ -4,6 +4,7 @@ import type { LeagueMembership } from '@core/racing/domain/entities/LeagueMember
|
||||
import { Protest } from '@core/racing/domain/entities/Protest';
|
||||
import type { Race } from '@core/racing/domain/entities/Race';
|
||||
import { Penalty } from '@core/racing/domain/entities/penalty/Penalty';
|
||||
import { seedId } from './SeedIdHelper';
|
||||
|
||||
type StewardingSeed = {
|
||||
protests: Protest[];
|
||||
@@ -11,7 +12,10 @@ type StewardingSeed = {
|
||||
};
|
||||
|
||||
export class RacingStewardingFactory {
|
||||
constructor(private readonly baseDate: Date) {}
|
||||
constructor(
|
||||
private readonly baseDate: Date,
|
||||
private readonly persistence: 'postgres' | 'inmemory' = 'inmemory',
|
||||
) {}
|
||||
|
||||
create(races: Race[], drivers: Driver[], leagueMemberships: LeagueMembership[]): StewardingSeed {
|
||||
const protests: Protest[] = [];
|
||||
@@ -57,7 +61,7 @@ export class RacingStewardingFactory {
|
||||
if (firstRace) {
|
||||
protests.push(
|
||||
Protest.create({
|
||||
id: 'protest-1',
|
||||
id: seedId('protest-1', this.persistence),
|
||||
raceId: firstRace.id.toString(),
|
||||
protestingDriverId: protester,
|
||||
accusedDriverId: accused,
|
||||
@@ -76,7 +80,7 @@ export class RacingStewardingFactory {
|
||||
// No penalty yet (pending), but seed a direct steward warning on same race.
|
||||
penalties.push(
|
||||
Penalty.create({
|
||||
id: 'penalty-1',
|
||||
id: seedId('penalty-1', this.persistence),
|
||||
leagueId: 'league-5',
|
||||
raceId: firstRace.id.toString(),
|
||||
driverId: accused,
|
||||
@@ -94,7 +98,7 @@ export class RacingStewardingFactory {
|
||||
if (secondRace) {
|
||||
protests.push(
|
||||
Protest.create({
|
||||
id: 'protest-2',
|
||||
id: seedId('protest-2', this.persistence),
|
||||
raceId: secondRace.id.toString(),
|
||||
protestingDriverId: spare,
|
||||
accusedDriverId: accused,
|
||||
@@ -113,14 +117,14 @@ export class RacingStewardingFactory {
|
||||
// Under review penalty still pending (linked to protest)
|
||||
penalties.push(
|
||||
Penalty.create({
|
||||
id: 'penalty-2',
|
||||
id: seedId('penalty-2', this.persistence),
|
||||
leagueId: 'league-5',
|
||||
raceId: secondRace.id.toString(),
|
||||
driverId: accused,
|
||||
type: 'time_penalty',
|
||||
value: 10,
|
||||
reason: 'Unsafe rejoin (protest pending review)',
|
||||
protestId: 'protest-2',
|
||||
protestId: seedId('protest-2', this.persistence),
|
||||
issuedBy: steward,
|
||||
status: 'pending',
|
||||
issuedAt: faker.date.recent({ days: 10, refDate: this.baseDate }),
|
||||
@@ -131,7 +135,7 @@ export class RacingStewardingFactory {
|
||||
|
||||
if (thirdRace) {
|
||||
const upheld = Protest.create({
|
||||
id: 'protest-3',
|
||||
id: seedId('protest-3', this.persistence),
|
||||
raceId: thirdRace.id.toString(),
|
||||
protestingDriverId: protester,
|
||||
accusedDriverId: spare,
|
||||
@@ -151,7 +155,7 @@ export class RacingStewardingFactory {
|
||||
|
||||
penalties.push(
|
||||
Penalty.create({
|
||||
id: 'penalty-3',
|
||||
id: seedId('penalty-3', this.persistence),
|
||||
leagueId: 'league-5',
|
||||
raceId: thirdRace.id.toString(),
|
||||
driverId: spare,
|
||||
@@ -168,7 +172,7 @@ export class RacingStewardingFactory {
|
||||
);
|
||||
|
||||
const dismissed = Protest.create({
|
||||
id: 'protest-4',
|
||||
id: seedId('protest-4', this.persistence),
|
||||
raceId: thirdRace.id.toString(),
|
||||
protestingDriverId: accused,
|
||||
accusedDriverId: protester,
|
||||
@@ -210,7 +214,7 @@ export class RacingStewardingFactory {
|
||||
const status = faker.helpers.arrayElement(['awaiting_defense', 'withdrawn'] as const);
|
||||
|
||||
const protest = Protest.create({
|
||||
id: `protest-${leagueId}-${race.id.toString()}`,
|
||||
id: seedId(`protest-${leagueId}-${race.id.toString()}`, this.persistence),
|
||||
raceId: race.id.toString(),
|
||||
protestingDriverId: a,
|
||||
accusedDriverId: b,
|
||||
@@ -239,7 +243,7 @@ export class RacingStewardingFactory {
|
||||
// A non-protest-linked penalty can still exist for the same race.
|
||||
penalties.push(
|
||||
Penalty.create({
|
||||
id: `penalty-${leagueId}-${race.id.toString()}`,
|
||||
id: seedId(`penalty-${leagueId}-${race.id.toString()}`, this.persistence),
|
||||
leagueId,
|
||||
raceId: race.id.toString(),
|
||||
driverId: b,
|
||||
|
||||
Reference in New Issue
Block a user