46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { DriverSummaryViewModel } from './DriverSummaryViewModel';
|
|
import type { GetDriverOutputDTO } from '../types/generated/GetDriverOutputDTO';
|
|
|
|
const driverDto: GetDriverOutputDTO = {
|
|
id: 'driver-1',
|
|
iracingId: 'ir-123',
|
|
name: 'Test Driver',
|
|
country: 'DE',
|
|
joinedAt: '2024-01-01T00:00:00Z',
|
|
};
|
|
|
|
describe('DriverSummaryViewModel', () => {
|
|
it('maps driver and optional fields from DTO', () => {
|
|
const viewModel = new DriverSummaryViewModel({
|
|
driver: driverDto,
|
|
rating: 2500,
|
|
rank: 10,
|
|
});
|
|
|
|
expect(viewModel.driver).toBe(driverDto);
|
|
expect(viewModel.rating).toBe(2500);
|
|
expect(viewModel.rank).toBe(10);
|
|
});
|
|
|
|
it('defaults nullable rating and rank when undefined', () => {
|
|
const viewModel = new DriverSummaryViewModel({
|
|
driver: driverDto,
|
|
});
|
|
|
|
expect(viewModel.rating).toBeNull();
|
|
expect(viewModel.rank).toBeNull();
|
|
});
|
|
|
|
it('keeps explicit null rating and rank', () => {
|
|
const viewModel = new DriverSummaryViewModel({
|
|
driver: driverDto,
|
|
rating: null,
|
|
rank: null,
|
|
});
|
|
|
|
expect(viewModel.rating).toBeNull();
|
|
expect(viewModel.rank).toBeNull();
|
|
});
|
|
});
|