view data fixes
This commit is contained in:
@@ -1,34 +1,33 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { HomeViewDataBuilder } from './HomeViewDataBuilder';
|
||||
import type { HomeDataDTO } from '@/lib/types/dtos/HomeDataDTO';
|
||||
import type { DashboardOverviewDTO } from '@/lib/types/generated/DashboardOverviewDTO';
|
||||
|
||||
describe('HomeViewDataBuilder', () => {
|
||||
describe('happy paths', () => {
|
||||
it('should transform HomeDataDTO to HomeViewData correctly', () => {
|
||||
const homeDataDto: HomeDataDTO = {
|
||||
isAlpha: true,
|
||||
it('should transform DashboardOverviewDTO to HomeViewData correctly', () => {
|
||||
const homeDataDto: DashboardOverviewDTO = {
|
||||
currentDriver: null,
|
||||
upcomingRaces: [
|
||||
{
|
||||
id: 'race-1',
|
||||
name: 'Test Race',
|
||||
scheduledAt: '2024-01-01T10:00:00Z',
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
scheduledAt: '2024-01-01T10:00:00Z',
|
||||
isMyLeague: false,
|
||||
},
|
||||
],
|
||||
topLeagues: [
|
||||
leagueStandingsSummaries: [
|
||||
{
|
||||
id: 'league-1',
|
||||
name: 'Test League',
|
||||
description: 'Test Description',
|
||||
},
|
||||
],
|
||||
teams: [
|
||||
{
|
||||
id: 'team-1',
|
||||
name: 'Test Team',
|
||||
tag: 'TT',
|
||||
leagueId: 'league-1',
|
||||
leagueName: 'Test League',
|
||||
position: 1,
|
||||
points: 100,
|
||||
totalDrivers: 20,
|
||||
},
|
||||
],
|
||||
feedSummary: { items: [] },
|
||||
friends: [],
|
||||
activeLeaguesCount: 1,
|
||||
};
|
||||
|
||||
const result = HomeViewDataBuilder.build(homeDataDto);
|
||||
@@ -38,130 +37,58 @@ describe('HomeViewDataBuilder', () => {
|
||||
upcomingRaces: [
|
||||
{
|
||||
id: 'race-1',
|
||||
name: 'Test Race',
|
||||
scheduledAt: '2024-01-01T10:00:00Z',
|
||||
track: 'Test Track',
|
||||
car: 'Test Car',
|
||||
formattedDate: 'Mon, Jan 1, 2024',
|
||||
},
|
||||
],
|
||||
topLeagues: [
|
||||
{
|
||||
id: 'league-1',
|
||||
name: 'Test League',
|
||||
description: 'Test Description',
|
||||
},
|
||||
],
|
||||
teams: [
|
||||
{
|
||||
id: 'team-1',
|
||||
name: 'Test Team',
|
||||
tag: 'TT',
|
||||
description: '',
|
||||
},
|
||||
],
|
||||
teams: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty arrays correctly', () => {
|
||||
const homeDataDto: HomeDataDTO = {
|
||||
isAlpha: false,
|
||||
const homeDataDto: DashboardOverviewDTO = {
|
||||
currentDriver: null,
|
||||
upcomingRaces: [],
|
||||
topLeagues: [],
|
||||
teams: [],
|
||||
leagueStandingsSummaries: [],
|
||||
feedSummary: { items: [] },
|
||||
friends: [],
|
||||
activeLeaguesCount: 0,
|
||||
};
|
||||
|
||||
const result = HomeViewDataBuilder.build(homeDataDto);
|
||||
|
||||
expect(result).toEqual({
|
||||
isAlpha: false,
|
||||
isAlpha: true,
|
||||
upcomingRaces: [],
|
||||
topLeagues: [],
|
||||
teams: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle multiple items in arrays', () => {
|
||||
const homeDataDto: HomeDataDTO = {
|
||||
isAlpha: true,
|
||||
upcomingRaces: [
|
||||
{ id: 'race-1', name: 'Race 1', scheduledAt: '2024-01-01T10:00:00Z', track: 'Track 1' },
|
||||
{ id: 'race-2', name: 'Race 2', scheduledAt: '2024-01-02T10:00:00Z', track: 'Track 2' },
|
||||
],
|
||||
topLeagues: [
|
||||
{ id: 'league-1', name: 'League 1', description: 'Description 1' },
|
||||
{ id: 'league-2', name: 'League 2', description: 'Description 2' },
|
||||
],
|
||||
teams: [
|
||||
{ id: 'team-1', name: 'Team 1', tag: 'T1' },
|
||||
{ id: 'team-2', name: 'Team 2', tag: 'T2' },
|
||||
],
|
||||
};
|
||||
|
||||
const result = HomeViewDataBuilder.build(homeDataDto);
|
||||
|
||||
expect(result.upcomingRaces).toHaveLength(2);
|
||||
expect(result.topLeagues).toHaveLength(2);
|
||||
expect(result.teams).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('data transformation', () => {
|
||||
it('should preserve all DTO fields in the output', () => {
|
||||
const homeDataDto: HomeDataDTO = {
|
||||
isAlpha: true,
|
||||
upcomingRaces: [{ id: 'race-1', name: 'Race', scheduledAt: '2024-01-01T10:00:00Z', track: 'Track' }],
|
||||
topLeagues: [{ id: 'league-1', name: 'League', description: 'Description' }],
|
||||
teams: [{ id: 'team-1', name: 'Team', tag: 'T' }],
|
||||
};
|
||||
|
||||
const result = HomeViewDataBuilder.build(homeDataDto);
|
||||
|
||||
expect(result.isAlpha).toBe(homeDataDto.isAlpha);
|
||||
expect(result.upcomingRaces).toEqual(homeDataDto.upcomingRaces);
|
||||
expect(result.topLeagues).toEqual(homeDataDto.topLeagues);
|
||||
expect(result.teams).toEqual(homeDataDto.teams);
|
||||
});
|
||||
|
||||
it('should not modify the input DTO', () => {
|
||||
const homeDataDto: HomeDataDTO = {
|
||||
isAlpha: true,
|
||||
upcomingRaces: [{ id: 'race-1', name: 'Race', scheduledAt: '2024-01-01T10:00:00Z', track: 'Track' }],
|
||||
topLeagues: [{ id: 'league-1', name: 'League', description: 'Description' }],
|
||||
teams: [{ id: 'team-1', name: 'Team', tag: 'T' }],
|
||||
const homeDataDto: DashboardOverviewDTO = {
|
||||
currentDriver: null,
|
||||
upcomingRaces: [{ id: 'race-1', track: 'Track', car: 'Car', scheduledAt: '2024-01-01T10:00:00Z', isMyLeague: false }],
|
||||
leagueStandingsSummaries: [{ leagueId: 'league-1', leagueName: 'League', position: 1, points: 10, totalDrivers: 10 }],
|
||||
feedSummary: { items: [] },
|
||||
friends: [],
|
||||
activeLeaguesCount: 1,
|
||||
};
|
||||
|
||||
const originalDto = { ...homeDataDto };
|
||||
const originalDto = JSON.parse(JSON.stringify(homeDataDto));
|
||||
HomeViewDataBuilder.build(homeDataDto);
|
||||
|
||||
expect(homeDataDto).toEqual(originalDto);
|
||||
});
|
||||
});
|
||||
|
||||
describe('edge cases', () => {
|
||||
it('should handle false isAlpha value', () => {
|
||||
const homeDataDto: HomeDataDTO = {
|
||||
isAlpha: false,
|
||||
upcomingRaces: [],
|
||||
topLeagues: [],
|
||||
teams: [],
|
||||
};
|
||||
|
||||
const result = HomeViewDataBuilder.build(homeDataDto);
|
||||
|
||||
expect(result.isAlpha).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle null/undefined values in arrays', () => {
|
||||
const homeDataDto: HomeDataDTO = {
|
||||
isAlpha: true,
|
||||
upcomingRaces: [{ id: 'race-1', name: 'Race', scheduledAt: '2024-01-01T10:00:00Z', track: 'Track' }],
|
||||
topLeagues: [{ id: 'league-1', name: 'League', description: 'Description' }],
|
||||
teams: [{ id: 'team-1', name: 'Team', tag: 'T' }],
|
||||
};
|
||||
|
||||
const result = HomeViewDataBuilder.build(homeDataDto);
|
||||
|
||||
expect(result.upcomingRaces[0].id).toBe('race-1');
|
||||
expect(result.topLeagues[0].id).toBe('league-1');
|
||||
expect(result.teams[0].id).toBe('team-1');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user