inmemory to postgres
This commit is contained in:
@@ -6,9 +6,13 @@ import { SeasonSponsorship } from '@core/racing/domain/entities/season/SeasonSpo
|
||||
import type { Sponsor } from '@core/racing/domain/entities/sponsor/Sponsor';
|
||||
import type { SeasonStatusValue } from '@core/racing/domain/value-objects/SeasonStatus';
|
||||
import { Money } from '@core/racing/domain/value-objects/Money';
|
||||
import { seedId } from './SeedIdHelper';
|
||||
|
||||
export class RacingSeasonSponsorshipFactory {
|
||||
constructor(private readonly baseDate: Date) {}
|
||||
constructor(
|
||||
private readonly baseDate: Date,
|
||||
private readonly persistence: 'postgres' | 'inmemory' = 'inmemory',
|
||||
) {}
|
||||
|
||||
createSeasons(leagues: League[]): Season[] {
|
||||
const seasons: Season[] = [];
|
||||
@@ -16,10 +20,10 @@ export class RacingSeasonSponsorshipFactory {
|
||||
for (const league of leagues) {
|
||||
const leagueId = league.id.toString();
|
||||
|
||||
if (leagueId === 'league-5') {
|
||||
if (leagueId === seedId('league-5', this.persistence)) {
|
||||
seasons.push(
|
||||
Season.create({
|
||||
id: 'season-1',
|
||||
id: seedId('season-1', this.persistence),
|
||||
leagueId,
|
||||
gameId: 'iracing',
|
||||
name: 'Season 1 (GT Sprint)',
|
||||
@@ -29,7 +33,7 @@ export class RacingSeasonSponsorshipFactory {
|
||||
startDate: this.daysFromBase(-30),
|
||||
}),
|
||||
Season.create({
|
||||
id: 'season-2',
|
||||
id: seedId('season-2', this.persistence),
|
||||
leagueId,
|
||||
gameId: 'iracing',
|
||||
name: 'Season 2 (Endurance Cup)',
|
||||
@@ -40,7 +44,7 @@ export class RacingSeasonSponsorshipFactory {
|
||||
endDate: this.daysFromBase(-60),
|
||||
}),
|
||||
Season.create({
|
||||
id: 'season-3',
|
||||
id: seedId('season-3', this.persistence),
|
||||
leagueId,
|
||||
gameId: 'iracing',
|
||||
name: 'Season 3 (Planned)',
|
||||
@@ -53,10 +57,10 @@ export class RacingSeasonSponsorshipFactory {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (leagueId === 'league-3') {
|
||||
if (leagueId === seedId('league-3', this.persistence)) {
|
||||
seasons.push(
|
||||
Season.create({
|
||||
id: 'league-3-season-a',
|
||||
id: seedId('league-3-season-a', this.persistence),
|
||||
leagueId,
|
||||
gameId: 'iracing',
|
||||
name: 'Split Season A',
|
||||
@@ -66,7 +70,7 @@ export class RacingSeasonSponsorshipFactory {
|
||||
startDate: this.daysFromBase(-10),
|
||||
}),
|
||||
Season.create({
|
||||
id: 'league-3-season-b',
|
||||
id: seedId('league-3-season-b', this.persistence),
|
||||
leagueId,
|
||||
gameId: 'iracing',
|
||||
name: 'Split Season B',
|
||||
@@ -80,16 +84,16 @@ export class RacingSeasonSponsorshipFactory {
|
||||
}
|
||||
|
||||
const baseYear = this.baseDate.getUTCFullYear();
|
||||
const seasonCount = leagueId === 'league-2' ? 1 : faker.number.int({ min: 1, max: 3 });
|
||||
const seasonCount = leagueId === seedId('league-2', this.persistence) ? 1 : faker.number.int({ min: 1, max: 3 });
|
||||
|
||||
for (let i = 0; i < seasonCount; i++) {
|
||||
const id = `${leagueId}-season-${i + 1}`;
|
||||
const id = seedId(`${leagueId}-season-${i + 1}`, this.persistence);
|
||||
const isFirst = i === 0;
|
||||
|
||||
const status: SeasonStatusValue =
|
||||
leagueId === 'league-1' && isFirst
|
||||
leagueId === seedId('league-1', this.persistence) && isFirst
|
||||
? 'active'
|
||||
: leagueId === 'league-2'
|
||||
: leagueId === seedId('league-2', this.persistence)
|
||||
? 'planned'
|
||||
: isFirst
|
||||
? faker.helpers.arrayElement(['active', 'planned'] as const)
|
||||
@@ -131,8 +135,9 @@ export class RacingSeasonSponsorshipFactory {
|
||||
const sponsorIds = sponsors.map((s) => s.id.toString());
|
||||
|
||||
for (const season of seasons) {
|
||||
const expectedSeasonId = seedId('season-1', this.persistence);
|
||||
const sponsorshipCount =
|
||||
season.id === 'season-1'
|
||||
season.id === expectedSeasonId
|
||||
? 2
|
||||
: season.status.isActive()
|
||||
? faker.number.int({ min: 0, max: 2 })
|
||||
@@ -152,7 +157,7 @@ export class RacingSeasonSponsorshipFactory {
|
||||
usedSponsorIds.add(sponsorId);
|
||||
|
||||
const base = SeasonSponsorship.create({
|
||||
id: `season-sponsorship-${season.id}-${i + 1}`,
|
||||
id: seedId(`season-sponsorship-${season.id}-${i + 1}`, this.persistence),
|
||||
seasonId: season.id,
|
||||
leagueId: season.leagueId,
|
||||
sponsorId,
|
||||
@@ -190,7 +195,8 @@ export class RacingSeasonSponsorshipFactory {
|
||||
const sponsorIds = sponsors.map((s) => s.id.toString());
|
||||
|
||||
for (const season of seasons) {
|
||||
const isHighTrafficDemo = season.id === 'season-1';
|
||||
const expectedSeasonId = seedId('season-1', this.persistence);
|
||||
const isHighTrafficDemo = season.id === expectedSeasonId;
|
||||
const maxRequests =
|
||||
isHighTrafficDemo
|
||||
? 8
|
||||
@@ -204,7 +210,7 @@ export class RacingSeasonSponsorshipFactory {
|
||||
|
||||
const sponsorId =
|
||||
isHighTrafficDemo && i === 0
|
||||
? 'demo-sponsor-1'
|
||||
? seedId('demo-sponsor-1', this.persistence)
|
||||
: faker.helpers.arrayElement(sponsorIds);
|
||||
|
||||
const offeredAmount = Money.create(
|
||||
@@ -230,7 +236,7 @@ export class RacingSeasonSponsorshipFactory {
|
||||
|
||||
requests.push(
|
||||
SponsorshipRequest.create({
|
||||
id: `sponsorship-request-${season.id}-${i + 1}`,
|
||||
id: seedId(`sponsorship-request-${season.id}-${i + 1}`, this.persistence),
|
||||
sponsorId,
|
||||
entityType: 'season',
|
||||
entityId: season.id,
|
||||
|
||||
Reference in New Issue
Block a user