wip
This commit is contained in:
13
testing/index.ts
Normal file
13
testing/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export * from './src/faker/faker';
|
||||
export * from './src/images/images';
|
||||
export * from './src/media/DemoAvatarGenerationAdapter';
|
||||
export * from './src/media/DemoFaceValidationAdapter';
|
||||
export * from './src/media/DemoImageServiceAdapter';
|
||||
export * from './src/media/InMemoryAvatarGenerationRepository';
|
||||
export * from './src/racing/RacingSeedCore';
|
||||
export * from './src/racing/RacingSponsorshipSeed';
|
||||
export * from './src/racing/RacingFeedSeed';
|
||||
export * from './src/racing/RacingStaticSeed';
|
||||
export * from './src/racing/DemoTracks';
|
||||
export * from './src/racing/DemoCars';
|
||||
export * from './src/racing/DemoDriverStats';
|
||||
7
testing/package.json
Normal file
7
testing/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "@gridpilot/testing",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"main": "./index.ts",
|
||||
"types": "./index.ts"
|
||||
}
|
||||
8
testing/src/faker/faker.ts
Normal file
8
testing/src/faker/faker.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { faker as baseFaker } from '@faker-js/faker';
|
||||
|
||||
const faker = baseFaker;
|
||||
|
||||
// Fixed seed so demo data is stable across builds
|
||||
faker.seed(20240317);
|
||||
|
||||
export { faker };
|
||||
68
testing/src/images/images.ts
Normal file
68
testing/src/images/images.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { faker } from '../faker/faker';
|
||||
|
||||
const DRIVER_AVATARS = [
|
||||
'/images/avatars/avatar-1.svg',
|
||||
'/images/avatars/avatar-2.svg',
|
||||
'/images/avatars/avatar-3.svg',
|
||||
'/images/avatars/avatar-4.svg',
|
||||
'/images/avatars/avatar-5.svg',
|
||||
'/images/avatars/avatar-6.svg',
|
||||
] as const;
|
||||
|
||||
const TEAM_LOGOS = [
|
||||
'/images/logos/team-1.svg',
|
||||
'/images/logos/team-2.svg',
|
||||
'/images/logos/team-3.svg',
|
||||
'/images/logos/team-4.svg',
|
||||
] as const;
|
||||
|
||||
const LEAGUE_BANNERS = [
|
||||
'/images/header.jpeg',
|
||||
'/images/ff1600.jpeg',
|
||||
'/images/lmp3.jpeg',
|
||||
'/images/porsche.jpeg',
|
||||
] as const;
|
||||
|
||||
function hashString(input: string): number {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < input.length; i += 1) {
|
||||
hash = (hash * 31 + input.charCodeAt(i)) | 0;
|
||||
}
|
||||
return Math.abs(hash);
|
||||
}
|
||||
|
||||
export function getDriverAvatar(driverId: string): string {
|
||||
const index = hashString(driverId) % DRIVER_AVATARS.length;
|
||||
const avatar = DRIVER_AVATARS[index] ?? DRIVER_AVATARS[0];
|
||||
return avatar;
|
||||
}
|
||||
|
||||
export function getTeamLogo(teamId: string): string {
|
||||
const index = hashString(teamId) % TEAM_LOGOS.length;
|
||||
const logo = TEAM_LOGOS[index] ?? TEAM_LOGOS[0];
|
||||
return logo;
|
||||
}
|
||||
|
||||
export function getLeagueBanner(leagueId: string): string {
|
||||
const index = hashString(leagueId) % LEAGUE_BANNERS.length;
|
||||
const banner = LEAGUE_BANNERS[index] ?? LEAGUE_BANNERS[0];
|
||||
return banner;
|
||||
}
|
||||
|
||||
export interface LeagueCoverImage {
|
||||
url: string;
|
||||
alt: string;
|
||||
}
|
||||
|
||||
export function getLeagueCoverImage(leagueId: string): LeagueCoverImage {
|
||||
const seed = hashString(leagueId);
|
||||
|
||||
faker.seed(seed);
|
||||
const alt = faker.lorem.words(3);
|
||||
|
||||
const url = `https://picsum.photos/seed/${seed}/1200/280?blur=2`;
|
||||
|
||||
return { url, alt };
|
||||
}
|
||||
|
||||
export { DRIVER_AVATARS, TEAM_LOGOS, LEAGUE_BANNERS };
|
||||
124
testing/src/media/DemoAvatarGenerationAdapter.ts
Normal file
124
testing/src/media/DemoAvatarGenerationAdapter.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import type {
|
||||
AvatarGenerationPort,
|
||||
AvatarGenerationOptions,
|
||||
AvatarGenerationResult,
|
||||
} from '@gridpilot/media';
|
||||
|
||||
/**
|
||||
* Demo implementation of AvatarGenerationPort.
|
||||
*
|
||||
* In production, this would use a real AI image generation API like:
|
||||
* - OpenAI DALL-E
|
||||
* - Midjourney API
|
||||
* - Stable Diffusion
|
||||
* - RunwayML
|
||||
*
|
||||
* For demo purposes, this returns placeholder avatar images.
|
||||
*/
|
||||
export class DemoAvatarGenerationAdapter implements AvatarGenerationPort {
|
||||
private readonly placeholderAvatars: Record<string, string[]> = {
|
||||
red: [
|
||||
'/images/avatars/generated/red-1.png',
|
||||
'/images/avatars/generated/red-2.png',
|
||||
'/images/avatars/generated/red-3.png',
|
||||
],
|
||||
blue: [
|
||||
'/images/avatars/generated/blue-1.png',
|
||||
'/images/avatars/generated/blue-2.png',
|
||||
'/images/avatars/generated/blue-3.png',
|
||||
],
|
||||
green: [
|
||||
'/images/avatars/generated/green-1.png',
|
||||
'/images/avatars/generated/green-2.png',
|
||||
'/images/avatars/generated/green-3.png',
|
||||
],
|
||||
yellow: [
|
||||
'/images/avatars/generated/yellow-1.png',
|
||||
'/images/avatars/generated/yellow-2.png',
|
||||
'/images/avatars/generated/yellow-3.png',
|
||||
],
|
||||
orange: [
|
||||
'/images/avatars/generated/orange-1.png',
|
||||
'/images/avatars/generated/orange-2.png',
|
||||
'/images/avatars/generated/orange-3.png',
|
||||
],
|
||||
purple: [
|
||||
'/images/avatars/generated/purple-1.png',
|
||||
'/images/avatars/generated/purple-2.png',
|
||||
'/images/avatars/generated/purple-3.png',
|
||||
],
|
||||
black: [
|
||||
'/images/avatars/generated/black-1.png',
|
||||
'/images/avatars/generated/black-2.png',
|
||||
'/images/avatars/generated/black-3.png',
|
||||
],
|
||||
white: [
|
||||
'/images/avatars/generated/white-1.png',
|
||||
'/images/avatars/generated/white-2.png',
|
||||
'/images/avatars/generated/white-3.png',
|
||||
],
|
||||
pink: [
|
||||
'/images/avatars/generated/pink-1.png',
|
||||
'/images/avatars/generated/pink-2.png',
|
||||
'/images/avatars/generated/pink-3.png',
|
||||
],
|
||||
cyan: [
|
||||
'/images/avatars/generated/cyan-1.png',
|
||||
'/images/avatars/generated/cyan-2.png',
|
||||
'/images/avatars/generated/cyan-3.png',
|
||||
],
|
||||
};
|
||||
|
||||
async generateAvatars(options: AvatarGenerationOptions): Promise<AvatarGenerationResult> {
|
||||
// Simulate AI processing time (1-3 seconds)
|
||||
await this.delay(1500 + Math.random() * 1500);
|
||||
|
||||
// Log what would be sent to the AI (for debugging)
|
||||
console.log('[DemoAvatarGeneration] Would generate with prompt:', options.prompt);
|
||||
console.log('[DemoAvatarGeneration] Suit color:', options.suitColor);
|
||||
console.log('[DemoAvatarGeneration] Style:', options.style);
|
||||
console.log('[DemoAvatarGeneration] Count:', options.count);
|
||||
|
||||
// For demo, return placeholder URLs based on suit color
|
||||
// In production, these would be actual AI-generated images
|
||||
const colorAvatars = this.getPlaceholderAvatars(options.suitColor) ?? [];
|
||||
|
||||
// Generate unique URLs with a hash to simulate different generations
|
||||
const hash = this.generateHash((options.facePhotoUrl ?? '') + Date.now());
|
||||
const avatars = colorAvatars.slice(0, options.count).map((baseUrl, index) => {
|
||||
// In demo mode, use dicebear or similar for generating varied avatars
|
||||
const seed = `${hash}-${options.suitColor}-${index}`;
|
||||
return {
|
||||
url: `https://api.dicebear.com/7.x/personas/svg?seed=${seed}&backgroundColor=transparent`,
|
||||
thumbnailUrl: `https://api.dicebear.com/7.x/personas/svg?seed=${seed}&backgroundColor=transparent&size=64`,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
avatars,
|
||||
};
|
||||
}
|
||||
|
||||
private delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
private getPlaceholderAvatars(color: string): string[] | undefined {
|
||||
const avatars = this.placeholderAvatars[color];
|
||||
if (!avatars || avatars.length === 0) {
|
||||
return this.placeholderAvatars.blue;
|
||||
}
|
||||
return avatars;
|
||||
}
|
||||
|
||||
private generateHash(input: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < input.length; i += 1) {
|
||||
const char = input.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + char;
|
||||
hash |= 0;
|
||||
}
|
||||
return Math.abs(hash).toString(36);
|
||||
}
|
||||
}
|
||||
62
testing/src/media/DemoFaceValidationAdapter.ts
Normal file
62
testing/src/media/DemoFaceValidationAdapter.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { FaceValidationPort, FaceValidationResult } from '@gridpilot/media';
|
||||
|
||||
/**
|
||||
* Demo implementation of FaceValidationPort.
|
||||
*
|
||||
* In production, this would use a real face detection API like:
|
||||
* - AWS Rekognition
|
||||
* - Google Cloud Vision
|
||||
* - Azure Face API
|
||||
* - OpenCV / face-api.js
|
||||
*
|
||||
* For demo purposes, this always returns a valid face if the image data is provided.
|
||||
*/
|
||||
export class DemoFaceValidationAdapter implements FaceValidationPort {
|
||||
async validateFacePhoto(imageData: string | Buffer): Promise<FaceValidationResult> {
|
||||
// Simulate some processing time
|
||||
await this.delay(500);
|
||||
|
||||
// Check if we have any image data
|
||||
const dataString = typeof imageData === 'string' ? imageData : imageData.toString();
|
||||
|
||||
if (!dataString || dataString.length < 100) {
|
||||
return {
|
||||
isValid: false,
|
||||
hasFace: false,
|
||||
faceCount: 0,
|
||||
confidence: 0,
|
||||
errorMessage: 'Invalid or empty image data',
|
||||
};
|
||||
}
|
||||
|
||||
// Check for valid base64 image data or data URL
|
||||
const isValidImage =
|
||||
dataString.startsWith('data:image/') ||
|
||||
dataString.startsWith('/9j/') || // JPEG magic bytes in base64
|
||||
dataString.startsWith('iVBOR') || // PNG magic bytes in base64
|
||||
dataString.length > 1000; // Assume long strings are valid image data
|
||||
|
||||
if (!isValidImage) {
|
||||
return {
|
||||
isValid: false,
|
||||
hasFace: false,
|
||||
faceCount: 0,
|
||||
confidence: 0,
|
||||
errorMessage: 'Please upload a valid image file (JPEG or PNG)',
|
||||
};
|
||||
}
|
||||
|
||||
// For demo: always return success with high confidence
|
||||
// In production, this would actually analyze the image
|
||||
return {
|
||||
isValid: true,
|
||||
hasFace: true,
|
||||
faceCount: 1,
|
||||
confidence: 0.95,
|
||||
};
|
||||
}
|
||||
|
||||
private delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
41
testing/src/media/DemoImageServiceAdapter.ts
Normal file
41
testing/src/media/DemoImageServiceAdapter.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { ImageServicePort } from '@gridpilot/media';
|
||||
|
||||
const MALE_DEFAULT_AVATAR = '/images/avatars/male-default-avatar.jpg';
|
||||
const FEMALE_DEFAULT_AVATAR = '/images/avatars/female-default-avatar.jpeg';
|
||||
|
||||
export class DemoImageServiceAdapter implements ImageServicePort {
|
||||
getDriverAvatar(driverId: string): string {
|
||||
const numericSuffixMatch = driverId.match(/(\d+)$/);
|
||||
if (numericSuffixMatch) {
|
||||
const numericSuffixString = numericSuffixMatch[1] ?? '';
|
||||
const numericSuffix = Number.parseInt(numericSuffixString, 10);
|
||||
return numericSuffix % 2 === 0 ? FEMALE_DEFAULT_AVATAR : MALE_DEFAULT_AVATAR;
|
||||
}
|
||||
|
||||
const seed = stableHash(driverId);
|
||||
return seed % 2 === 0 ? FEMALE_DEFAULT_AVATAR : MALE_DEFAULT_AVATAR;
|
||||
}
|
||||
|
||||
getTeamLogo(teamId: string): string {
|
||||
const seed = stableHash(teamId);
|
||||
return `https://picsum.photos/seed/team-${seed}/256/256`;
|
||||
}
|
||||
|
||||
getLeagueCover(leagueId: string): string {
|
||||
const seed = stableHash(leagueId);
|
||||
return `https://picsum.photos/seed/league-cover-${seed}/1200/280?blur=2`;
|
||||
}
|
||||
|
||||
getLeagueLogo(leagueId: string): string {
|
||||
const seed = stableHash(leagueId);
|
||||
return `https://picsum.photos/seed/league-logo-${seed}/160/160`;
|
||||
}
|
||||
}
|
||||
|
||||
function stableHash(value: string): number {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < value.length; i += 1) {
|
||||
hash = (hash * 31 + value.charCodeAt(i)) | 0;
|
||||
}
|
||||
return Math.abs(hash);
|
||||
}
|
||||
78
testing/src/media/InMemoryAvatarGenerationRepository.ts
Normal file
78
testing/src/media/InMemoryAvatarGenerationRepository.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import type {
|
||||
IAvatarGenerationRepository,
|
||||
} from '@gridpilot/media';
|
||||
import {
|
||||
AvatarGenerationRequest,
|
||||
type AvatarGenerationRequestProps,
|
||||
} from '@gridpilot/media';
|
||||
import { ILogger } from '@gridpilot/shared/logging/ILogger';
|
||||
|
||||
/**
|
||||
* In-memory implementation of IAvatarGenerationRepository.
|
||||
*
|
||||
* For demo/development purposes. In production, this would use a database.
|
||||
*/
|
||||
export class InMemoryAvatarGenerationRepository implements IAvatarGenerationRepository {
|
||||
private readonly requests = new Map<string, AvatarGenerationRequestProps>();
|
||||
private readonly logger: ILogger;
|
||||
|
||||
constructor(logger: ILogger) {
|
||||
this.logger = logger;
|
||||
this.logger.info('InMemoryAvatarGenerationRepository initialized.');
|
||||
}
|
||||
|
||||
async save(request: AvatarGenerationRequest): Promise<void> {
|
||||
this.logger.debug(`Saving avatar generation request with ID: ${request.id}`);
|
||||
this.requests.set(request.id, request.toProps());
|
||||
this.logger.info(`Avatar generation request with ID: ${request.id} saved successfully.`);
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<AvatarGenerationRequest | null> {
|
||||
this.logger.debug(`Finding avatar generation request by ID: ${id}`);
|
||||
const props = this.requests.get(id);
|
||||
if (!props) {
|
||||
this.logger.info(`Avatar generation request with ID: ${id} not found.`);
|
||||
return null;
|
||||
}
|
||||
this.logger.info(`Avatar generation request with ID: ${id} found.`);
|
||||
return AvatarGenerationRequest.reconstitute(props);
|
||||
}
|
||||
|
||||
async findByUserId(userId: string): Promise<AvatarGenerationRequest[]> {
|
||||
this.logger.debug(`Finding avatar generation requests by user ID: ${userId}`);
|
||||
const results: AvatarGenerationRequest[] = [];
|
||||
for (const props of this.requests.values()) {
|
||||
if (props.userId === userId) {
|
||||
results.push(AvatarGenerationRequest.reconstitute(props));
|
||||
}
|
||||
}
|
||||
this.logger.info(`${results.length} avatar generation requests found for user ID: ${userId}.`);
|
||||
return results.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
||||
}
|
||||
|
||||
async findLatestByUserId(userId: string): Promise<AvatarGenerationRequest | null> {
|
||||
this.logger.debug(`Finding latest avatar generation request for user ID: ${userId}`);
|
||||
const userRequests = await this.findByUserId(userId);
|
||||
if (userRequests.length === 0) {
|
||||
this.logger.info(`No avatar generation requests found for user ID: ${userId}.`);
|
||||
return null;
|
||||
}
|
||||
const latest = userRequests[0];
|
||||
if (!latest) {
|
||||
this.logger.info(`No latest avatar generation request found for user ID: ${userId}.`);
|
||||
return null;
|
||||
}
|
||||
this.logger.info(`Latest avatar generation request found for user ID: ${userId}, ID: ${latest.id}.`);
|
||||
return latest;
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
this.logger.debug(`Deleting avatar generation request with ID: ${id}`);
|
||||
const deleted = this.requests.delete(id);
|
||||
if (deleted) {
|
||||
this.logger.info(`Avatar generation request with ID: ${id} deleted successfully.`);
|
||||
} else {
|
||||
this.logger.warn(`Attempted to delete non-existent avatar generation request with ID: ${id}.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
93
testing/src/racing/DemoCars.ts
Normal file
93
testing/src/racing/DemoCars.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { Car } from '@gridpilot/racing/domain/entities/Car';
|
||||
|
||||
/**
|
||||
* Demo car data for iRacing.
|
||||
* Extracted from the legacy DemoData module so that cars
|
||||
* live in their own focused file.
|
||||
*/
|
||||
export const DEMO_CARS: Car[] = [
|
||||
Car.create({
|
||||
id: 'car-porsche-992',
|
||||
name: '911 GT3 R',
|
||||
shortName: '992 GT3R',
|
||||
manufacturer: 'Porsche',
|
||||
carClass: 'gt',
|
||||
license: 'B',
|
||||
year: 2023,
|
||||
horsepower: 565,
|
||||
weight: 1300,
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Car.create({
|
||||
id: 'car-ferrari-296',
|
||||
name: '296 GT3',
|
||||
shortName: '296 GT3',
|
||||
manufacturer: 'Ferrari',
|
||||
carClass: 'gt',
|
||||
license: 'B',
|
||||
year: 2023,
|
||||
horsepower: 600,
|
||||
weight: 1270,
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Car.create({
|
||||
id: 'car-mclaren-720s',
|
||||
name: '720S GT3 Evo',
|
||||
shortName: '720S',
|
||||
manufacturer: 'McLaren',
|
||||
carClass: 'gt',
|
||||
license: 'B',
|
||||
year: 2023,
|
||||
horsepower: 552,
|
||||
weight: 1290,
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Car.create({
|
||||
id: 'car-mercedes-gt3',
|
||||
name: 'AMG GT3 2020',
|
||||
shortName: 'AMG GT3',
|
||||
manufacturer: 'Mercedes',
|
||||
carClass: 'gt',
|
||||
license: 'B',
|
||||
year: 2020,
|
||||
horsepower: 550,
|
||||
weight: 1285,
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Car.create({
|
||||
id: 'car-lmp2',
|
||||
name: 'Dallara P217 LMP2',
|
||||
shortName: 'LMP2',
|
||||
manufacturer: 'Dallara',
|
||||
carClass: 'prototype',
|
||||
license: 'A',
|
||||
year: 2021,
|
||||
horsepower: 600,
|
||||
weight: 930,
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Car.create({
|
||||
id: 'car-f4',
|
||||
name: 'Formula 4',
|
||||
shortName: 'F4',
|
||||
manufacturer: 'Tatuus',
|
||||
carClass: 'formula',
|
||||
license: 'D',
|
||||
year: 2022,
|
||||
horsepower: 160,
|
||||
weight: 570,
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Car.create({
|
||||
id: 'car-mx5',
|
||||
name: 'MX-5 Cup',
|
||||
shortName: 'MX5',
|
||||
manufacturer: 'Mazda',
|
||||
carClass: 'sports',
|
||||
license: 'D',
|
||||
year: 2023,
|
||||
horsepower: 181,
|
||||
weight: 1128,
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
];
|
||||
75
testing/src/racing/DemoDriverStats.ts
Normal file
75
testing/src/racing/DemoDriverStats.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Driver statistics and ranking data used for demo seeding.
|
||||
* Split out from the legacy DemoData module to keep responsibilities focused.
|
||||
*/
|
||||
export interface DriverStats {
|
||||
driverId: string;
|
||||
rating: number;
|
||||
totalRaces: number;
|
||||
wins: number;
|
||||
podiums: number;
|
||||
dnfs: number;
|
||||
avgFinish: number;
|
||||
bestFinish: number;
|
||||
worstFinish: number;
|
||||
consistency: number;
|
||||
overallRank: number;
|
||||
percentile: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create demo driver statistics based on seed data.
|
||||
* This is deterministic for a given driver ordering so it can be reused
|
||||
* by any in-memory repository wiring.
|
||||
*/
|
||||
export function createDemoDriverStats(drivers: Array<{ id: string }>): Record<string, DriverStats> {
|
||||
const stats: Record<string, DriverStats> = {};
|
||||
|
||||
drivers.forEach((driver, index) => {
|
||||
const totalRaces = 40 + index * 5;
|
||||
const wins = Math.max(0, Math.floor(totalRaces * 0.2) - index);
|
||||
const podiums = Math.max(wins * 2, 0);
|
||||
const dnfs = Math.max(0, Math.floor(index / 2));
|
||||
const rating = 1500 + index * 25;
|
||||
|
||||
stats[driver.id] = {
|
||||
driverId: driver.id,
|
||||
rating,
|
||||
totalRaces,
|
||||
wins,
|
||||
podiums,
|
||||
dnfs,
|
||||
avgFinish: 4,
|
||||
bestFinish: 1,
|
||||
worstFinish: 20,
|
||||
consistency: 80,
|
||||
overallRank: index + 1,
|
||||
percentile: Math.max(0, 100 - index),
|
||||
};
|
||||
});
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get league-specific rankings for a driver (demo implementation).
|
||||
* In production this would be calculated from actual league membership
|
||||
* and results; here we keep a very small static example for UI wiring.
|
||||
*/
|
||||
export function getDemoLeagueRankings(driverId: string, leagueId: string): {
|
||||
rank: number;
|
||||
totalDrivers: number;
|
||||
percentile: number;
|
||||
} {
|
||||
// Mock league rankings (in production, calculate from actual league membership)
|
||||
const mockLeagueRanks: Record<string, Record<string, any>> = {
|
||||
'league-1': {
|
||||
'driver-1': { rank: 1, totalDrivers: 12, percentile: 92 },
|
||||
'driver-2': { rank: 2, totalDrivers: 12, percentile: 84 },
|
||||
'driver-3': { rank: 4, totalDrivers: 12, percentile: 67 },
|
||||
'driver-4': { rank: 5, totalDrivers: 12, percentile: 58 },
|
||||
},
|
||||
};
|
||||
|
||||
return mockLeagueRanks[leagueId]?.[driverId] || { rank: 0, totalDrivers: 0, percentile: 0 };
|
||||
}
|
||||
93
testing/src/racing/DemoTracks.ts
Normal file
93
testing/src/racing/DemoTracks.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { Track } from '@gridpilot/racing/domain/entities/Track';
|
||||
|
||||
/**
|
||||
* Demo track data for iRacing.
|
||||
* Extracted from the legacy DemoData module so that tracks
|
||||
* live in their own focused file.
|
||||
*/
|
||||
export const DEMO_TRACKS: Track[] = [
|
||||
Track.create({
|
||||
id: 'track-spa',
|
||||
name: 'Spa-Francorchamps',
|
||||
shortName: 'SPA',
|
||||
country: 'Belgium',
|
||||
category: 'road',
|
||||
difficulty: 'advanced',
|
||||
lengthKm: 7.004,
|
||||
turns: 19,
|
||||
imageUrl: '/images/tracks/spa.jpg',
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Track.create({
|
||||
id: 'track-monza',
|
||||
name: 'Autodromo Nazionale Monza',
|
||||
shortName: 'MON',
|
||||
country: 'Italy',
|
||||
category: 'road',
|
||||
difficulty: 'intermediate',
|
||||
lengthKm: 5.793,
|
||||
turns: 11,
|
||||
imageUrl: '/images/tracks/monza.jpg',
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Track.create({
|
||||
id: 'track-nurburgring',
|
||||
name: 'Nürburgring Grand Prix',
|
||||
shortName: 'NUR',
|
||||
country: 'Germany',
|
||||
category: 'road',
|
||||
difficulty: 'advanced',
|
||||
lengthKm: 5.148,
|
||||
turns: 15,
|
||||
imageUrl: '/images/tracks/nurburgring.jpg',
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Track.create({
|
||||
id: 'track-silverstone',
|
||||
name: 'Silverstone Circuit',
|
||||
shortName: 'SIL',
|
||||
country: 'United Kingdom',
|
||||
category: 'road',
|
||||
difficulty: 'intermediate',
|
||||
lengthKm: 5.891,
|
||||
turns: 18,
|
||||
imageUrl: '/images/tracks/silverstone.jpg',
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Track.create({
|
||||
id: 'track-suzuka',
|
||||
name: 'Suzuka International Racing Course',
|
||||
shortName: 'SUZ',
|
||||
country: 'Japan',
|
||||
category: 'road',
|
||||
difficulty: 'expert',
|
||||
lengthKm: 5.807,
|
||||
turns: 18,
|
||||
imageUrl: '/images/tracks/suzuka.jpg',
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Track.create({
|
||||
id: 'track-daytona',
|
||||
name: 'Daytona International Speedway',
|
||||
shortName: 'DAY',
|
||||
country: 'United States',
|
||||
category: 'oval',
|
||||
difficulty: 'intermediate',
|
||||
lengthKm: 4.023,
|
||||
turns: 4,
|
||||
imageUrl: '/images/tracks/daytona.jpg',
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
Track.create({
|
||||
id: 'track-laguna',
|
||||
name: 'WeatherTech Raceway Laguna Seca',
|
||||
shortName: 'LAG',
|
||||
country: 'United States',
|
||||
category: 'road',
|
||||
difficulty: 'advanced',
|
||||
lengthKm: 3.602,
|
||||
turns: 11,
|
||||
imageUrl: '/images/tracks/laguna.jpg',
|
||||
gameId: 'iracing',
|
||||
}),
|
||||
];
|
||||
292
testing/src/racing/RacingFeedSeed.ts
Normal file
292
testing/src/racing/RacingFeedSeed.ts
Normal file
@@ -0,0 +1,292 @@
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
import { League } from '@gridpilot/racing/domain/entities/League';
|
||||
import { Race } from '@gridpilot/racing/domain/entities/Race';
|
||||
import type { Result } from '@gridpilot/racing/domain/entities/Result';
|
||||
import type { FeedItem } from '@gridpilot/social/domain/types/FeedItem';
|
||||
import type { FriendDTO } from '@gridpilot/social/application/dto/FriendDTO';
|
||||
import { faker } from '../faker/faker';
|
||||
import { getLeagueBanner, getDriverAvatar } from '../images/images';
|
||||
import type { Friendship, RacingMembership } from './RacingSeedCore';
|
||||
|
||||
/**
|
||||
* Feed events and derived racing demo data.
|
||||
* Extracted from the legacy StaticRacingSeed module to keep files smaller.
|
||||
*/
|
||||
export function createFeedEvents(
|
||||
drivers: Driver[],
|
||||
leagues: League[],
|
||||
races: Race[],
|
||||
friendships: Friendship[],
|
||||
): FeedItem[] {
|
||||
const events: FeedItem[] = [];
|
||||
const now = new Date();
|
||||
const completedRaces = races.filter((race) => race.status === 'completed');
|
||||
|
||||
// Focus the global feed around a stable “core” of demo drivers
|
||||
const coreDrivers = faker.helpers.shuffle(drivers).slice(0, Math.min(16, drivers.length));
|
||||
|
||||
coreDrivers.forEach((driver, index) => {
|
||||
const league = pickOne(leagues);
|
||||
const raceSource = completedRaces.length > 0 ? completedRaces : races;
|
||||
const race = pickOne(raceSource);
|
||||
const minutesAgo = 10 + index * 5;
|
||||
const baseTimestamp = new Date(now.getTime() - minutesAgo * 60 * 1000);
|
||||
|
||||
const actorFriendId = driver.id;
|
||||
|
||||
// Joined league
|
||||
events.push({
|
||||
id: `friend-joined-league:${driver.id}:${minutesAgo}`,
|
||||
type: 'friend-joined-league',
|
||||
timestamp: baseTimestamp,
|
||||
actorDriverId: driver.id,
|
||||
actorFriendId,
|
||||
leagueId: league.id,
|
||||
headline: `${driver.name} joined ${league.name}`,
|
||||
body: 'They are now registered for the full season.',
|
||||
ctaLabel: 'View league',
|
||||
ctaHref: `/leagues/${league.id}`,
|
||||
});
|
||||
|
||||
// Finished race / podium highlight
|
||||
const finishingPosition = (index % 5) + 1;
|
||||
events.push({
|
||||
id: `friend-finished-race:${driver.id}:${minutesAgo}`,
|
||||
type: 'friend-finished-race',
|
||||
timestamp: new Date(baseTimestamp.getTime() - 8 * 60 * 1000),
|
||||
actorDriverId: driver.id,
|
||||
actorFriendId,
|
||||
leagueId: race.leagueId,
|
||||
raceId: race.id,
|
||||
position: finishingPosition,
|
||||
headline: `${driver.name} finished P${finishingPosition} at ${race.track}`,
|
||||
body:
|
||||
finishingPosition <= 3
|
||||
? `${driver.name} scored a podium in ${race.car}.`
|
||||
: `${driver.name} secured a strong result in ${race.car}.`,
|
||||
ctaLabel: 'View results',
|
||||
ctaHref: `/races/${race.id}/results`,
|
||||
});
|
||||
|
||||
// New personal best
|
||||
events.push({
|
||||
id: `friend-new-personal-best:${driver.id}:${minutesAgo}`,
|
||||
type: 'friend-new-personal-best',
|
||||
timestamp: new Date(baseTimestamp.getTime() - 20 * 60 * 1000),
|
||||
actorDriverId: driver.id,
|
||||
actorFriendId,
|
||||
leagueId: race.leagueId,
|
||||
raceId: race.id,
|
||||
headline: `${driver.name} set a new personal best at ${race.track}`,
|
||||
body: 'Consistency and pace are trending up this season.',
|
||||
ctaLabel: 'View lap chart',
|
||||
ctaHref: `/races/${race.id}/analysis`,
|
||||
});
|
||||
|
||||
// Joined team (where applicable)
|
||||
const driverFriendships = friendships.filter((f) => f.driverId === driver.id);
|
||||
if (driverFriendships.length > 0) {
|
||||
const friend = pickOne(driverFriendships);
|
||||
const teammate = drivers.find((d) => d.id === friend.friendId);
|
||||
if (teammate) {
|
||||
events.push({
|
||||
id: `friend-joined-team:${driver.id}:${minutesAgo}`,
|
||||
type: 'friend-joined-team',
|
||||
timestamp: new Date(baseTimestamp.getTime() - 30 * 60 * 1000),
|
||||
actorDriverId: driver.id,
|
||||
actorFriendId,
|
||||
headline: `${driver.name} and ${teammate.name} are now teammates`,
|
||||
body: 'They will be sharing strategy and setups this season.',
|
||||
ctaLabel: 'View team',
|
||||
ctaHref: '/teams',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// League highlight
|
||||
events.push({
|
||||
id: `league-highlight:${league.id}:${minutesAgo}`,
|
||||
type: 'league-highlight',
|
||||
timestamp: new Date(baseTimestamp.getTime() - 45 * 60 * 1000),
|
||||
leagueId: league.id,
|
||||
headline: `${league.name} active with ${drivers.length}+ drivers`,
|
||||
body: 'Participation is growing. Perfect time to join the grid.',
|
||||
ctaLabel: 'Explore league',
|
||||
ctaHref: `/leagues/${league.id}`,
|
||||
});
|
||||
});
|
||||
|
||||
// Global “system” events: new race scheduled and results posted
|
||||
const upcomingRaces = races.filter((race) => race.status === 'scheduled').slice(0, 8);
|
||||
upcomingRaces.forEach((race, index) => {
|
||||
const minutesAgo = 60 + index * 15;
|
||||
const timestamp = new Date(now.getTime() - minutesAgo * 60 * 1000);
|
||||
events.push({
|
||||
id: `new-race-scheduled:${race.id}`,
|
||||
type: 'new-race-scheduled',
|
||||
timestamp,
|
||||
leagueId: race.leagueId,
|
||||
raceId: race.id,
|
||||
headline: `New race scheduled at ${race.track}`,
|
||||
body: `${race.car} • ${race.scheduledAt.toLocaleString()}`,
|
||||
ctaLabel: 'View schedule',
|
||||
ctaHref: `/races/${race.id}`,
|
||||
});
|
||||
});
|
||||
|
||||
const completedForResults = completedRaces.slice(0, 8);
|
||||
completedForResults.forEach((race, index) => {
|
||||
const minutesAgo = 180 + index * 20;
|
||||
const timestamp = new Date(now.getTime() - minutesAgo * 60 * 1000);
|
||||
events.push({
|
||||
id: `new-result-posted:${race.id}`,
|
||||
type: 'new-result-posted',
|
||||
timestamp,
|
||||
leagueId: race.leagueId,
|
||||
raceId: race.id,
|
||||
headline: `Results posted for ${race.track}`,
|
||||
body: 'Standings and stats updated across the grid.',
|
||||
ctaLabel: 'View classification',
|
||||
ctaHref: `/races/${race.id}/results`,
|
||||
});
|
||||
});
|
||||
|
||||
const sorted = events
|
||||
.slice()
|
||||
.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());
|
||||
|
||||
return sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived friend DTOs for UI consumption.
|
||||
* This preserves the previous demo-data `friends` shape while
|
||||
* keeping generation logic separate from the main seed.
|
||||
*/
|
||||
export function buildFriends(
|
||||
drivers: Driver[],
|
||||
memberships: RacingMembership[],
|
||||
): FriendDTO[] {
|
||||
return drivers.map((driver) => {
|
||||
const membership = memberships.find((m) => m.driverId === driver.id);
|
||||
|
||||
const base: FriendDTO = {
|
||||
driverId: driver.id,
|
||||
displayName: driver.name,
|
||||
avatarUrl: getDriverAvatar(driver.id),
|
||||
isOnline: true,
|
||||
lastSeen: new Date(),
|
||||
};
|
||||
|
||||
const withLeague =
|
||||
membership?.leagueId !== undefined
|
||||
? { ...base, primaryLeagueId: membership.leagueId }
|
||||
: base;
|
||||
|
||||
const withTeam =
|
||||
membership?.teamId !== undefined
|
||||
? { ...withLeague, primaryTeamId: membership.teamId }
|
||||
: withLeague;
|
||||
|
||||
return withTeam;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Build top leagues with banner URLs for UI.
|
||||
*/
|
||||
export type LeagueWithBannerDTO = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
ownerId: string;
|
||||
settings: League['settings'];
|
||||
createdAt: Date;
|
||||
socialLinks: League['socialLinks'];
|
||||
bannerUrl: string;
|
||||
};
|
||||
|
||||
export function buildTopLeagues(leagues: League[]): LeagueWithBannerDTO[] {
|
||||
return leagues.map((league) => ({
|
||||
id: league.id,
|
||||
name: league.name,
|
||||
description: league.description,
|
||||
ownerId: league.ownerId,
|
||||
settings: league.settings,
|
||||
createdAt: league.createdAt,
|
||||
socialLinks: league.socialLinks,
|
||||
bannerUrl: getLeagueBanner(league.id),
|
||||
}));
|
||||
}
|
||||
|
||||
export type RaceWithResultsDTO = {
|
||||
raceId: string;
|
||||
track: string;
|
||||
car: string;
|
||||
scheduledAt: Date;
|
||||
winnerDriverId: string;
|
||||
winnerName: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility to get upcoming races from a given race list.
|
||||
*/
|
||||
export function buildUpcomingRaces(
|
||||
races: Race[],
|
||||
limit?: number,
|
||||
): readonly Race[] {
|
||||
const upcoming = races.filter((race) => race.status === 'scheduled');
|
||||
const sorted = upcoming
|
||||
.slice()
|
||||
.sort((a, b) => a.scheduledAt.getTime() - b.scheduledAt.getTime());
|
||||
return typeof limit === 'number' ? sorted.slice(0, limit) : sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to get latest race results from races + results + drivers.
|
||||
*/
|
||||
export function buildLatestResults(
|
||||
races: Race[],
|
||||
results: Result[],
|
||||
drivers: Driver[],
|
||||
limit?: number,
|
||||
): readonly RaceWithResultsDTO[] {
|
||||
const completedRaces = races.filter((race) => race.status === 'completed');
|
||||
|
||||
const joined = completedRaces.map((race) => {
|
||||
const raceResults = results
|
||||
.filter((result) => result.raceId === race.id)
|
||||
.slice()
|
||||
.sort((a, b) => a.position - b.position);
|
||||
const winner = raceResults[0];
|
||||
const winnerDriver =
|
||||
winner && drivers.find((driver) => driver.id === winner.driverId);
|
||||
|
||||
return {
|
||||
raceId: race.id,
|
||||
track: race.track,
|
||||
car: race.car,
|
||||
scheduledAt: race.scheduledAt,
|
||||
winnerDriverId: winner?.driverId ?? '',
|
||||
winnerName: winnerDriver?.name ?? 'Winner',
|
||||
};
|
||||
});
|
||||
|
||||
const sorted = joined
|
||||
.slice()
|
||||
.sort((a, b) => b.scheduledAt.getTime() - a.scheduledAt.getTime());
|
||||
|
||||
return typeof limit === 'number' ? sorted.slice(0, limit) : sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local helper: random pick from an array.
|
||||
* Kept here to avoid importing from core in callers that only care about feed.
|
||||
*/
|
||||
function pickOne<T>(items: readonly T[]): T {
|
||||
if (items.length === 0) {
|
||||
throw new Error('pickOne: empty items array');
|
||||
}
|
||||
const index = faker.number.int({ min: 0, max: items.length - 1 });
|
||||
return items[index]!;
|
||||
}
|
||||
408
testing/src/racing/RacingSeedCore.ts
Normal file
408
testing/src/racing/RacingSeedCore.ts
Normal file
@@ -0,0 +1,408 @@
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
import { League } from '@gridpilot/racing/domain/entities/League';
|
||||
import { Race } from '@gridpilot/racing/domain/entities/Race';
|
||||
import { Result } from '@gridpilot/racing/domain/entities/Result';
|
||||
import { Standing } from '@gridpilot/racing/domain/entities/Standing';
|
||||
import { faker } from '../faker/faker';
|
||||
|
||||
/**
|
||||
* Core racing seed types and generators (drivers, leagues, teams, races, standings).
|
||||
* Extracted from the legacy StaticRacingSeed module to keep files smaller and focused.
|
||||
*/
|
||||
export type RacingMembership = {
|
||||
driverId: string;
|
||||
leagueId: string;
|
||||
teamId?: string;
|
||||
};
|
||||
|
||||
export type Friendship = {
|
||||
driverId: string;
|
||||
friendId: string;
|
||||
};
|
||||
|
||||
export interface DemoTeamDTO {
|
||||
id: string;
|
||||
name: string;
|
||||
tag: string;
|
||||
description: string;
|
||||
logoUrl: string;
|
||||
primaryLeagueId: string;
|
||||
memberCount: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Championship points table used when aggregating standings.
|
||||
*/
|
||||
export const POINTS_TABLE: Record<number, number> = {
|
||||
1: 25,
|
||||
2: 18,
|
||||
3: 15,
|
||||
4: 12,
|
||||
5: 10,
|
||||
6: 8,
|
||||
7: 6,
|
||||
8: 4,
|
||||
9: 2,
|
||||
10: 1,
|
||||
};
|
||||
|
||||
export function pickOne<T>(items: readonly T[]): T {
|
||||
if (items.length === 0) {
|
||||
throw new Error('pickOne: empty items array');
|
||||
}
|
||||
const index = faker.number.int({ min: 0, max: items.length - 1 });
|
||||
return items[index]!;
|
||||
}
|
||||
|
||||
export function createDrivers(count: number): Driver[] {
|
||||
const drivers: Driver[] = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const id = `driver-${i + 1}`;
|
||||
const name = faker.person.fullName();
|
||||
const country = faker.location.countryCode('alpha-2');
|
||||
const iracingId = faker.string.numeric(6);
|
||||
|
||||
drivers.push(
|
||||
Driver.create({
|
||||
id,
|
||||
iracingId,
|
||||
name,
|
||||
country,
|
||||
bio: faker.lorem.sentence(),
|
||||
joinedAt: faker.date.past(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return drivers;
|
||||
}
|
||||
|
||||
export function createLeagues(ownerIds: string[]): League[] {
|
||||
const leagueNames = [
|
||||
'GridPilot Sprint Series',
|
||||
'GridPilot Endurance Cup',
|
||||
'GridPilot Club Ladder',
|
||||
'Sprint Challenge League',
|
||||
'Club Racers Collective',
|
||||
'Sim Racing Alliance',
|
||||
'Pacific Time Attack',
|
||||
'Nordic Night Series',
|
||||
];
|
||||
|
||||
const leagues: League[] = [];
|
||||
const leagueCount = 6 + faker.number.int({ min: 0, max: 2 });
|
||||
|
||||
for (let i = 0; i < leagueCount; i++) {
|
||||
const id = `league-${i + 1}`;
|
||||
const name = leagueNames[i] ?? faker.company.name();
|
||||
// Ensure league-5 (demo league with running race) is owned by driver-1
|
||||
const ownerId = i === 4 ? 'driver-1' : pickOne(ownerIds);
|
||||
|
||||
const maxDriversOptions = [24, 32, 48, 64];
|
||||
let settings = {
|
||||
pointsSystem: faker.helpers.arrayElement(['f1-2024', 'indycar']),
|
||||
sessionDuration: faker.helpers.arrayElement([45, 60, 90, 120]),
|
||||
qualifyingFormat: faker.helpers.arrayElement(['open', 'single-lap']),
|
||||
maxDrivers: faker.helpers.arrayElement(maxDriversOptions),
|
||||
} as const;
|
||||
|
||||
if (i === 0) {
|
||||
settings = {
|
||||
...settings,
|
||||
maxDrivers: 24,
|
||||
};
|
||||
} else if (i === 1) {
|
||||
settings = {
|
||||
...settings,
|
||||
maxDrivers: 24,
|
||||
};
|
||||
} else if (i === 2) {
|
||||
settings = {
|
||||
...settings,
|
||||
maxDrivers: 40,
|
||||
};
|
||||
}
|
||||
|
||||
const socialLinks =
|
||||
i === 0
|
||||
? {
|
||||
discordUrl: 'https://discord.gg/gridpilot-demo',
|
||||
youtubeUrl: 'https://youtube.com/@gridpilot-demo',
|
||||
websiteUrl: 'https://gridpilot-demo.example.com',
|
||||
}
|
||||
: i === 1
|
||||
? {
|
||||
discordUrl: 'https://discord.gg/gridpilot-endurance',
|
||||
youtubeUrl: 'https://youtube.com/@gridpilot-endurance',
|
||||
}
|
||||
: i === 2
|
||||
? {
|
||||
websiteUrl: 'https://virtual-touring.example.com',
|
||||
}
|
||||
: undefined;
|
||||
|
||||
if (socialLinks) {
|
||||
leagues.push(
|
||||
League.create({
|
||||
id,
|
||||
name,
|
||||
description: faker.lorem.sentence(),
|
||||
ownerId,
|
||||
settings,
|
||||
createdAt: faker.date.past(),
|
||||
socialLinks,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
leagues.push(
|
||||
League.create({
|
||||
id,
|
||||
name,
|
||||
description: faker.lorem.sentence(),
|
||||
ownerId,
|
||||
settings,
|
||||
createdAt: faker.date.past(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return leagues;
|
||||
}
|
||||
|
||||
export function createTeams(leagues: League[], getTeamLogo: (id: string) => string): DemoTeamDTO[] {
|
||||
const teams: DemoTeamDTO[] = [];
|
||||
const teamCount = 24 + faker.number.int({ min: 0, max: 12 });
|
||||
|
||||
for (let i = 0; i < teamCount; i++) {
|
||||
const id = `team-${i + 1}`;
|
||||
const primaryLeague = pickOne(leagues);
|
||||
const name = faker.company.name();
|
||||
const tag = faker.string.alpha({ length: 4 }).toUpperCase();
|
||||
const memberCount = faker.number.int({ min: 2, max: 8 });
|
||||
|
||||
teams.push({
|
||||
id,
|
||||
name,
|
||||
tag,
|
||||
description: faker.lorem.sentence(),
|
||||
logoUrl: getTeamLogo(id),
|
||||
primaryLeagueId: primaryLeague.id,
|
||||
memberCount,
|
||||
});
|
||||
}
|
||||
|
||||
return teams;
|
||||
}
|
||||
|
||||
export function createMemberships(
|
||||
drivers: Driver[],
|
||||
leagues: League[],
|
||||
teams: DemoTeamDTO[],
|
||||
): RacingMembership[] {
|
||||
const memberships: RacingMembership[] = [];
|
||||
|
||||
const teamsByLeague = new Map<string, DemoTeamDTO[]>();
|
||||
teams.forEach((team) => {
|
||||
const list = teamsByLeague.get(team.primaryLeagueId) ?? [];
|
||||
list.push(team);
|
||||
teamsByLeague.set(team.primaryLeagueId, list);
|
||||
});
|
||||
|
||||
|
||||
drivers.forEach((driver) => {
|
||||
// Each driver participates in 1–3 leagues
|
||||
const leagueSampleSize = faker.number.int({ min: 1, max: Math.min(3, leagues.length) });
|
||||
const shuffledLeagues = faker.helpers.shuffle(leagues).slice(0, leagueSampleSize);
|
||||
|
||||
shuffledLeagues.forEach((league) => {
|
||||
const leagueTeams = teamsByLeague.get(league.id) ?? [];
|
||||
const team =
|
||||
leagueTeams.length > 0 && faker.datatype.boolean()
|
||||
? pickOne(leagueTeams)
|
||||
: undefined;
|
||||
|
||||
const membership: RacingMembership = {
|
||||
driverId: driver.id,
|
||||
leagueId: league.id,
|
||||
};
|
||||
|
||||
if (team) {
|
||||
membership.teamId = team.id;
|
||||
}
|
||||
|
||||
memberships.push(membership);
|
||||
});
|
||||
});
|
||||
|
||||
return memberships;
|
||||
}
|
||||
|
||||
export function createRaces(leagues: League[]): Race[] {
|
||||
const races: Race[] = [];
|
||||
const raceCount = 60 + faker.number.int({ min: 0, max: 20 });
|
||||
|
||||
const tracks = [
|
||||
'Monza GP',
|
||||
'Spa-Francorchamps',
|
||||
'Suzuka',
|
||||
'Mount Panorama',
|
||||
'Silverstone GP',
|
||||
'Interlagos',
|
||||
'Imola',
|
||||
'Laguna Seca',
|
||||
];
|
||||
|
||||
const cars = [
|
||||
'GT3 – Porsche 911',
|
||||
'GT3 – BMW M4',
|
||||
'LMP3 Prototype',
|
||||
'GT4 – Alpine',
|
||||
'Touring – Civic',
|
||||
];
|
||||
|
||||
const baseDate = new Date();
|
||||
|
||||
for (let i = 0; i < raceCount; i++) {
|
||||
const id = `race-${i + 1}`;
|
||||
let league = pickOne(leagues);
|
||||
const offsetDays = faker.number.int({ min: -30, max: 45 });
|
||||
const scheduledAt = new Date(baseDate.getTime() + offsetDays * 24 * 60 * 60 * 1000);
|
||||
let status: 'scheduled' | 'completed' | 'running' = scheduledAt.getTime() < baseDate.getTime() ? 'completed' : 'scheduled';
|
||||
let strengthOfField: number | undefined;
|
||||
|
||||
// Special case: Make race-1 a running race in league-5 (user's admin league)
|
||||
if (i === 0) {
|
||||
const league5 = leagues.find(l => l.id === 'league-5');
|
||||
if (league5) {
|
||||
league = league5;
|
||||
status = 'running';
|
||||
// Calculate SOF for the running race (simulate 12-20 drivers with average rating ~1500)
|
||||
const participantCount = faker.number.int({ min: 12, max: 20 });
|
||||
const averageRating = 1500 + faker.number.int({ min: -200, max: 300 });
|
||||
strengthOfField = Math.round(averageRating);
|
||||
}
|
||||
}
|
||||
|
||||
races.push(
|
||||
Race.create({
|
||||
id,
|
||||
leagueId: league.id,
|
||||
scheduledAt,
|
||||
track: faker.helpers.arrayElement(tracks),
|
||||
car: faker.helpers.arrayElement(cars),
|
||||
sessionType: 'race',
|
||||
status,
|
||||
...(strengthOfField !== undefined ? { strengthOfField } : {}),
|
||||
...(status === 'running' ? { registeredCount: faker.number.int({ min: 12, max: 20 }) } : {}),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return races;
|
||||
}
|
||||
|
||||
export function createResults(drivers: Driver[], races: Race[]): Result[] {
|
||||
const results: Result[] = [];
|
||||
|
||||
const completedRaces = races.filter((race) => race.status === 'completed');
|
||||
|
||||
completedRaces.forEach((race) => {
|
||||
const participantCount = faker.number.int({ min: 20, max: 32 });
|
||||
const shuffledDrivers = faker.helpers.shuffle(drivers).slice(0, participantCount);
|
||||
|
||||
shuffledDrivers.forEach((driver, index) => {
|
||||
const position = index + 1;
|
||||
const startPosition = faker.number.int({ min: 1, max: participantCount });
|
||||
const fastestLap = 90_000 + index * 250 + faker.number.int({ min: 0, max: 2_000 });
|
||||
const incidents = faker.number.int({ min: 0, max: 6 });
|
||||
|
||||
results.push(
|
||||
Result.create({
|
||||
id: `${race.id}-${driver.id}`,
|
||||
raceId: race.id,
|
||||
driverId: driver.id,
|
||||
position,
|
||||
startPosition,
|
||||
fastestLap,
|
||||
incidents,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
export function createStandings(leagues: League[], results: Result[]): Standing[] {
|
||||
const standingsByLeague = new Map<string, Standing[]>();
|
||||
|
||||
leagues.forEach((league) => {
|
||||
const leagueRaceIds = new Set(
|
||||
results
|
||||
.filter((result) => {
|
||||
return result.raceId.startsWith('race-');
|
||||
})
|
||||
.map((result) => result.raceId),
|
||||
);
|
||||
|
||||
const leagueResults = results.filter((result) => leagueRaceIds.has(result.raceId));
|
||||
|
||||
const standingsMap = new Map<string, Standing>();
|
||||
|
||||
leagueResults.forEach((result) => {
|
||||
const key = result.driverId;
|
||||
let standing = standingsMap.get(key);
|
||||
|
||||
if (!standing) {
|
||||
standing = Standing.create({
|
||||
leagueId: league.id,
|
||||
driverId: result.driverId,
|
||||
});
|
||||
}
|
||||
|
||||
standing = standing.addRaceResult(result.position, POINTS_TABLE);
|
||||
standingsMap.set(key, standing);
|
||||
});
|
||||
|
||||
const sortedStandings = Array.from(standingsMap.values()).sort((a, b) => {
|
||||
if (b.points !== a.points) {
|
||||
return b.points - a.points;
|
||||
}
|
||||
if (b.wins !== a.wins) {
|
||||
return b.wins - a.wins;
|
||||
}
|
||||
return b.racesCompleted - a.racesCompleted;
|
||||
});
|
||||
|
||||
const finalizedStandings = sortedStandings.map((standing, index) =>
|
||||
standing.updatePosition(index + 1),
|
||||
);
|
||||
|
||||
standingsByLeague.set(league.id, finalizedStandings);
|
||||
});
|
||||
|
||||
return Array.from(standingsByLeague.values()).flat();
|
||||
}
|
||||
|
||||
export function createFriendships(drivers: Driver[]): Friendship[] {
|
||||
const friendships: Friendship[] = [];
|
||||
|
||||
drivers.forEach((driver, index) => {
|
||||
const friendCount = faker.number.int({ min: 3, max: 8 });
|
||||
for (let offset = 1; offset <= friendCount; offset++) {
|
||||
const friendIndex = (index + offset) % drivers.length;
|
||||
const friend = drivers[friendIndex];
|
||||
if (!friend) continue;
|
||||
if (friend.id === driver.id) continue;
|
||||
|
||||
friendships.push({
|
||||
driverId: driver.id,
|
||||
friendId: friend.id,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return friendships;
|
||||
}
|
||||
451
testing/src/racing/RacingSponsorshipSeed.ts
Normal file
451
testing/src/racing/RacingSponsorshipSeed.ts
Normal file
@@ -0,0 +1,451 @@
|
||||
import { League } from '@gridpilot/racing/domain/entities/League';
|
||||
import { Race } from '@gridpilot/racing/domain/entities/Race';
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
import { Money } from '@gridpilot/racing/domain/value-objects/Money';
|
||||
import { SponsorshipPricing } from '@gridpilot/racing/domain/value-objects/SponsorshipPricing';
|
||||
import {
|
||||
SponsorshipRequest,
|
||||
type SponsorableEntityType,
|
||||
} from '@gridpilot/racing/domain/entities/SponsorshipRequest';
|
||||
|
||||
import type { DemoTeamDTO } from './RacingSeedCore';
|
||||
|
||||
/**
|
||||
* Demo sponsor data for seeding.
|
||||
*/
|
||||
export interface DemoSponsorDTO {
|
||||
id: string;
|
||||
name: string;
|
||||
contactEmail: string;
|
||||
logoUrl: string;
|
||||
websiteUrl: string;
|
||||
tagline: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Demo season sponsorship data.
|
||||
* This remains a simple DTO since the SeasonSponsorship
|
||||
* domain entity is instantiated in the DI config.
|
||||
*/
|
||||
export interface DemoSeasonSponsorshipDTO {
|
||||
id: string;
|
||||
seasonId: string;
|
||||
sponsorId: string;
|
||||
tier: 'main' | 'secondary';
|
||||
pricingAmount: number;
|
||||
pricingCurrency: 'USD' | 'EUR' | 'GBP';
|
||||
status: 'pending' | 'active' | 'cancelled';
|
||||
description?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Demo sponsorship request data for seeding.
|
||||
* Backed directly by the SponsorshipRequest domain entity.
|
||||
*/
|
||||
export type DemoSponsorshipRequestDTO = SponsorshipRequest;
|
||||
|
||||
/**
|
||||
* Demo sponsorship pricing configuration for entities, using the
|
||||
* SponsorshipPricing value object to keep pricing logic in the domain.
|
||||
*/
|
||||
export interface DemoSponsorshipPricingDTO {
|
||||
entityType: SponsorableEntityType;
|
||||
entityId: string;
|
||||
pricing: SponsorshipPricing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Demo sponsors data - realistic sim racing sponsors.
|
||||
*/
|
||||
export const DEMO_SPONSORS: DemoSponsorDTO[] = [
|
||||
{
|
||||
id: 'sponsor-fanatec',
|
||||
name: 'Fanatec',
|
||||
contactEmail: 'partnerships@fanatec.com',
|
||||
logoUrl: '/images/sponsors/fanatec.svg',
|
||||
websiteUrl: 'https://fanatec.com',
|
||||
tagline: "The world's leading sim racing hardware",
|
||||
},
|
||||
{
|
||||
id: 'sponsor-simucube',
|
||||
name: 'Simucube',
|
||||
contactEmail: 'sponsors@simucube.com',
|
||||
logoUrl: '/images/sponsors/simucube.svg',
|
||||
websiteUrl: 'https://simucube.com',
|
||||
tagline: 'Professional Direct Drive Wheels',
|
||||
},
|
||||
{
|
||||
id: 'sponsor-heusinkveld',
|
||||
name: 'Heusinkveld',
|
||||
contactEmail: 'info@heusinkveld.com',
|
||||
logoUrl: '/images/sponsors/heusinkveld.svg',
|
||||
websiteUrl: 'https://heusinkveld.com',
|
||||
tagline: 'Sim Racing Pedals & Hardware',
|
||||
},
|
||||
{
|
||||
id: 'sponsor-trak-racer',
|
||||
name: 'Trak Racer',
|
||||
contactEmail: 'partnerships@trakracer.com',
|
||||
logoUrl: '/images/sponsors/trak-racer.svg',
|
||||
websiteUrl: 'https://trakracer.com',
|
||||
tagline: 'Premium Racing Simulators & Cockpits',
|
||||
},
|
||||
{
|
||||
id: 'sponsor-simlab',
|
||||
name: 'Sim-Lab',
|
||||
contactEmail: 'sponsor@sim-lab.eu',
|
||||
logoUrl: '/images/sponsors/simlab.svg',
|
||||
websiteUrl: 'https://sim-lab.eu',
|
||||
tagline: 'Aluminum Profile Sim Racing Rigs',
|
||||
},
|
||||
{
|
||||
id: 'sponsor-motionrig',
|
||||
name: 'MotionRig Pro',
|
||||
contactEmail: 'business@motionrigpro.com',
|
||||
logoUrl: '/images/sponsors/motionrig.svg',
|
||||
websiteUrl: 'https://motionrigpro.com',
|
||||
tagline: 'Feel every turn, every bump',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Create season sponsorships linking sponsors to leagues.
|
||||
*/
|
||||
export function createSeasonSponsorships(
|
||||
leagues: League[],
|
||||
sponsors: DemoSponsorDTO[],
|
||||
): DemoSeasonSponsorshipDTO[] {
|
||||
const sponsorships: DemoSeasonSponsorshipDTO[] = [];
|
||||
|
||||
const FANATEC_ID = sponsors.find((s) => s.id === 'sponsor-fanatec')?.id ?? 'sponsor-fanatec';
|
||||
const HEUSINKVELD_ID =
|
||||
sponsors.find((s) => s.id === 'sponsor-heusinkveld')?.id ?? 'sponsor-heusinkveld';
|
||||
const SIMUCUBE_ID = sponsors.find((s) => s.id === 'sponsor-simucube')?.id ?? 'sponsor-simucube';
|
||||
const TRAK_RACER_ID =
|
||||
sponsors.find((s) => s.id === 'sponsor-trak-racer')?.id ?? 'sponsor-trak-racer';
|
||||
const SIMLAB_ID = sponsors.find((s) => s.id === 'sponsor-simlab')?.id ?? 'sponsor-simlab';
|
||||
const MOTIONRIG_ID =
|
||||
sponsors.find((s) => s.id === 'sponsor-motionrig')?.id ?? 'sponsor-motionrig';
|
||||
|
||||
// GridPilot Sprint Series - sponsored by Fanatec (main) + Heusinkveld & Simucube (secondary)
|
||||
const sprintLeague = leagues.find((l) => l.name === 'GridPilot Sprint Series');
|
||||
if (sprintLeague) {
|
||||
sponsorships.push({
|
||||
id: `sponsorship-${sprintLeague.id}-fanatec`,
|
||||
seasonId: `season-${sprintLeague.id}-demo`,
|
||||
sponsorId: FANATEC_ID,
|
||||
tier: 'main',
|
||||
pricingAmount: 5000,
|
||||
pricingCurrency: 'USD',
|
||||
status: 'active',
|
||||
description: 'Main sponsor for the Sprint Series - premium wheel branding',
|
||||
});
|
||||
sponsorships.push({
|
||||
id: `sponsorship-${sprintLeague.id}-heusinkveld`,
|
||||
seasonId: `season-${sprintLeague.id}-demo`,
|
||||
sponsorId: HEUSINKVELD_ID,
|
||||
tier: 'secondary',
|
||||
pricingAmount: 2000,
|
||||
pricingCurrency: 'USD',
|
||||
status: 'active',
|
||||
});
|
||||
sponsorships.push({
|
||||
id: `sponsorship-${sprintLeague.id}-simucube`,
|
||||
seasonId: `season-${sprintLeague.id}-demo`,
|
||||
sponsorId: SIMUCUBE_ID,
|
||||
tier: 'secondary',
|
||||
pricingAmount: 2000,
|
||||
pricingCurrency: 'USD',
|
||||
status: 'active',
|
||||
});
|
||||
}
|
||||
|
||||
// GridPilot Endurance Cup - sponsored by Trak Racer (main) + Sim-Lab (secondary)
|
||||
const enduranceLeague = leagues.find((l) => l.name === 'GridPilot Endurance Cup');
|
||||
if (enduranceLeague) {
|
||||
sponsorships.push({
|
||||
id: `sponsorship-${enduranceLeague.id}-trakracer`,
|
||||
seasonId: `season-${enduranceLeague.id}-demo`,
|
||||
sponsorId: TRAK_RACER_ID,
|
||||
tier: 'main',
|
||||
pricingAmount: 7500,
|
||||
pricingCurrency: 'USD',
|
||||
status: 'active',
|
||||
description: 'Endurance series naming rights',
|
||||
});
|
||||
sponsorships.push({
|
||||
id: `sponsorship-${enduranceLeague.id}-simlab`,
|
||||
seasonId: `season-${enduranceLeague.id}-demo`,
|
||||
sponsorId: SIMLAB_ID,
|
||||
tier: 'secondary',
|
||||
pricingAmount: 3000,
|
||||
pricingCurrency: 'USD',
|
||||
status: 'active',
|
||||
});
|
||||
}
|
||||
|
||||
// GridPilot Club Ladder - sponsored by MotionRig Pro (main)
|
||||
const clubLeague = leagues.find((l) => l.name === 'GridPilot Club Ladder');
|
||||
if (clubLeague) {
|
||||
sponsorships.push({
|
||||
id: `sponsorship-${clubLeague.id}-motionrig`,
|
||||
seasonId: `season-${clubLeague.id}-demo`,
|
||||
sponsorId: MOTIONRIG_ID,
|
||||
tier: 'main',
|
||||
pricingAmount: 3500,
|
||||
pricingCurrency: 'USD',
|
||||
status: 'active',
|
||||
description: 'Club ladder motion platform showcase',
|
||||
});
|
||||
}
|
||||
|
||||
return sponsorships;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create sponsorship pricing configurations for demo entities.
|
||||
* Uses the SponsorshipPricing value object to ensure domain consistency
|
||||
* and to provide a mix of season, team, driver and race offerings.
|
||||
*/
|
||||
export function createSponsorshipPricings(
|
||||
leagues: League[],
|
||||
teams: DemoTeamDTO[],
|
||||
drivers: Driver[],
|
||||
races: Race[],
|
||||
): DemoSponsorshipPricingDTO[] {
|
||||
const pricings: DemoSponsorshipPricingDTO[] = [];
|
||||
|
||||
// League/Season pricing - all leagues can accept sponsorships, with varied configs
|
||||
leagues.forEach((league, index) => {
|
||||
let pricing = SponsorshipPricing.defaultLeague();
|
||||
|
||||
// Vary league pricing/availability for demo richness
|
||||
if (index % 3 === 1) {
|
||||
// Some leagues closed for applications
|
||||
pricing = pricing.setAcceptingApplications(false);
|
||||
} else if (index % 3 === 2) {
|
||||
// Some leagues with main-only sponsorship
|
||||
pricing = pricing.updateSecondarySlot({ available: false, maxSlots: 0 });
|
||||
} else {
|
||||
// Slightly higher price for featured leagues
|
||||
pricing = pricing.updateMainSlot({
|
||||
price: Money.create(1000 + index * 50, 'USD'),
|
||||
});
|
||||
}
|
||||
|
||||
pricings.push({
|
||||
entityType: 'season',
|
||||
entityId: `season-${league.id}-demo`,
|
||||
pricing,
|
||||
});
|
||||
});
|
||||
|
||||
// Team pricing - first 10 teams accept sponsorships using team defaults,
|
||||
// with some teams pausing applications.
|
||||
teams.slice(0, 10).forEach((team, index) => {
|
||||
let pricing = SponsorshipPricing.defaultTeam();
|
||||
|
||||
if (index % 4 === 1) {
|
||||
// Teams with main + secondary but not currently accepting
|
||||
pricing = pricing.setAcceptingApplications(false);
|
||||
} else if (index % 4 === 2) {
|
||||
// Teams with only secondary slots
|
||||
pricing = pricing.updateMainSlot({ available: false, maxSlots: 0 });
|
||||
} else if (index % 4 === 3) {
|
||||
// Teams with premium main slot pricing
|
||||
pricing = pricing.updateMainSlot({
|
||||
price: Money.create(750 + index * 25, 'USD'),
|
||||
});
|
||||
}
|
||||
|
||||
pricings.push({
|
||||
entityType: 'team',
|
||||
entityId: team.id,
|
||||
pricing,
|
||||
});
|
||||
});
|
||||
|
||||
// Driver pricing - first 20 drivers accept sponsorships with varied availability.
|
||||
drivers.slice(0, 20).forEach((driver, index) => {
|
||||
let pricing = SponsorshipPricing.defaultDriver();
|
||||
|
||||
if (index % 3 === 0) {
|
||||
// Higher profile drivers
|
||||
pricing = pricing.updateMainSlot({
|
||||
price: Money.create(250 + index * 10, 'USD'),
|
||||
});
|
||||
} else if (index % 3 === 1) {
|
||||
// Drivers temporarily not accepting sponsorships
|
||||
pricing = pricing.setAcceptingApplications(false);
|
||||
}
|
||||
|
||||
pricings.push({
|
||||
entityType: 'driver',
|
||||
entityId: driver.id,
|
||||
pricing,
|
||||
});
|
||||
});
|
||||
|
||||
// Race pricing - upcoming races can have title sponsors with different tiers
|
||||
const upcomingRaces = races.filter((r) => r.status === 'scheduled').slice(0, 10);
|
||||
upcomingRaces.forEach((race, index) => {
|
||||
let pricing = SponsorshipPricing.defaultRace();
|
||||
|
||||
if (index % 2 === 0) {
|
||||
// Premium events with higher pricing
|
||||
pricing = pricing.updateMainSlot({
|
||||
price: Money.create(350 + index * 30, 'USD'),
|
||||
});
|
||||
}
|
||||
|
||||
pricings.push({
|
||||
entityType: 'race',
|
||||
entityId: race.id,
|
||||
pricing,
|
||||
});
|
||||
});
|
||||
|
||||
return pricings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create demo sponsorship requests (some pending, some accepted/rejected).
|
||||
* Uses the SponsorshipRequest domain entity and Money value object so that
|
||||
* all downstream sponsor flows can rely on domain behavior.
|
||||
*/
|
||||
export function createSponsorshipRequests(
|
||||
sponsors: DemoSponsorDTO[],
|
||||
leagues: League[],
|
||||
teams: DemoTeamDTO[],
|
||||
drivers: Driver[],
|
||||
races: Race[],
|
||||
): DemoSponsorshipRequestDTO[] {
|
||||
const requests: DemoSponsorshipRequestDTO[] = [];
|
||||
const now = new Date();
|
||||
|
||||
const SIMUCUBE_ID = sponsors.find((s) => s.id === 'sponsor-simucube')?.id ?? 'sponsor-simucube';
|
||||
const HEUSINKVELD_ID =
|
||||
sponsors.find((s) => s.id === 'sponsor-heusinkveld')?.id ?? 'sponsor-heusinkveld';
|
||||
const TRAK_RACER_ID =
|
||||
sponsors.find((s) => s.id === 'sponsor-trak-racer')?.id ?? 'sponsor-trak-racer';
|
||||
const MOTIONRIG_ID =
|
||||
sponsors.find((s) => s.id === 'sponsor-motionrig')?.id ?? 'sponsor-motionrig';
|
||||
const SIMLAB_ID = sponsors.find((s) => s.id === 'sponsor-simlab')?.id ?? 'sponsor-simlab';
|
||||
|
||||
// Pending request: Simucube wants to sponsor a driver
|
||||
if (drivers.length > 6) {
|
||||
const targetDriver = drivers[5];
|
||||
if (targetDriver) {
|
||||
requests.push(
|
||||
SponsorshipRequest.create({
|
||||
id: 'req-simucube-driver-1',
|
||||
sponsorId: SIMUCUBE_ID,
|
||||
entityType: 'driver',
|
||||
entityId: targetDriver.id,
|
||||
tier: 'main',
|
||||
offeredAmount: Money.create(250, 'USD'),
|
||||
message:
|
||||
'We would love to sponsor your racing career! Simucube offers the best direct drive wheels in sim racing.',
|
||||
createdAt: new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000), // 2 days ago
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Pending request: Heusinkveld wants to sponsor a team
|
||||
if (teams.length > 3) {
|
||||
const targetTeam = teams[2];
|
||||
if (targetTeam) {
|
||||
requests.push(
|
||||
SponsorshipRequest.create({
|
||||
id: 'req-heusinkveld-team-1',
|
||||
sponsorId: HEUSINKVELD_ID,
|
||||
entityType: 'team',
|
||||
entityId: targetTeam.id,
|
||||
tier: 'main',
|
||||
offeredAmount: Money.create(550, 'USD'),
|
||||
message:
|
||||
'Heusinkveld pedals are known for their precision. We believe your team embodies the same values.',
|
||||
createdAt: new Date(now.getTime() - 3 * 24 * 60 * 60 * 1000), // 3 days ago
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Pending request: Trak Racer wants to sponsor a race
|
||||
const upcomingRace = races.find((r) => r.status === 'scheduled');
|
||||
if (upcomingRace) {
|
||||
requests.push(
|
||||
SponsorshipRequest.create({
|
||||
id: 'req-trakracer-race-1',
|
||||
sponsorId: TRAK_RACER_ID,
|
||||
entityType: 'race',
|
||||
entityId: upcomingRace.id,
|
||||
tier: 'main',
|
||||
offeredAmount: Money.create(350, 'USD'),
|
||||
message: 'We would like to be the title sponsor for this exciting race event!',
|
||||
createdAt: new Date(now.getTime() - 1 * 24 * 60 * 60 * 1000), // 1 day ago
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// Pending request: MotionRig Pro wants secondary spot on a league season
|
||||
const clubLeague = leagues.find((l) => l.name === 'Sprint Challenge League');
|
||||
if (clubLeague) {
|
||||
requests.push(
|
||||
SponsorshipRequest.create({
|
||||
id: 'req-motionrig-league-1',
|
||||
sponsorId: MOTIONRIG_ID,
|
||||
entityType: 'season',
|
||||
entityId: `season-${clubLeague.id}-demo`,
|
||||
tier: 'secondary',
|
||||
offeredAmount: Money.create(1500, 'USD'),
|
||||
message:
|
||||
'MotionRig Pro would love to be a secondary sponsor. Our motion platforms are perfect for your competitive drivers.',
|
||||
createdAt: new Date(now.getTime() - 5 * 24 * 60 * 60 * 1000), // 5 days ago
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// Already accepted request (for history)
|
||||
if (teams.length > 0) {
|
||||
const acceptedTeam = teams[0];
|
||||
if (acceptedTeam) {
|
||||
requests.push(
|
||||
SponsorshipRequest.create({
|
||||
id: 'req-simlab-team-accepted',
|
||||
sponsorId: SIMLAB_ID,
|
||||
entityType: 'team',
|
||||
entityId: acceptedTeam.id,
|
||||
tier: 'secondary',
|
||||
offeredAmount: Money.create(300, 'USD'),
|
||||
message: 'Sim-Lab rigs are the foundation of any competitive setup.',
|
||||
status: 'accepted',
|
||||
createdAt: new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000), // 30 days ago
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Already rejected request (for history)
|
||||
if (drivers.length > 10) {
|
||||
const rejectedDriver = drivers[10];
|
||||
if (rejectedDriver) {
|
||||
requests.push(
|
||||
SponsorshipRequest.create({
|
||||
id: 'req-motionrig-driver-rejected',
|
||||
sponsorId: MOTIONRIG_ID,
|
||||
entityType: 'driver',
|
||||
entityId: rejectedDriver.id,
|
||||
tier: 'main',
|
||||
offeredAmount: Money.create(150, 'USD'),
|
||||
message: 'Would you like to represent MotionRig Pro?',
|
||||
status: 'rejected',
|
||||
createdAt: new Date(now.getTime() - 20 * 24 * 60 * 60 * 1000), // 20 days ago
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return requests;
|
||||
}
|
||||
203
testing/src/racing/RacingStaticSeed.ts
Normal file
203
testing/src/racing/RacingStaticSeed.ts
Normal file
@@ -0,0 +1,203 @@
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
import { League } from '@gridpilot/racing/domain/entities/League';
|
||||
import { Race } from '@gridpilot/racing/domain/entities/Race';
|
||||
import { Result } from '@gridpilot/racing/domain/entities/Result';
|
||||
import { Standing } from '@gridpilot/racing/domain/entities/Standing';
|
||||
|
||||
import type { FeedItem } from '@gridpilot/social/domain/types/FeedItem';
|
||||
import type { FriendDTO } from '@gridpilot/social/application/dto/FriendDTO';
|
||||
|
||||
import { faker } from '../faker/faker';
|
||||
import { getTeamLogo } from '../images/images';
|
||||
|
||||
import {
|
||||
createDrivers,
|
||||
createLeagues,
|
||||
createTeams,
|
||||
createMemberships,
|
||||
createRaces,
|
||||
createResults,
|
||||
createStandings,
|
||||
createFriendships,
|
||||
type RacingMembership,
|
||||
type Friendship,
|
||||
type DemoTeamDTO,
|
||||
} from './RacingSeedCore';
|
||||
import {
|
||||
DEMO_SPONSORS,
|
||||
createSeasonSponsorships,
|
||||
createSponsorshipPricings,
|
||||
createSponsorshipRequests,
|
||||
type DemoSponsorDTO,
|
||||
type DemoSeasonSponsorshipDTO,
|
||||
type DemoSponsorshipRequestDTO,
|
||||
type DemoSponsorshipPricingDTO,
|
||||
} from './RacingSponsorshipSeed';
|
||||
import {
|
||||
createFeedEvents,
|
||||
buildFriends,
|
||||
buildTopLeagues,
|
||||
buildUpcomingRaces,
|
||||
buildLatestResults,
|
||||
type RaceWithResultsDTO,
|
||||
} from './RacingFeedSeed';
|
||||
|
||||
/**
|
||||
* Aggregated racing seed data used by the website DI container
|
||||
* and other demo infrastructure.
|
||||
*/
|
||||
export type RacingSeedData = {
|
||||
drivers: Driver[];
|
||||
leagues: League[];
|
||||
races: Race[];
|
||||
results: Result[];
|
||||
standings: Standing[];
|
||||
memberships: RacingMembership[];
|
||||
friendships: Friendship[];
|
||||
feedEvents: FeedItem[];
|
||||
teams: DemoTeamDTO[];
|
||||
sponsors: DemoSponsorDTO[];
|
||||
seasonSponsorships: DemoSeasonSponsorshipDTO[];
|
||||
sponsorshipRequests: DemoSponsorshipRequestDTO[];
|
||||
sponsorshipPricings: DemoSponsorshipPricingDTO[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the full static racing seed from the smaller core/sponsorship/feed modules.
|
||||
*/
|
||||
export function createStaticRacingSeed(seed: number): RacingSeedData {
|
||||
faker.seed(seed);
|
||||
|
||||
const drivers = createDrivers(96);
|
||||
const leagues = createLeagues(drivers.slice(0, 12).map((d) => d.id));
|
||||
const teams = createTeams(leagues, getTeamLogo);
|
||||
const memberships = createMemberships(drivers, leagues, teams);
|
||||
const races = createRaces(leagues);
|
||||
const results = createResults(drivers, races);
|
||||
const friendships = createFriendships(drivers);
|
||||
const feedEvents = createFeedEvents(drivers, leagues, races, friendships);
|
||||
const standings = createStandings(leagues, results);
|
||||
const sponsors = DEMO_SPONSORS;
|
||||
const seasonSponsorships = createSeasonSponsorships(leagues, sponsors);
|
||||
const sponsorshipPricings = createSponsorshipPricings(leagues, teams, drivers, races);
|
||||
const sponsorshipRequests = createSponsorshipRequests(sponsors, leagues, teams, drivers, races);
|
||||
|
||||
return {
|
||||
drivers,
|
||||
leagues,
|
||||
races,
|
||||
results,
|
||||
standings,
|
||||
memberships,
|
||||
friendships,
|
||||
feedEvents,
|
||||
teams,
|
||||
sponsors,
|
||||
seasonSponsorships,
|
||||
sponsorshipRequests,
|
||||
sponsorshipPricings,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton seed used by website demo helpers.
|
||||
*
|
||||
* Alpha demo dataset (deterministic, in-memory only):
|
||||
* - 90+ drivers across multiple leagues
|
||||
* - Leagues with precomputed races, results and standings
|
||||
* - Team memberships and friendships forming social “circles”
|
||||
* - Feed events referencing real driver, league, race and team IDs
|
||||
*/
|
||||
const staticSeed = createStaticRacingSeed(42);
|
||||
|
||||
export const drivers = staticSeed.drivers;
|
||||
export const leagues = staticSeed.leagues;
|
||||
export const races = staticSeed.races;
|
||||
export const results = staticSeed.results;
|
||||
export const standings = staticSeed.standings;
|
||||
export const teams = staticSeed.teams;
|
||||
export const memberships = staticSeed.memberships;
|
||||
export const friendships = staticSeed.friendships;
|
||||
export const feedEvents = staticSeed.feedEvents;
|
||||
export const sponsors = staticSeed.sponsors;
|
||||
export const seasonSponsorships = staticSeed.seasonSponsorships;
|
||||
export const sponsorshipRequests = staticSeed.sponsorshipRequests;
|
||||
export const sponsorshipPricings = staticSeed.sponsorshipPricings;
|
||||
|
||||
/**
|
||||
* Derived friend DTOs for UI consumption.
|
||||
* This preserves the previous demo-data `friends` shape.
|
||||
*/
|
||||
export const friends: FriendDTO[] = buildFriends(staticSeed.drivers, staticSeed.memberships);
|
||||
|
||||
/**
|
||||
* Top leagues with banner URLs for UI.
|
||||
*/
|
||||
export const topLeagues = buildTopLeagues(leagues);
|
||||
|
||||
/**
|
||||
* Re-export RaceWithResultsDTO and helpers for latest/upcoming races.
|
||||
*/
|
||||
export type { RaceWithResultsDTO } from './RacingFeedSeed';
|
||||
|
||||
export function getUpcomingRaces(limit?: number): readonly Race[] {
|
||||
return buildUpcomingRaces(races, limit);
|
||||
}
|
||||
|
||||
export function getLatestResults(limit?: number): readonly RaceWithResultsDTO[] {
|
||||
return buildLatestResults(races, results, drivers, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demo league archetype helper for seeding structure and scoring.
|
||||
* Kept here as the small, focused definition used by DI.
|
||||
*/
|
||||
export type DemoLeagueArchetype =
|
||||
| {
|
||||
id: 'sprint-series';
|
||||
name: 'GridPilot Sprint Series';
|
||||
structure: { mode: 'solo'; maxDrivers: 24 };
|
||||
scoringPresetId: 'sprint-main-driver';
|
||||
}
|
||||
| {
|
||||
id: 'endurance-cup';
|
||||
name: 'GridPilot Endurance Cup';
|
||||
structure: { mode: 'fixedTeams'; maxTeams: 12; driversPerTeam: 2 };
|
||||
scoringPresetId: 'endurance-main-double';
|
||||
}
|
||||
| {
|
||||
id: 'club-ladder';
|
||||
name: 'GridPilot Club Ladder';
|
||||
structure: { mode: 'solo'; maxDrivers: 40 };
|
||||
scoringPresetId: 'club-default';
|
||||
};
|
||||
|
||||
export function getDemoLeagueArchetypeByName(
|
||||
leagueName: string,
|
||||
): DemoLeagueArchetype | undefined {
|
||||
switch (leagueName) {
|
||||
case 'GridPilot Sprint Series':
|
||||
return {
|
||||
id: 'sprint-series',
|
||||
name: 'GridPilot Sprint Series',
|
||||
structure: { mode: 'solo', maxDrivers: 24 },
|
||||
scoringPresetId: 'sprint-main-driver',
|
||||
};
|
||||
case 'GridPilot Endurance Cup':
|
||||
return {
|
||||
id: 'endurance-cup',
|
||||
name: 'GridPilot Endurance Cup',
|
||||
structure: { mode: 'fixedTeams', maxTeams: 12, driversPerTeam: 2 },
|
||||
scoringPresetId: 'endurance-main-double',
|
||||
};
|
||||
case 'GridPilot Club Ladder':
|
||||
return {
|
||||
id: 'club-ladder',
|
||||
name: 'GridPilot Club Ladder',
|
||||
structure: { mode: 'solo', maxDrivers: 40 },
|
||||
scoringPresetId: 'club-default',
|
||||
};
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
9
testing/tsconfig.json
Normal file
9
testing/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"declaration": true,
|
||||
"declarationMap": false
|
||||
},
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user