164 lines
4.9 KiB
TypeScript
164 lines
4.9 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { TeamsViewDataBuilder } from './TeamsViewDataBuilder';
|
|
import type { GetAllTeamsOutputDTO } from '@/lib/types/generated/GetAllTeamsOutputDTO';
|
|
|
|
describe('TeamsViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform TeamsPageDto to TeamsViewData correctly', () => {
|
|
const apiDto: GetAllTeamsOutputDTO = {
|
|
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',
|
|
createdAt: '2023-01-01',
|
|
},
|
|
{
|
|
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',
|
|
createdAt: '2023-01-01',
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = TeamsViewDataBuilder.build(apiDto);
|
|
|
|
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: GetAllTeamsOutputDTO = {
|
|
teams: [],
|
|
};
|
|
|
|
const result = TeamsViewDataBuilder.build(apiDto);
|
|
|
|
expect(result.teams).toHaveLength(0);
|
|
});
|
|
|
|
it('should handle teams with missing optional fields', () => {
|
|
const apiDto: GetAllTeamsOutputDTO = {
|
|
teams: [
|
|
{
|
|
id: 'team-1',
|
|
name: 'Minimal Team',
|
|
memberCount: 5,
|
|
createdAt: '2023-01-01',
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = TeamsViewDataBuilder.build(apiDto);
|
|
|
|
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).toBe('');
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const apiDto: GetAllTeamsOutputDTO = {
|
|
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',
|
|
createdAt: '2023-01-01',
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = TeamsViewDataBuilder.build(apiDto);
|
|
|
|
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: GetAllTeamsOutputDTO = {
|
|
teams: [
|
|
{
|
|
id: 'team-1',
|
|
name: 'Test Team',
|
|
memberCount: 10,
|
|
createdAt: '2023-01-01',
|
|
},
|
|
],
|
|
};
|
|
|
|
const originalDto = JSON.parse(JSON.stringify(apiDto));
|
|
TeamsViewDataBuilder.build(apiDto);
|
|
|
|
expect(apiDto).toEqual(originalDto);
|
|
});
|
|
});
|
|
});
|