import { describe, it, expect, beforeEach } from 'vitest'; import { DriversTestContext } from '../DriversTestContext'; import { Driver } from '../../../../core/racing/domain/entities/Driver'; import { Team } from '../../../../core/racing/domain/entities/Team'; describe('GetProfileOverviewUseCase Integration', () => { let context: DriversTestContext; beforeEach(() => { context = DriversTestContext.create(); context.clear(); }); describe('Success Path', () => { it('should retrieve complete driver profile overview', async () => { 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' }); 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: [] }); const result = await context.getProfileOverviewUseCase.execute({ driverId }); 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.teamMemberships[0]!.team.id).toBe('t1'); expect(overview.socialSummary.friendsCount).toBe(1); expect(overview.extendedProfile).toBeDefined(); }); it('should handle driver with minimal data', async () => { const driverId = 'new'; const driver = Driver.create({ id: driverId, iracingId: '9', name: 'New Driver', country: 'DE' }); await context.driverRepository.create(driver); const result = await context.getProfileOverviewUseCase.execute({ driverId }); expect(result.isOk()).toBe(true); const overview = result.unwrap(); expect(overview.driverInfo.driver.id).toBe(driverId); expect(overview.stats).toBeNull(); expect(overview.teamMemberships).toHaveLength(0); expect(overview.socialSummary.friendsCount).toBe(0); }); }); describe('Error Handling', () => { it('should return error when driver does not exist', async () => { const result = await context.getProfileOverviewUseCase.execute({ driverId: 'none' }); expect(result.isErr()).toBe(true); const error = result.unwrapErr(); expect(error.code).toBe('DRIVER_NOT_FOUND'); }); }); });