import { describe, it, expect } from 'vitest'; import { TeamsViewDataBuilder } from './TeamsViewDataBuilder'; describe('TeamsViewDataBuilder', () => { describe('happy paths', () => { it('should transform TeamsPageDto to TeamsViewData correctly', () => { const apiDto = { teams: [ { id: 'team-1', name: 'Racing Team Alpha', memberCount: 15, logoUrl: 'https://example.com/logo1.jpg', rating: 1500, totalWins: 50, totalRaces: 200, region: 'USA', isRecruiting: false, category: 'competitive', performanceLevel: 'elite', description: 'A top-tier racing team', }, { id: 'team-2', name: 'Speed Demons', memberCount: 8, logoUrl: 'https://example.com/logo2.jpg', rating: 1200, totalWins: 20, totalRaces: 150, region: 'UK', isRecruiting: true, category: 'casual', performanceLevel: 'advanced', description: 'Fast and fun', }, ], }; const result = TeamsViewDataBuilder.build(apiDto as any); expect(result.teams).toHaveLength(2); expect(result.teams[0]).toEqual({ teamId: 'team-1', teamName: 'Racing Team Alpha', memberCount: 15, logoUrl: 'https://example.com/logo1.jpg', ratingLabel: '1,500', ratingValue: 1500, winsLabel: '50', racesLabel: '200', region: 'USA', isRecruiting: false, category: 'competitive', performanceLevel: 'elite', description: 'A top-tier racing team', countryCode: 'USA', }); expect(result.teams[1]).toEqual({ teamId: 'team-2', teamName: 'Speed Demons', memberCount: 8, logoUrl: 'https://example.com/logo2.jpg', ratingLabel: '1,200', ratingValue: 1200, winsLabel: '20', racesLabel: '150', region: 'UK', isRecruiting: true, category: 'casual', performanceLevel: 'advanced', description: 'Fast and fun', countryCode: 'UK', }); }); it('should handle empty teams list', () => { const apiDto = { teams: [], }; const result = TeamsViewDataBuilder.build(apiDto as any); expect(result.teams).toHaveLength(0); }); it('should handle teams with missing optional fields', () => { const apiDto = { teams: [ { id: 'team-1', name: 'Minimal Team', memberCount: 5, }, ], }; const result = TeamsViewDataBuilder.build(apiDto as any); expect(result.teams[0].ratingValue).toBe(0); expect(result.teams[0].winsLabel).toBe('0'); expect(result.teams[0].racesLabel).toBe('0'); expect(result.teams[0].logoUrl).toBeUndefined(); }); }); describe('data transformation', () => { it('should preserve all DTO fields in the output', () => { const apiDto = { teams: [ { id: 'team-1', name: 'Test Team', memberCount: 10, rating: 1000, totalWins: 5, totalRaces: 20, region: 'EU', isRecruiting: true, category: 'test', performanceLevel: 'test-level', description: 'test-desc', }, ], }; const result = TeamsViewDataBuilder.build(apiDto as any); expect(result.teams[0].teamId).toBe(apiDto.teams[0].id); expect(result.teams[0].teamName).toBe(apiDto.teams[0].name); expect(result.teams[0].memberCount).toBe(apiDto.teams[0].memberCount); expect(result.teams[0].ratingValue).toBe(apiDto.teams[0].rating); expect(result.teams[0].region).toBe(apiDto.teams[0].region); expect(result.teams[0].isRecruiting).toBe(apiDto.teams[0].isRecruiting); expect(result.teams[0].category).toBe(apiDto.teams[0].category); expect(result.teams[0].performanceLevel).toBe(apiDto.teams[0].performanceLevel); expect(result.teams[0].description).toBe(apiDto.teams[0].description); }); it('should not modify the input DTO', () => { const apiDto = { teams: [ { id: 'team-1', name: 'Test Team', memberCount: 10, }, ], }; const originalDto = JSON.parse(JSON.stringify(apiDto)); TeamsViewDataBuilder.build(apiDto as any); expect(apiDto).toEqual(originalDto); }); }); });