Files
gridpilot.gg/tests/integration/profile/use-cases/GetProfileOverviewUseCase.test.ts
Marc Mintel 6df38a462a
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
integration tests
2026-01-23 11:44:59 +01:00

95 lines
3.4 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest';
import { ProfileTestContext } from '../ProfileTestContext';
import { GetProfileOverviewUseCase } from '../../../../core/racing/application/use-cases/GetProfileOverviewUseCase';
import { DriverStatsUseCase } from '../../../../core/racing/application/use-cases/DriverStatsUseCase';
import { RankingUseCase } from '../../../../core/racing/application/use-cases/RankingUseCase';
import { Driver } from '../../../../core/racing/domain/entities/Driver';
import { Team } from '../../../../core/racing/domain/entities/Team';
describe('GetProfileOverviewUseCase', () => {
let context: ProfileTestContext;
let useCase: GetProfileOverviewUseCase;
beforeEach(async () => {
context = new ProfileTestContext();
const driverStatsUseCase = new DriverStatsUseCase(
context.resultRepository,
context.standingRepository,
context.driverStatsRepository,
context.logger
);
const rankingUseCase = new RankingUseCase(
context.standingRepository,
context.driverRepository,
context.driverStatsRepository,
context.logger
);
useCase = new GetProfileOverviewUseCase(
context.driverRepository,
context.teamRepository,
context.teamMembershipRepository,
context.socialRepository,
context.driverExtendedProfileProvider,
driverStatsUseCase,
rankingUseCase
);
await context.clear();
});
it('should retrieve complete driver profile overview', async () => {
// Given: A driver exists with stats, team, and friends
const driverId = 'd1';
const driver = Driver.create({ id: driverId, iracingId: '1', name: 'John Doe', country: 'US' });
await context.driverRepository.create(driver);
await context.driverStatsRepository.saveDriverStats(driverId, {
rating: 2000,
totalRaces: 10,
wins: 2,
podiums: 5,
overallRank: 1,
safetyRating: 4.5,
sportsmanshipRating: 95,
dnfs: 0,
avgFinish: 3.5,
bestFinish: 1,
worstFinish: 10,
consistency: 85,
experienceLevel: 'pro'
} as any);
const team = Team.create({ id: 't1', name: 'Team 1', tag: 'T1', description: 'Desc', ownerId: 'other', leagues: [] });
await context.teamRepository.create(team);
await context.teamMembershipRepository.saveMembership({
teamId: 't1',
driverId: driverId,
role: 'driver',
status: 'active',
joinedAt: new Date()
});
context.socialRepository.seed({
drivers: [driver, Driver.create({ id: 'f1', iracingId: '2', name: 'Friend 1', country: 'UK' })],
friendships: [{ driverId: driverId, friendId: 'f1' }],
feedEvents: []
});
// When: GetProfileOverviewUseCase.execute() is called
const result = await useCase.execute({ driverId });
// Then: The result should contain all profile sections
expect(result.isOk()).toBe(true);
const overview = result.unwrap();
expect(overview.driverInfo.driver.id).toBe(driverId);
expect(overview.stats?.rating).toBe(2000);
expect(overview.teamMemberships).toHaveLength(1);
expect(overview.socialSummary.friendsCount).toBe(1);
});
it('should return error when driver does not exist', async () => {
const result = await useCase.execute({ driverId: 'non-existent' });
expect(result.isErr()).toBe(true);
expect((result.error as any).code).toBe('DRIVER_NOT_FOUND');
});
});