view data fixes
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
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 = {
|
||||
const apiDto: GetAllTeamsOutputDTO = {
|
||||
teams: [
|
||||
{
|
||||
id: 'team-1',
|
||||
@@ -19,6 +20,7 @@ describe('TeamsViewDataBuilder', () => {
|
||||
category: 'competitive',
|
||||
performanceLevel: 'elite',
|
||||
description: 'A top-tier racing team',
|
||||
createdAt: '2023-01-01',
|
||||
},
|
||||
{
|
||||
id: 'team-2',
|
||||
@@ -33,11 +35,12 @@ describe('TeamsViewDataBuilder', () => {
|
||||
category: 'casual',
|
||||
performanceLevel: 'advanced',
|
||||
description: 'Fast and fun',
|
||||
createdAt: '2023-01-01',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = TeamsViewDataBuilder.build(apiDto as any);
|
||||
const result = TeamsViewDataBuilder.build(apiDto);
|
||||
|
||||
expect(result.teams).toHaveLength(2);
|
||||
expect(result.teams[0]).toEqual({
|
||||
@@ -75,38 +78,39 @@ describe('TeamsViewDataBuilder', () => {
|
||||
});
|
||||
|
||||
it('should handle empty teams list', () => {
|
||||
const apiDto = {
|
||||
const apiDto: GetAllTeamsOutputDTO = {
|
||||
teams: [],
|
||||
};
|
||||
|
||||
const result = TeamsViewDataBuilder.build(apiDto as any);
|
||||
const result = TeamsViewDataBuilder.build(apiDto);
|
||||
|
||||
expect(result.teams).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should handle teams with missing optional fields', () => {
|
||||
const apiDto = {
|
||||
const apiDto: GetAllTeamsOutputDTO = {
|
||||
teams: [
|
||||
{
|
||||
id: 'team-1',
|
||||
name: 'Minimal Team',
|
||||
memberCount: 5,
|
||||
createdAt: '2023-01-01',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = TeamsViewDataBuilder.build(apiDto as any);
|
||||
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).toBeUndefined();
|
||||
expect(result.teams[0].logoUrl).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('data transformation', () => {
|
||||
it('should preserve all DTO fields in the output', () => {
|
||||
const apiDto = {
|
||||
const apiDto: GetAllTeamsOutputDTO = {
|
||||
teams: [
|
||||
{
|
||||
id: 'team-1',
|
||||
@@ -120,11 +124,12 @@ describe('TeamsViewDataBuilder', () => {
|
||||
category: 'test',
|
||||
performanceLevel: 'test-level',
|
||||
description: 'test-desc',
|
||||
createdAt: '2023-01-01',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = TeamsViewDataBuilder.build(apiDto as any);
|
||||
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);
|
||||
@@ -138,18 +143,19 @@ describe('TeamsViewDataBuilder', () => {
|
||||
});
|
||||
|
||||
it('should not modify the input DTO', () => {
|
||||
const apiDto = {
|
||||
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 as any);
|
||||
TeamsViewDataBuilder.build(apiDto);
|
||||
|
||||
expect(apiDto).toEqual(originalDto);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user