inmemory to postgres
This commit is contained in:
@@ -3,9 +3,13 @@ import { League } from '@core/racing/domain/entities/League';
|
||||
import { Team } from '@core/racing/domain/entities/Team';
|
||||
import type { TeamJoinRequest, TeamMembership } from '@core/racing/domain/types/TeamMembership';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { seedId } from './SeedIdHelper';
|
||||
|
||||
export class RacingTeamFactory {
|
||||
constructor(private readonly baseDate: Date) {}
|
||||
constructor(
|
||||
private readonly baseDate: Date,
|
||||
private readonly persistence: 'postgres' | 'inmemory' = 'inmemory',
|
||||
) {}
|
||||
|
||||
createTeams(drivers: Driver[], leagues: League[]): Team[] {
|
||||
const teamCount = 15;
|
||||
@@ -19,7 +23,7 @@ export class RacingTeamFactory {
|
||||
);
|
||||
|
||||
return Team.create({
|
||||
id: `team-${i}`,
|
||||
id: seedId(`team-${i}`, this.persistence),
|
||||
name: faker.company.name() + ' Racing',
|
||||
tag: faker.string.alpha({ length: 4, casing: 'upper' }),
|
||||
description: faker.lorem.sentences(2),
|
||||
@@ -128,7 +132,7 @@ export class RacingTeamFactory {
|
||||
|
||||
candidateDriverIds.forEach((driverId, idx) => {
|
||||
addRequest({
|
||||
id: `team-join-${team1.id.toString()}-${driverId}`,
|
||||
id: seedId(`team-join-${team1.id.toString()}-${driverId}`, this.persistence),
|
||||
teamId: team1.id.toString(),
|
||||
driverId,
|
||||
requestedAt: this.addDays(this.baseDate, -(5 + idx)),
|
||||
@@ -142,7 +146,7 @@ export class RacingTeamFactory {
|
||||
|
||||
// Conflict edge case: owner submits a join request to own team.
|
||||
addRequest({
|
||||
id: `team-join-${team1.id.toString()}-${team1.ownerId.toString()}-conflict`,
|
||||
id: seedId(`team-join-${team1.id.toString()}-${team1.ownerId.toString()}-conflict`, this.persistence),
|
||||
teamId: team1.id.toString(),
|
||||
driverId: team1.ownerId.toString(),
|
||||
requestedAt: this.addDays(this.baseDate, -1),
|
||||
@@ -154,7 +158,7 @@ export class RacingTeamFactory {
|
||||
if (team3 && drivers[0]) {
|
||||
const driverId = drivers[0].id.toString();
|
||||
addRequest({
|
||||
id: 'dup-team-join-req-1',
|
||||
id: seedId('dup-team-join-req-1', this.persistence),
|
||||
teamId: team3.id.toString(),
|
||||
driverId,
|
||||
requestedAt: this.addDays(this.baseDate, -10),
|
||||
@@ -162,7 +166,7 @@ export class RacingTeamFactory {
|
||||
});
|
||||
|
||||
addRequest({
|
||||
id: 'dup-team-join-req-1',
|
||||
id: seedId('dup-team-join-req-1', this.persistence),
|
||||
teamId: team3.id.toString(),
|
||||
driverId,
|
||||
requestedAt: this.addDays(this.baseDate, -9),
|
||||
|
||||
Reference in New Issue
Block a user