import { describe, it, expect } from 'vitest'; import { DashboardOverviewUseCase, type DashboardOverviewInput, type DashboardOverviewResult, } from '@core/racing/application/use-cases/DashboardOverviewUseCase'; import { Driver } from '@core/racing/domain/entities/Driver'; import { Race } from '@core/racing/domain/entities/Race'; import { League } from '@core/racing/domain/entities/League'; import { Standing } from '@core/racing/domain/entities/Standing'; import { LeagueMembership } from '@core/racing/domain/entities/LeagueMembership'; import { Result as RaceResult } from '@core/racing/domain/entities/result/Result'; import type { FeedItem } from '@core/social/domain/types/FeedItem'; import { Result as UseCaseResult } from '@core/shared/application/Result'; import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode'; describe('DashboardOverviewUseCase', () => { it('partitions upcoming races into myUpcomingRaces and otherUpcomingRaces and selects nextRace from myUpcomingRaces', async () => { const driverId = 'driver-1'; const driver = Driver.create({ id: driverId, iracingId: '12345', name: 'Alice Racer', country: 'US' }); const leagues = [ League.create({ id: 'league-1', name: 'Alpha League', description: 'First league', ownerId: 'owner-1' }), League.create({ id: 'league-2', name: 'Beta League', description: 'Second league', ownerId: 'owner-2' }), ]; const now = Date.now(); const races = [ Race.create({ id: 'race-1', leagueId: 'league-1', track: 'Monza', car: 'GT3', scheduledAt: new Date(now + 60 * 60 * 1000), status: 'scheduled', }), Race.create({ id: 'race-2', leagueId: 'league-1', track: 'Spa', car: 'GT3', scheduledAt: new Date(now + 2 * 60 * 60 * 1000), status: 'scheduled', }), Race.create({ id: 'race-3', leagueId: 'league-2', track: 'Silverstone', car: 'GT4', scheduledAt: new Date(now + 3 * 60 * 60 * 1000), status: 'scheduled', }), Race.create({ id: 'race-4', leagueId: 'league-2', track: 'Imola', car: 'GT4', scheduledAt: new Date(now + 4 * 60 * 60 * 1000), status: 'scheduled', }), ]; const results: RaceResult[] = []; const memberships = [ LeagueMembership.create({ leagueId: 'league-1', driverId, role: 'member', status: 'active', }), LeagueMembership.create({ leagueId: 'league-2', driverId, role: 'member', status: 'active', }), ]; const registeredRaceIds = new Set(['race-1', 'race-3']); const feedItems: FeedItem[] = []; const friends: Driver[] = []; const driverRepository = { findById: async (id: string): Promise => (id === driver.id ? driver : null), findByIRacingId: async (): Promise => null, findAll: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByIRacingId: async (): Promise => false, }; const raceRepository = { findById: async (): Promise => null, findAll: async (): Promise => races, findByLeagueId: async (): Promise => [], findUpcomingByLeagueId: async (): Promise => [], findCompletedByLeagueId: async (): Promise => [], findByStatus: async (): Promise => [], findByDateRange: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, }; const resultRepository = { findById: async (): Promise => null, findAll: async (): Promise => results, findByRaceId: async (): Promise => [], findByDriverId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, createMany: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByRaceId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByRaceId: async (): Promise => false, }; const leagueRepository = { findById: async (): Promise => null, findAll: async (): Promise => leagues, findByOwnerId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, searchByName: async (): Promise => [], }; const standingRepository = { findByLeagueId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => null, findAll: async (): Promise => [], save: async (): Promise => { throw new Error('Not implemented'); }, saveMany: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByLeagueId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, recalculate: async (): Promise => [], }; const leagueMembershipRepository = { getMembership: async (leagueId: string, driverIdParam: string): Promise => { return ( memberships.find( m => m.leagueId === leagueId && m.driverId === driverIdParam, ) ?? null ); }, getLeagueMembers: async (): Promise => [], getJoinRequests: async (): Promise => [], saveMembership: async (): Promise => { throw new Error('Not implemented'); }, removeMembership: async (): Promise => { throw new Error('Not implemented'); }, saveJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, removeJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, }; const raceRegistrationRepository = { isRegistered: async (raceId: string, driverIdParam: string): Promise => { if (driverIdParam !== driverId) return false; return registeredRaceIds.has(raceId); }, getRegisteredDrivers: async (): Promise => [], getRegistrationCount: async (): Promise => 0, register: async (): Promise => { throw new Error('Not implemented'); }, withdraw: async (): Promise => { throw new Error('Not implemented'); }, getDriverRegistrations: async (): Promise => [], clearRaceRegistrations: async (): Promise => { throw new Error('Not implemented'); }, }; const feedRepository = { getFeedForDriver: async (): Promise => feedItems, getGlobalFeed: async (): Promise => [], }; const socialRepository = { getFriends: async (): Promise => friends, getFriendIds: async (): Promise => [], getSuggestedFriends: async (): Promise => [], }; const getDriverAvatar = async (id: string): Promise => `avatar-${id}`; const getDriverStats = (id: string) => id === driverId ? { rating: 1600, wins: 5, podiums: 12, totalRaces: 40, overallRank: 42, consistency: 88, } : null; const useCase = new DashboardOverviewUseCase( driverRepository, raceRepository, resultRepository, leagueRepository, standingRepository, leagueMembershipRepository, raceRegistrationRepository, feedRepository, socialRepository, getDriverAvatar, getDriverStats, ); const input: DashboardOverviewInput = { driverId }; const result: UseCaseResult< DashboardOverviewResult, ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }> > = await useCase.execute(input); expect(result.isOk()).toBe(true); const vm = result.unwrap(); expect(vm.myUpcomingRaces.map(r => r.race.id)).toEqual(['race-1', 'race-3']); expect(vm.otherUpcomingRaces.map(r => r.race.id)).toEqual(['race-2', 'race-4']); expect(vm.nextRace).not.toBeNull(); expect(vm.nextRace!.race.id).toBe('race-1'); }); it('builds recentResults sorted by date descending and leagueStandingsSummaries from standings', async () => { const driverId = 'driver-2'; const driver = Driver.create({ id: driverId, iracingId: '67890', name: 'Result Driver', country: 'DE' }); const leagues = [ League.create({ id: 'league-A', name: 'Results League A', description: 'League A', ownerId: 'owner-A' }), League.create({ id: 'league-B', name: 'Results League B', description: 'League B', ownerId: 'owner-B' }), ]; const raceOld = Race.create({ id: 'race-old', leagueId: 'league-A', track: 'Old Circuit', car: 'GT3', scheduledAt: new Date('2024-01-01T10:00:00Z'), status: 'completed', }); const raceNew = Race.create({ id: 'race-new', leagueId: 'league-B', track: 'New Circuit', car: 'GT4', scheduledAt: new Date('2024-02-01T10:00:00Z'), status: 'completed', }); const races = [raceOld, raceNew]; const results: RaceResult[] = [ RaceResult.create({ id: 'result-old', raceId: raceOld.id, driverId, position: 5, fastestLap: 120, incidents: 3, startPosition: 5, }), RaceResult.create({ id: 'result-new', raceId: raceNew.id, driverId, position: 2, fastestLap: 115, incidents: 1, startPosition: 2, }), ]; const memberships = [ LeagueMembership.create({ leagueId: 'league-A', driverId, role: 'member', status: 'active', }), LeagueMembership.create({ leagueId: 'league-B', driverId, role: 'member', status: 'active', }), ]; const standingsByLeague = new Map(); standingsByLeague.set('league-A', [ Standing.create({ leagueId: 'league-A', driverId, position: 3, points: 50 }), Standing.create({ leagueId: 'league-A', driverId: 'other-1', position: 1, points: 80 }), ]); standingsByLeague.set('league-B', [ Standing.create({ leagueId: 'league-B', driverId, position: 1, points: 100 }), Standing.create({ leagueId: 'league-B', driverId: 'other-2', position: 2, points: 90 }), ]); const driverRepository = { findById: async (id: string): Promise => (id === driver.id ? driver : null), findByIRacingId: async (): Promise => null, findAll: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByIRacingId: async (): Promise => false, }; const raceRepository = { findById: async (): Promise => null, findAll: async (): Promise => races, findByLeagueId: async (): Promise => [], findUpcomingByLeagueId: async (): Promise => [], findCompletedByLeagueId: async (): Promise => [], findByStatus: async (): Promise => [], findByDateRange: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, }; const resultRepository = { findById: async (): Promise => null, findAll: async (): Promise => results, findByRaceId: async (): Promise => [], findByDriverId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, createMany: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByRaceId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByRaceId: async (): Promise => false, }; const leagueRepository = { findById: async (): Promise => null, findAll: async (): Promise => leagues, findByOwnerId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, searchByName: async (): Promise => [], }; const standingRepository = { findByLeagueId: async (leagueId: string): Promise => standingsByLeague.get(leagueId) ?? [], findByDriverIdAndLeagueId: async (): Promise => null, findAll: async (): Promise => [], save: async (): Promise => { throw new Error('Not implemented'); }, saveMany: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByLeagueId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, recalculate: async (): Promise => [], }; const leagueMembershipRepository = { getMembership: async (leagueId: string, driverIdParam: string): Promise => { return ( memberships.find( m => m.leagueId === leagueId && m.driverId === driverIdParam, ) ?? null ); }, getLeagueMembers: async (): Promise => [], getJoinRequests: async (): Promise => [], saveMembership: async (): Promise => { throw new Error('Not implemented'); }, removeMembership: async (): Promise => { throw new Error('Not implemented'); }, saveJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, removeJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, }; const raceRegistrationRepository = { isRegistered: async (): Promise => false, getRegisteredDrivers: async (): Promise => [], getRegistrationCount: async (): Promise => 0, register: async (): Promise => { throw new Error('Not implemented'); }, withdraw: async (): Promise => { throw new Error('Not implemented'); }, getDriverRegistrations: async (): Promise => [], clearRaceRegistrations: async (): Promise => { throw new Error('Not implemented'); }, }; const feedRepository = { getFeedForDriver: async (): Promise => [], getGlobalFeed: async (): Promise => [], }; const socialRepository = { getFriends: async (): Promise => [], getFriendIds: async (): Promise => [], getSuggestedFriends: async (): Promise => [], }; const getDriverAvatar = async (id: string): Promise => `avatar-${id}`; const getDriverStats = (id: string) => id === driverId ? { rating: 1800, wins: 3, podiums: 7, totalRaces: 20, overallRank: 10, consistency: 92, } : null; const useCase = new DashboardOverviewUseCase( driverRepository, raceRepository, resultRepository, leagueRepository, standingRepository, leagueMembershipRepository, raceRegistrationRepository, feedRepository, socialRepository, getDriverAvatar, getDriverStats, ); const input: DashboardOverviewInput = { driverId }; const result: UseCaseResult< DashboardOverviewResult, ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }> > = await useCase.execute(input); expect(result.isOk()).toBe(true); const vm = result.unwrap(); expect(vm.recentResults.length).toBe(2); expect(vm.recentResults[0]!.race.id).toBe('race-new'); expect(vm.recentResults[1]!.race.id).toBe('race-old'); const summariesByLeague = new Map( vm.leagueStandingsSummaries.map(s => [s.league.id, s]), ); const summaryA = summariesByLeague.get('league-A'); const summaryB = summariesByLeague.get('league-B'); expect(summaryA).toBeDefined(); expect(summaryA!.standing?.position).toBe(3); expect(summaryA!.standing?.points).toBe(50); expect(summaryA!.totalDrivers).toBe(2); expect(summaryB).toBeDefined(); expect(summaryB!.standing?.position).toBe(1); expect(summaryB!.standing?.points).toBe(100); expect(summaryB!.totalDrivers).toBe(2); }); it('returns empty collections and safe defaults when driver has no races or standings', async () => { const driverId = 'driver-empty'; const driver = Driver.create({ id: driverId, iracingId: '11111', name: 'New Racer', country: 'FR' }); const driverRepository = { findById: async (id: string): Promise => (id === driver.id ? driver : null), findByIRacingId: async (): Promise => null, findAll: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByIRacingId: async (): Promise => false, }; const raceRepository = { findById: async (): Promise => null, findAll: async (): Promise => [], findByLeagueId: async (): Promise => [], findUpcomingByLeagueId: async (): Promise => [], findCompletedByLeagueId: async (): Promise => [], findByStatus: async (): Promise => [], findByDateRange: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, }; const resultRepository = { findById: async (): Promise => null, findAll: async (): Promise => [], findByRaceId: async (): Promise => [], findByDriverId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, createMany: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByRaceId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByRaceId: async (): Promise => false, }; const leagueRepository = { findById: async (): Promise => null, findAll: async (): Promise => [], findByOwnerId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, searchByName: async (): Promise => [], }; const standingRepository = { findByLeagueId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => null, findAll: async (): Promise => [], save: async (): Promise => { throw new Error('Not implemented'); }, saveMany: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByLeagueId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, recalculate: async (): Promise => [], }; const leagueMembershipRepository = { getMembership: async (): Promise => null, getLeagueMembers: async (): Promise => [], getJoinRequests: async (): Promise => [], saveMembership: async (): Promise => { throw new Error('Not implemented'); }, removeMembership: async (): Promise => { throw new Error('Not implemented'); }, saveJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, removeJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, }; const raceRegistrationRepository = { isRegistered: async (): Promise => false, getRegisteredDrivers: async (): Promise => [], getRegistrationCount: async (): Promise => 0, register: async (): Promise => { throw new Error('Not implemented'); }, withdraw: async (): Promise => { throw new Error('Not implemented'); }, getDriverRegistrations: async (): Promise => [], clearRaceRegistrations: async (): Promise => { throw new Error('Not implemented'); }, }; const feedRepository = { getFeedForDriver: async (): Promise => [], getGlobalFeed: async (): Promise => [], }; const socialRepository = { getFriends: async (): Promise => [], getFriendIds: async (): Promise => [], getSuggestedFriends: async (): Promise => [], }; const getDriverAvatar = async (id: string): Promise => `avatar-${id}`; const getDriverStats = () => null; const useCase = new DashboardOverviewUseCase( driverRepository, raceRepository, resultRepository, leagueRepository, standingRepository, leagueMembershipRepository, raceRegistrationRepository, feedRepository, socialRepository, getDriverAvatar, getDriverStats, ); const input: DashboardOverviewInput = { driverId }; const result: UseCaseResult< DashboardOverviewResult, ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }> > = await useCase.execute(input); expect(result.isOk()).toBe(true); const vm = result.unwrap(); expect(vm.myUpcomingRaces).toEqual([]); expect(vm.otherUpcomingRaces).toEqual([]); expect(vm.nextRace).toBeNull(); expect(vm.recentResults).toEqual([]); expect(vm.leagueStandingsSummaries).toEqual([]); expect(vm.friends).toEqual([]); expect(vm.feedSummary.notificationCount).toBe(0); expect(vm.feedSummary.items).toEqual([]); }); it('returns DRIVER_NOT_FOUND error when driver is missing', async () => { const driverId = 'missing-driver'; const driverRepository = { findById: async (): Promise => null, findByIRacingId: async (): Promise => null, findAll: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByIRacingId: async (): Promise => false, }; const raceRepository = { findById: async (): Promise => null, findAll: async (): Promise => [], findByLeagueId: async (): Promise => [], findUpcomingByLeagueId: async (): Promise => [], findCompletedByLeagueId: async (): Promise => [], findByStatus: async (): Promise => [], findByDateRange: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, }; const resultRepository = { findById: async (): Promise => null, findAll: async (): Promise => [], findByRaceId: async (): Promise => [], findByDriverId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, createMany: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByRaceId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByRaceId: async (): Promise => false, }; const leagueRepository = { findById: async (): Promise => null, findAll: async (): Promise => [], findByOwnerId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, searchByName: async (): Promise => [], }; const standingRepository = { findByLeagueId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => null, findAll: async (): Promise => [], save: async (): Promise => { throw new Error('Not implemented'); }, saveMany: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByLeagueId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, recalculate: async (): Promise => [], }; const leagueMembershipRepository = { getMembership: async (): Promise => null, getLeagueMembers: async (): Promise => [], getJoinRequests: async (): Promise => [], saveMembership: async (): Promise => { throw new Error('Not implemented'); }, removeMembership: async (): Promise => { throw new Error('Not implemented'); }, saveJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, removeJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, }; const raceRegistrationRepository = { isRegistered: async (): Promise => false, getRegisteredDrivers: async (): Promise => [], getRegistrationCount: async (): Promise => 0, register: async (): Promise => { throw new Error('Not implemented'); }, withdraw: async (): Promise => { throw new Error('Not implemented'); }, getDriverRegistrations: async (): Promise => [], clearRaceRegistrations: async (): Promise => { throw new Error('Not implemented'); }, }; const feedRepository = { getFeedForDriver: async (): Promise => [], getGlobalFeed: async (): Promise => [], }; const socialRepository = { getFriends: async (): Promise => [], getFriendIds: async (): Promise => [], getSuggestedFriends: async (): Promise => [], }; const getDriverAvatar = async (id: string): Promise => `avatar-${id}`; const getDriverStats = () => null; const useCase = new DashboardOverviewUseCase( driverRepository, raceRepository, resultRepository, leagueRepository, standingRepository, leagueMembershipRepository, raceRegistrationRepository, feedRepository, socialRepository, getDriverAvatar, getDriverStats, ); const input: DashboardOverviewInput = { driverId }; const result: UseCaseResult< DashboardOverviewResult, ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }> > = await useCase.execute(input); expect(result.isErr()).toBe(true); const err = result.unwrapErr(); expect(err.code).toBe('DRIVER_NOT_FOUND'); expect(err.details?.message).toBe('Driver not found'); }); it('returns REPOSITORY_ERROR when an unexpected error occurs', async () => { const driverId = 'driver-error'; const driver = Driver.create({ id: driverId, iracingId: '99999', name: 'Error Driver', country: 'GB' }); const driverRepository = { findById: async (): Promise => driver, findByIRacingId: async (): Promise => null, findAll: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByIRacingId: async (): Promise => false, }; const raceRepository = { findById: async (): Promise => null, findAll: async (): Promise => { throw new Error('DB failure'); }, findByLeagueId: async (): Promise => [], findUpcomingByLeagueId: async (): Promise => [], findCompletedByLeagueId: async (): Promise => [], findByStatus: async (): Promise => [], findByDateRange: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, }; const resultRepository = { findById: async (): Promise => null, findAll: async (): Promise => [], findByRaceId: async (): Promise => [], findByDriverId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, createMany: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByRaceId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, existsByRaceId: async (): Promise => false, }; const leagueRepository = { findById: async (): Promise => null, findAll: async (): Promise => [], findByOwnerId: async (): Promise => [], create: async (): Promise => { throw new Error('Not implemented'); }, update: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, searchByName: async (): Promise => [], }; const standingRepository = { findByLeagueId: async (): Promise => [], findByDriverIdAndLeagueId: async (): Promise => null, findAll: async (): Promise => [], save: async (): Promise => { throw new Error('Not implemented'); }, saveMany: async (): Promise => { throw new Error('Not implemented'); }, delete: async (): Promise => { throw new Error('Not implemented'); }, deleteByLeagueId: async (): Promise => { throw new Error('Not implemented'); }, exists: async (): Promise => false, recalculate: async (): Promise => [], }; const leagueMembershipRepository = { getMembership: async (): Promise => null, getLeagueMembers: async (): Promise => [], getJoinRequests: async (): Promise => [], saveMembership: async (): Promise => { throw new Error('Not implemented'); }, removeMembership: async (): Promise => { throw new Error('Not implemented'); }, saveJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, removeJoinRequest: async (): Promise => { throw new Error('Not implemented'); }, }; const raceRegistrationRepository = { isRegistered: async (): Promise => false, getRegisteredDrivers: async (): Promise => [], getRegistrationCount: async (): Promise => 0, register: async (): Promise => { throw new Error('Not implemented'); }, withdraw: async (): Promise => { throw new Error('Not implemented'); }, getDriverRegistrations: async (): Promise => [], clearRaceRegistrations: async (): Promise => { throw new Error('Not implemented'); }, }; const feedRepository = { getFeedForDriver: async (): Promise => [], getGlobalFeed: async (): Promise => [], }; const socialRepository = { getFriends: async (): Promise => [], getFriendIds: async (): Promise => [], getSuggestedFriends: async (): Promise => [], }; const getDriverAvatar = async (id: string): Promise => `avatar-${id}`; const getDriverStats = () => null; const useCase = new DashboardOverviewUseCase( driverRepository, raceRepository, resultRepository, leagueRepository, standingRepository, leagueMembershipRepository, raceRegistrationRepository, feedRepository, socialRepository, getDriverAvatar, getDriverStats, ); const input: DashboardOverviewInput = { driverId }; const result: UseCaseResult< DashboardOverviewResult, ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }> > = await useCase.execute(input); expect(result.isErr()).toBe(true); const err = result.unwrapErr(); expect(err.code).toBe('REPOSITORY_ERROR'); expect(err.details?.message).toBe('DB failure'); }); });