seed data
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { League } from '@core/racing/domain/entities/League';
|
||||
import { League, LeagueSettings } from '@core/racing/domain/entities/League';
|
||||
import { Driver } from '@core/racing/domain/entities/Driver';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { seedId } from './SeedIdHelper';
|
||||
@@ -11,7 +11,7 @@ export class RacingLeagueFactory {
|
||||
) {}
|
||||
|
||||
create(): League[] {
|
||||
const leagueCount = 30;
|
||||
const leagueCount = 120; // Expanded to 100+ leagues
|
||||
|
||||
// Create diverse league configurations covering ALL enum combinations
|
||||
// Points systems: f1-2024, indycar, custom (3)
|
||||
@@ -20,6 +20,8 @@ export class RacingLeagueFactory {
|
||||
// Decision modes: admin_only, steward_decides, steward_vote, member_vote, steward_veto, member_veto (6)
|
||||
// Total combinations: 3 * 2 * 2 * 6 = 72, but we'll sample 30 covering extremes
|
||||
|
||||
// Category types for leagues
|
||||
|
||||
const leagueConfigs = [
|
||||
// 1-5: Ranked, F1-2024, various stewarding
|
||||
{
|
||||
@@ -277,7 +279,8 @@ export class RacingLeagueFactory {
|
||||
return Array.from({ length: leagueCount }, (_, idx) => {
|
||||
const i = idx + 1;
|
||||
const owner = faker.helpers.arrayElement(this.drivers);
|
||||
const config = leagueConfigs[idx]!;
|
||||
// Cycle through the 30 configs for variety
|
||||
const config = leagueConfigs[idx % 30]!;
|
||||
|
||||
const createdAt =
|
||||
// Ensure some "New" leagues (created within 7 days) so `/leagues` featured categories are populated.
|
||||
@@ -310,33 +313,29 @@ export class RacingLeagueFactory {
|
||||
}
|
||||
}
|
||||
|
||||
const leagueData: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
ownerId: string;
|
||||
settings: {
|
||||
pointsSystem: 'f1-2024' | 'indycar' | 'custom';
|
||||
maxDrivers: number;
|
||||
sessionDuration: number;
|
||||
qualifyingFormat: 'open' | 'single-lap';
|
||||
visibility?: 'ranked' | 'unranked';
|
||||
stewarding?: {
|
||||
decisionMode: 'admin_only' | 'steward_decides' | 'steward_vote' | 'member_vote' | 'steward_veto' | 'member_veto';
|
||||
requiredVotes?: number;
|
||||
requireDefense?: boolean;
|
||||
defenseTimeLimit?: number;
|
||||
voteTimeLimit?: number;
|
||||
protestDeadlineHours?: number;
|
||||
stewardingClosesHours?: number;
|
||||
notifyAccusedOnProtest?: boolean;
|
||||
notifyOnVoteRequired?: boolean;
|
||||
};
|
||||
};
|
||||
createdAt: Date;
|
||||
socialLinks?: { discordUrl?: string; youtubeUrl?: string; websiteUrl?: string };
|
||||
participantCount?: number;
|
||||
} = {
|
||||
// Determine category based on scoring configuration
|
||||
let category: string | undefined;
|
||||
if (config.pointsSystem === 'f1-2024') {
|
||||
if (config.qualifyingFormat === 'single-lap') {
|
||||
category = 'driver';
|
||||
} else {
|
||||
category = 'team';
|
||||
}
|
||||
} else if (config.pointsSystem === 'indycar') {
|
||||
category = 'nations';
|
||||
} else if (config.pointsSystem === 'custom') {
|
||||
category = 'trophy';
|
||||
}
|
||||
|
||||
// Override some leagues to have endurance or sprint categories
|
||||
if (idx % 8 === 0) {
|
||||
category = 'endurance';
|
||||
} else if (idx % 7 === 0) {
|
||||
category = 'sprint';
|
||||
}
|
||||
|
||||
// Build the league data object
|
||||
const leagueData = {
|
||||
id: seedId(`league-${i}`, this.persistence),
|
||||
name: faker.company.name() + ' Racing League',
|
||||
description: faker.lorem.sentences(2),
|
||||
@@ -356,6 +355,7 @@ export class RacingLeagueFactory {
|
||||
notifyOnVoteRequired: true,
|
||||
},
|
||||
},
|
||||
category,
|
||||
createdAt,
|
||||
participantCount,
|
||||
};
|
||||
@@ -374,11 +374,37 @@ export class RacingLeagueFactory {
|
||||
if (type === 'website') socialLinks.websiteUrl = faker.internet.url();
|
||||
});
|
||||
|
||||
// Create the final league data with optional fields
|
||||
const finalLeagueData: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
ownerId: string;
|
||||
settings?: Partial<LeagueSettings>;
|
||||
category?: string | undefined;
|
||||
createdAt?: Date;
|
||||
socialLinks?: {
|
||||
discordUrl?: string;
|
||||
youtubeUrl?: string;
|
||||
websiteUrl?: string;
|
||||
};
|
||||
participantCount?: number;
|
||||
} = {
|
||||
id: leagueData.id,
|
||||
name: leagueData.name,
|
||||
description: leagueData.description,
|
||||
ownerId: leagueData.ownerId,
|
||||
settings: leagueData.settings,
|
||||
category: leagueData.category,
|
||||
createdAt: leagueData.createdAt,
|
||||
participantCount: leagueData.participantCount,
|
||||
};
|
||||
|
||||
if (Object.keys(socialLinks).length > 0) {
|
||||
leagueData.socialLinks = socialLinks;
|
||||
finalLeagueData.socialLinks = socialLinks;
|
||||
}
|
||||
|
||||
return League.create(leagueData);
|
||||
return League.create(finalLeagueData);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user