128 lines
3.1 KiB
TypeScript
128 lines
3.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { DriverProfileViewModel } from './DriverProfileViewModel';
|
|
|
|
const createDriverProfileDto = (): DriverProfileViewModel => ({
|
|
currentDriver: {
|
|
id: 'driver-1',
|
|
name: 'Test Driver',
|
|
country: 'DE',
|
|
avatarUrl: 'https://example.com/avatar.jpg',
|
|
iracingId: 'ir-123',
|
|
joinedAt: '2024-01-01T00:00:00Z',
|
|
rating: 2500,
|
|
globalRank: 42,
|
|
consistency: 88,
|
|
bio: 'Test bio',
|
|
totalDrivers: 1000,
|
|
},
|
|
stats: {
|
|
totalRaces: 10,
|
|
wins: 3,
|
|
podiums: 5,
|
|
dnfs: 1,
|
|
avgFinish: 4.2,
|
|
bestFinish: 1,
|
|
worstFinish: 15,
|
|
finishRate: 90,
|
|
winRate: 30,
|
|
podiumRate: 50,
|
|
percentile: 95,
|
|
rating: 2500,
|
|
consistency: 88,
|
|
overallRank: 10,
|
|
},
|
|
finishDistribution: {
|
|
totalRaces: 10,
|
|
wins: 3,
|
|
podiums: 5,
|
|
topTen: 8,
|
|
dnfs: 1,
|
|
other: 1,
|
|
},
|
|
teamMemberships: [
|
|
{
|
|
teamId: 'team-1',
|
|
teamName: 'Test Team',
|
|
teamTag: 'TT',
|
|
role: 'driver',
|
|
joinedAt: '2023-01-01T00:00:00Z',
|
|
isCurrent: true,
|
|
},
|
|
],
|
|
socialSummary: {
|
|
friendsCount: 5,
|
|
friends: [
|
|
{
|
|
id: 'friend-1',
|
|
name: 'Friend 1',
|
|
country: 'US',
|
|
avatarUrl: 'https://example.com/friend.jpg',
|
|
},
|
|
],
|
|
},
|
|
extendedProfile: {
|
|
socialHandles: [
|
|
{
|
|
platform: 'twitter',
|
|
handle: '@test',
|
|
url: 'https://twitter.com/test',
|
|
},
|
|
],
|
|
achievements: [
|
|
{
|
|
id: 'ach-1',
|
|
title: 'Champion',
|
|
description: 'Won a championship',
|
|
icon: 'trophy',
|
|
rarity: 'epic',
|
|
earnedAt: '2024-01-10T00:00:00Z',
|
|
},
|
|
],
|
|
racingStyle: 'Aggressive',
|
|
favoriteTrack: 'Spa',
|
|
favoriteCar: 'F3',
|
|
timezone: 'Europe/Berlin',
|
|
availableHours: 'Evenings',
|
|
lookingForTeam: false,
|
|
openToRequests: true,
|
|
},
|
|
});
|
|
|
|
describe('DriverProfileViewModel', () => {
|
|
it('exposes profile sections from DTO', () => {
|
|
const dto = createDriverProfileDto();
|
|
const viewModel = new DriverProfileViewModel(dto);
|
|
|
|
expect(viewModel.currentDriver).toEqual(dto.currentDriver);
|
|
expect(viewModel.stats).toEqual(dto.stats);
|
|
expect(viewModel.finishDistribution).toEqual(dto.finishDistribution);
|
|
expect(viewModel.teamMemberships).toEqual(dto.teamMemberships);
|
|
expect(viewModel.socialSummary).toEqual(dto.socialSummary);
|
|
expect(viewModel.extendedProfile).toEqual(dto.extendedProfile);
|
|
});
|
|
|
|
it('supports nullable sections', () => {
|
|
const dto: DriverProfileViewModel = {
|
|
...createDriverProfileDto(),
|
|
currentDriver: null,
|
|
stats: null,
|
|
finishDistribution: null,
|
|
extendedProfile: null,
|
|
};
|
|
|
|
const viewModel = new DriverProfileViewModel(dto);
|
|
|
|
expect(viewModel.currentDriver).toBeNull();
|
|
expect(viewModel.stats).toBeNull();
|
|
expect(viewModel.finishDistribution).toBeNull();
|
|
expect(viewModel.extendedProfile).toBeNull();
|
|
});
|
|
|
|
it('returns original DTO from toDTO', () => {
|
|
const dto = createDriverProfileDto();
|
|
const viewModel = new DriverProfileViewModel(dto);
|
|
|
|
expect(viewModel.toDTO()).toBe(dto);
|
|
});
|
|
});
|