95 lines
2.6 KiB
TypeScript
95 lines
2.6 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { HomeViewDataBuilder } from './HomeViewDataBuilder';
|
|
import type { DashboardOverviewDTO } from '@/lib/types/generated/DashboardOverviewDTO';
|
|
|
|
describe('HomeViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform DashboardOverviewDTO to HomeViewData correctly', () => {
|
|
const homeDataDto: DashboardOverviewDTO = {
|
|
currentDriver: null,
|
|
upcomingRaces: [
|
|
{
|
|
id: 'race-1',
|
|
track: 'Test Track',
|
|
car: 'Test Car',
|
|
scheduledAt: '2024-01-01T10:00:00Z',
|
|
isMyLeague: false,
|
|
},
|
|
],
|
|
leagueStandingsSummaries: [
|
|
{
|
|
leagueId: 'league-1',
|
|
leagueName: 'Test League',
|
|
position: 1,
|
|
points: 100,
|
|
totalDrivers: 20,
|
|
},
|
|
],
|
|
feedSummary: { items: [] },
|
|
friends: [],
|
|
activeLeaguesCount: 1,
|
|
};
|
|
|
|
const result = HomeViewDataBuilder.build(homeDataDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlpha: true,
|
|
upcomingRaces: [
|
|
{
|
|
id: 'race-1',
|
|
track: 'Test Track',
|
|
car: 'Test Car',
|
|
formattedDate: 'Mon, Jan 1, 2024',
|
|
},
|
|
],
|
|
topLeagues: [
|
|
{
|
|
id: 'league-1',
|
|
name: 'Test League',
|
|
description: '',
|
|
},
|
|
],
|
|
teams: [],
|
|
});
|
|
});
|
|
|
|
it('should handle empty arrays correctly', () => {
|
|
const homeDataDto: DashboardOverviewDTO = {
|
|
currentDriver: null,
|
|
upcomingRaces: [],
|
|
leagueStandingsSummaries: [],
|
|
feedSummary: { items: [] },
|
|
friends: [],
|
|
activeLeaguesCount: 0,
|
|
};
|
|
|
|
const result = HomeViewDataBuilder.build(homeDataDto);
|
|
|
|
expect(result).toEqual({
|
|
isAlpha: true,
|
|
upcomingRaces: [],
|
|
topLeagues: [],
|
|
teams: [],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should not modify the input DTO', () => {
|
|
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 = JSON.parse(JSON.stringify(homeDataDto));
|
|
HomeViewDataBuilder.build(homeDataDto);
|
|
|
|
expect(homeDataDto).toEqual(originalDto);
|
|
});
|
|
});
|
|
});
|