import { describe, it, expect } from 'vitest';
import { RaceViewModel } from './RaceViewModel';
import type { RaceDTO } from '../types/generated/RaceDTO';

const createRaceDto = (overrides: Partial<RaceDTO> = {}): RaceDTO => ({
  id: 'race-1',
  name: 'Season Opener',
  date: '2025-01-01T20:00:00Z',
  ...overrides,
});

describe('RaceViewModel', () => {
  it('maps basic DTO fields', () => {
    const dto = createRaceDto({ id: 'race-123', name: 'Test Race', date: '2025-02-01T18:30:00Z' });

    const viewModel = new RaceViewModel(dto);

    expect(viewModel.id).toBe('race-123');
    expect(viewModel.name).toBe('Test Race');
    expect(viewModel.date).toBe('2025-02-01T18:30:00Z');
  });

  it('exposes optional status, registeredCount and strengthOfField from constructor arguments', () => {
    const dto = createRaceDto();

    const viewModel = new RaceViewModel(dto, 'upcoming', 25, 3000);

    expect(viewModel.status).toBe('upcoming');
    expect(viewModel.registeredCount).toBe(25);
    expect(viewModel.strengthOfField).toBe(3000);
  });

  it('formats date to locale string', () => {
    const dto = createRaceDto({ date: '2025-01-01T20:00:00Z' });

    const viewModel = new RaceViewModel(dto);

    const formatted = viewModel.formattedDate;

    expect(formatted).toContain('2025');
  });
});
