import { describe, it, expect } from 'vitest'; import { DriverProfileViewModelBuilder } from './DriverProfileViewModelBuilder'; import type { GetDriverProfileOutputDTO } from '@/lib/types/generated/GetDriverProfileOutputDTO'; describe('DriverProfileViewModelBuilder', () => { describe('happy paths', () => { it('should transform GetDriverProfileOutputDTO to DriverProfileViewModel correctly', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: 'Test bio', iracingId: 12345, joinedAt: '2024-01-01', globalRank: 100, }, stats: { totalRaces: 50, wins: 10, podiums: 20, dnfs: 5, avgFinish: 5.5, bestFinish: 1, worstFinish: 20, finishRate: 90, winRate: 20, podiumRate: 40, percentile: 95, rating: 1500, consistency: 85, overallRank: 100, }, finishDistribution: { totalRaces: 50, wins: 10, podiums: 20, topTen: 30, dnfs: 5, other: 15, }, teamMemberships: [ { teamId: 'team-1', teamName: 'Test Team', teamTag: 'TT', role: 'driver', joinedAt: '2024-01-01', isCurrent: true, }, ], socialSummary: { friendsCount: 10, friends: [ { id: 'friend-1', name: 'Friend 1', country: 'US', avatarUrl: 'avatar-url', }, ], }, extendedProfile: { socialHandles: [ { platform: 'twitter', handle: '@test', url: 'https://twitter.com/test', }, ], achievements: [ { id: 'ach-1', title: 'Achievement', description: 'Test achievement', icon: 'trophy', rarity: 'rare', earnedAt: '2024-01-01', }, ], racingStyle: 'Aggressive', favoriteTrack: 'Test Track', favoriteCar: 'Test Car', timezone: 'UTC', availableHours: 10, lookingForTeam: true, openToRequests: true, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver).not.toBeNull(); expect(result.currentDriver?.id).toBe('driver-123'); expect(result.currentDriver?.name).toBe('Test Driver'); expect(result.currentDriver?.country).toBe('US'); expect(result.currentDriver?.avatarUrl).toBe('avatar-url'); expect(result.currentDriver?.iracingId).toBe(12345); expect(result.currentDriver?.joinedAt).toBe('2024-01-01'); expect(result.currentDriver?.rating).toBe(1500); expect(result.currentDriver?.globalRank).toBe(100); expect(result.currentDriver?.consistency).toBe(85); expect(result.currentDriver?.bio).toBe('Test bio'); expect(result.currentDriver?.totalDrivers).toBeNull(); expect(result.stats).not.toBeNull(); expect(result.stats?.totalRaces).toBe(50); expect(result.stats?.wins).toBe(10); expect(result.stats?.podiums).toBe(20); expect(result.stats?.dnfs).toBe(5); expect(result.stats?.avgFinish).toBe(5.5); expect(result.stats?.bestFinish).toBe(1); expect(result.stats?.worstFinish).toBe(20); expect(result.stats?.finishRate).toBe(90); expect(result.stats?.winRate).toBe(20); expect(result.stats?.podiumRate).toBe(40); expect(result.stats?.percentile).toBe(95); expect(result.stats?.rating).toBe(1500); expect(result.stats?.consistency).toBe(85); expect(result.stats?.overallRank).toBe(100); expect(result.finishDistribution).not.toBeNull(); expect(result.finishDistribution?.totalRaces).toBe(50); expect(result.finishDistribution?.wins).toBe(10); expect(result.finishDistribution?.podiums).toBe(20); expect(result.finishDistribution?.topTen).toBe(30); expect(result.finishDistribution?.dnfs).toBe(5); expect(result.finishDistribution?.other).toBe(15); expect(result.teamMemberships).toHaveLength(1); expect(result.teamMemberships[0].teamId).toBe('team-1'); expect(result.teamMemberships[0].teamName).toBe('Test Team'); expect(result.teamMemberships[0].teamTag).toBe('TT'); expect(result.teamMemberships[0].role).toBe('driver'); expect(result.teamMemberships[0].joinedAt).toBe('2024-01-01'); expect(result.teamMemberships[0].isCurrent).toBe(true); expect(result.socialSummary).not.toBeNull(); expect(result.socialSummary?.friendsCount).toBe(10); expect(result.socialSummary?.friends).toHaveLength(1); expect(result.socialSummary?.friends[0].id).toBe('friend-1'); expect(result.socialSummary?.friends[0].name).toBe('Friend 1'); expect(result.socialSummary?.friends[0].country).toBe('US'); expect(result.socialSummary?.friends[0].avatarUrl).toBe('avatar-url'); expect(result.extendedProfile).not.toBeNull(); expect(result.extendedProfile?.socialHandles).toHaveLength(1); expect(result.extendedProfile?.socialHandles[0].platform).toBe('twitter'); expect(result.extendedProfile?.socialHandles[0].handle).toBe('@test'); expect(result.extendedProfile?.socialHandles[0].url).toBe('https://twitter.com/test'); expect(result.extendedProfile?.achievements).toHaveLength(1); expect(result.extendedProfile?.achievements[0].id).toBe('ach-1'); expect(result.extendedProfile?.achievements[0].title).toBe('Achievement'); expect(result.extendedProfile?.achievements[0].description).toBe('Test achievement'); expect(result.extendedProfile?.achievements[0].icon).toBe('trophy'); expect(result.extendedProfile?.achievements[0].rarity).toBe('rare'); expect(result.extendedProfile?.achievements[0].earnedAt).toBe('2024-01-01'); expect(result.extendedProfile?.racingStyle).toBe('Aggressive'); expect(result.extendedProfile?.favoriteTrack).toBe('Test Track'); expect(result.extendedProfile?.favoriteCar).toBe('Test Car'); expect(result.extendedProfile?.timezone).toBe('UTC'); expect(result.extendedProfile?.availableHours).toBe(10); expect(result.extendedProfile?.lookingForTeam).toBe(true); expect(result.extendedProfile?.openToRequests).toBe(true); }); it('should handle null driver (no profile)', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: null, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver).toBeNull(); expect(result.stats).toBeNull(); expect(result.finishDistribution).toBeNull(); expect(result.teamMemberships).toHaveLength(0); expect(result.socialSummary).not.toBeNull(); expect(result.socialSummary?.friendsCount).toBe(0); expect(result.socialSummary?.friends).toHaveLength(0); expect(result.extendedProfile).toBeNull(); }); it('should handle null stats', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.stats).toBeNull(); }); it('should handle null finish distribution', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: { totalRaces: 50, wins: 10, podiums: 20, dnfs: 5, avgFinish: 5.5, bestFinish: 1, worstFinish: 20, finishRate: 90, winRate: 20, podiumRate: 40, percentile: 95, rating: 1500, consistency: 85, overallRank: 100, }, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.finishDistribution).toBeNull(); }); it('should handle null extended profile', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile).toBeNull(); }); }); describe('data transformation', () => { it('should preserve all DTO fields in the output', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: 'Test bio', iracingId: 12345, joinedAt: '2024-01-01', globalRank: 100, }, stats: { totalRaces: 50, wins: 10, podiums: 20, dnfs: 5, avgFinish: 5.5, bestFinish: 1, worstFinish: 20, finishRate: 90, winRate: 20, podiumRate: 40, percentile: 95, rating: 1500, consistency: 85, overallRank: 100, }, finishDistribution: { totalRaces: 50, wins: 10, podiums: 20, topTen: 30, dnfs: 5, other: 15, }, teamMemberships: [ { teamId: 'team-1', teamName: 'Test Team', teamTag: 'TT', role: 'driver', joinedAt: '2024-01-01', isCurrent: true, }, ], socialSummary: { friendsCount: 10, friends: [ { id: 'friend-1', name: 'Friend 1', country: 'US', avatarUrl: 'avatar-url', }, ], }, extendedProfile: { socialHandles: [ { platform: 'twitter', handle: '@test', url: 'https://twitter.com/test', }, ], achievements: [ { id: 'ach-1', title: 'Achievement', description: 'Test achievement', icon: 'trophy', rarity: 'rare', earnedAt: '2024-01-01', }, ], racingStyle: 'Aggressive', favoriteTrack: 'Test Track', favoriteCar: 'Test Car', timezone: 'UTC', availableHours: 10, lookingForTeam: true, openToRequests: true, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver?.id).toBe(driverProfileDto.currentDriver?.id); expect(result.currentDriver?.name).toBe(driverProfileDto.currentDriver?.name); expect(result.currentDriver?.country).toBe(driverProfileDto.currentDriver?.country); expect(result.currentDriver?.avatarUrl).toBe(driverProfileDto.currentDriver?.avatarUrl); expect(result.currentDriver?.iracingId).toBe(driverProfileDto.currentDriver?.iracingId); expect(result.currentDriver?.joinedAt).toBe(driverProfileDto.currentDriver?.joinedAt); expect(result.currentDriver?.rating).toBe(driverProfileDto.currentDriver?.rating); expect(result.currentDriver?.globalRank).toBe(driverProfileDto.currentDriver?.globalRank); expect(result.currentDriver?.consistency).toBe(driverProfileDto.currentDriver?.consistency); expect(result.currentDriver?.bio).toBe(driverProfileDto.currentDriver?.bio); expect(result.stats?.totalRaces).toBe(driverProfileDto.stats?.totalRaces); expect(result.stats?.wins).toBe(driverProfileDto.stats?.wins); expect(result.stats?.podiums).toBe(driverProfileDto.stats?.podiums); expect(result.stats?.dnfs).toBe(driverProfileDto.stats?.dnfs); expect(result.stats?.avgFinish).toBe(driverProfileDto.stats?.avgFinish); expect(result.stats?.bestFinish).toBe(driverProfileDto.stats?.bestFinish); expect(result.stats?.worstFinish).toBe(driverProfileDto.stats?.worstFinish); expect(result.stats?.finishRate).toBe(driverProfileDto.stats?.finishRate); expect(result.stats?.winRate).toBe(driverProfileDto.stats?.winRate); expect(result.stats?.podiumRate).toBe(driverProfileDto.stats?.podiumRate); expect(result.stats?.percentile).toBe(driverProfileDto.stats?.percentile); expect(result.stats?.rating).toBe(driverProfileDto.stats?.rating); expect(result.stats?.consistency).toBe(driverProfileDto.stats?.consistency); expect(result.stats?.overallRank).toBe(driverProfileDto.stats?.overallRank); expect(result.finishDistribution?.totalRaces).toBe(driverProfileDto.finishDistribution?.totalRaces); expect(result.finishDistribution?.wins).toBe(driverProfileDto.finishDistribution?.wins); expect(result.finishDistribution?.podiums).toBe(driverProfileDto.finishDistribution?.podiums); expect(result.finishDistribution?.topTen).toBe(driverProfileDto.finishDistribution?.topTen); expect(result.finishDistribution?.dnfs).toBe(driverProfileDto.finishDistribution?.dnfs); expect(result.finishDistribution?.other).toBe(driverProfileDto.finishDistribution?.other); expect(result.teamMemberships).toHaveLength(1); expect(result.teamMemberships[0].teamId).toBe(driverProfileDto.teamMemberships[0].teamId); expect(result.teamMemberships[0].teamName).toBe(driverProfileDto.teamMemberships[0].teamName); expect(result.teamMemberships[0].teamTag).toBe(driverProfileDto.teamMemberships[0].teamTag); expect(result.teamMemberships[0].role).toBe(driverProfileDto.teamMemberships[0].role); expect(result.teamMemberships[0].joinedAt).toBe(driverProfileDto.teamMemberships[0].joinedAt); expect(result.teamMemberships[0].isCurrent).toBe(driverProfileDto.teamMemberships[0].isCurrent); expect(result.socialSummary?.friendsCount).toBe(driverProfileDto.socialSummary.friendsCount); expect(result.socialSummary?.friends).toHaveLength(1); expect(result.socialSummary?.friends[0].id).toBe(driverProfileDto.socialSummary.friends[0].id); expect(result.socialSummary?.friends[0].name).toBe(driverProfileDto.socialSummary.friends[0].name); expect(result.socialSummary?.friends[0].country).toBe(driverProfileDto.socialSummary.friends[0].country); expect(result.socialSummary?.friends[0].avatarUrl).toBe(driverProfileDto.socialSummary.friends[0].avatarUrl); expect(result.extendedProfile?.socialHandles).toHaveLength(1); expect(result.extendedProfile?.socialHandles[0].platform).toBe(driverProfileDto.extendedProfile?.socialHandles[0].platform); expect(result.extendedProfile?.socialHandles[0].handle).toBe(driverProfileDto.extendedProfile?.socialHandles[0].handle); expect(result.extendedProfile?.socialHandles[0].url).toBe(driverProfileDto.extendedProfile?.socialHandles[0].url); expect(result.extendedProfile?.achievements).toHaveLength(1); expect(result.extendedProfile?.achievements[0].id).toBe(driverProfileDto.extendedProfile?.achievements[0].id); expect(result.extendedProfile?.achievements[0].title).toBe(driverProfileDto.extendedProfile?.achievements[0].title); expect(result.extendedProfile?.achievements[0].description).toBe(driverProfileDto.extendedProfile?.achievements[0].description); expect(result.extendedProfile?.achievements[0].icon).toBe(driverProfileDto.extendedProfile?.achievements[0].icon); expect(result.extendedProfile?.achievements[0].rarity).toBe(driverProfileDto.extendedProfile?.achievements[0].rarity); expect(result.extendedProfile?.achievements[0].earnedAt).toBe(driverProfileDto.extendedProfile?.achievements[0].earnedAt); expect(result.extendedProfile?.racingStyle).toBe(driverProfileDto.extendedProfile?.racingStyle); expect(result.extendedProfile?.favoriteTrack).toBe(driverProfileDto.extendedProfile?.favoriteTrack); expect(result.extendedProfile?.favoriteCar).toBe(driverProfileDto.extendedProfile?.favoriteCar); expect(result.extendedProfile?.timezone).toBe(driverProfileDto.extendedProfile?.timezone); expect(result.extendedProfile?.availableHours).toBe(driverProfileDto.extendedProfile?.availableHours); expect(result.extendedProfile?.lookingForTeam).toBe(driverProfileDto.extendedProfile?.lookingForTeam); expect(result.extendedProfile?.openToRequests).toBe(driverProfileDto.extendedProfile?.openToRequests); }); it('should not modify the input DTO', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: 'Test bio', iracingId: 12345, joinedAt: '2024-01-01', globalRank: 100, }, stats: { totalRaces: 50, wins: 10, podiums: 20, dnfs: 5, avgFinish: 5.5, bestFinish: 1, worstFinish: 20, finishRate: 90, winRate: 20, podiumRate: 40, percentile: 95, rating: 1500, consistency: 85, overallRank: 100, }, finishDistribution: { totalRaces: 50, wins: 10, podiums: 20, topTen: 30, dnfs: 5, other: 15, }, teamMemberships: [ { teamId: 'team-1', teamName: 'Test Team', teamTag: 'TT', role: 'driver', joinedAt: '2024-01-01', isCurrent: true, }, ], socialSummary: { friendsCount: 10, friends: [ { id: 'friend-1', name: 'Friend 1', country: 'US', avatarUrl: 'avatar-url', }, ], }, extendedProfile: { socialHandles: [ { platform: 'twitter', handle: '@test', url: 'https://twitter.com/test', }, ], achievements: [ { id: 'ach-1', title: 'Achievement', description: 'Test achievement', icon: 'trophy', rarity: 'rare', earnedAt: '2024-01-01', }, ], racingStyle: 'Aggressive', favoriteTrack: 'Test Track', favoriteCar: 'Test Car', timezone: 'UTC', availableHours: 10, lookingForTeam: true, openToRequests: true, }, }; const originalDto = { ...driverProfileDto }; DriverProfileViewModelBuilder.build(driverProfileDto); expect(driverProfileDto).toEqual(originalDto); }); }); describe('edge cases', () => { it('should handle driver without avatar', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: null, bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver?.avatarUrl).toBe(''); }); it('should handle driver without iracingId', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver?.iracingId).toBeNull(); }); it('should handle driver without global rank', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver?.globalRank).toBeNull(); }); it('should handle driver without rating', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, rating: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver?.rating).toBeNull(); }); it('should handle driver without consistency', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, consistency: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver?.consistency).toBeNull(); }); it('should handle driver without bio', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.currentDriver?.bio).toBeNull(); }); it('should handle stats without avgFinish', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: { totalRaces: 50, wins: 10, podiums: 20, dnfs: 5, avgFinish: null, bestFinish: null, worstFinish: null, finishRate: null, winRate: null, podiumRate: null, percentile: null, rating: null, consistency: null, overallRank: null, }, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.stats?.avgFinish).toBeNull(); expect(result.stats?.bestFinish).toBeNull(); expect(result.stats?.worstFinish).toBeNull(); expect(result.stats?.finishRate).toBeNull(); expect(result.stats?.winRate).toBeNull(); expect(result.stats?.podiumRate).toBeNull(); expect(result.stats?.percentile).toBeNull(); expect(result.stats?.rating).toBeNull(); expect(result.stats?.consistency).toBeNull(); expect(result.stats?.overallRank).toBeNull(); }); it('should handle empty team memberships', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.teamMemberships).toHaveLength(0); }); it('should handle team membership without teamTag', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [ { teamId: 'team-1', teamName: 'Test Team', teamTag: null, role: 'driver', joinedAt: '2024-01-01', isCurrent: true, }, ], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.teamMemberships[0].teamTag).toBeNull(); }); it('should handle empty friends list', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.socialSummary?.friends).toHaveLength(0); expect(result.socialSummary?.friendsCount).toBe(0); }); it('should handle friend without avatar', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 1, friends: [ { id: 'friend-1', name: 'Friend 1', country: 'US', avatarUrl: null, }, ], }, extendedProfile: null, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.socialSummary?.friends[0].avatarUrl).toBe(''); }); it('should handle empty social handles', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.socialHandles).toHaveLength(0); }); it('should handle empty achievements', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.achievements).toHaveLength(0); }); it('should handle achievement without icon', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [ { id: 'ach-1', title: 'Achievement', description: 'Test achievement', icon: null, rarity: 'rare', earnedAt: '2024-01-01', }, ], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.achievements[0].icon).toBeNull(); }); it('should handle achievement without rarity', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [ { id: 'ach-1', title: 'Achievement', description: 'Test achievement', icon: 'trophy', rarity: null, earnedAt: '2024-01-01', }, ], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.achievements[0].rarity).toBeNull(); }); it('should handle extended profile without racingStyle', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.racingStyle).toBeNull(); }); it('should handle extended profile without favoriteTrack', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.favoriteTrack).toBeNull(); }); it('should handle extended profile without favoriteCar', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.favoriteCar).toBeNull(); }); it('should handle extended profile without timezone', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.timezone).toBeNull(); }); it('should handle extended profile without availableHours', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.availableHours).toBeNull(); }); it('should handle extended profile with lookingForTeam false', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.lookingForTeam).toBe(false); }); it('should handle extended profile with openToRequests false', () => { const driverProfileDto: GetDriverProfileOutputDTO = { currentDriver: { id: 'driver-123', name: 'Test Driver', country: 'US', avatarUrl: 'avatar-url', bio: null, iracingId: null, joinedAt: '2024-01-01', globalRank: null, }, stats: null, finishDistribution: null, teamMemberships: [], socialSummary: { friendsCount: 0, friends: [], }, extendedProfile: { socialHandles: [], achievements: [], racingStyle: null, favoriteTrack: null, favoriteCar: null, timezone: null, availableHours: null, lookingForTeam: false, openToRequests: false, }, }; const result = DriverProfileViewModelBuilder.build(driverProfileDto); expect(result.extendedProfile?.openToRequests).toBe(false); }); }); });