import { describe, it, expect } from 'vitest';
import { ImportRaceResultsSummaryViewModel } from './ImportRaceResultsSummaryViewModel';

describe('ImportRaceResultsSummaryViewModel', () => {
  it('maps DTO fields including errors', () => {
    const dto = {
      success: true,
      raceId: 'race-1',
      driversProcessed: 10,
      resultsRecorded: 8,
      errors: ['Driver missing', 'Invalid lap time'],
    };

    const viewModel = new ImportRaceResultsSummaryViewModel(dto);

    expect(viewModel.success).toBe(true);
    expect(viewModel.raceId).toBe('race-1');
    expect(viewModel.driversProcessed).toBe(10);
    expect(viewModel.resultsRecorded).toBe(8);
    expect(viewModel.errors).toEqual(['Driver missing', 'Invalid lap time']);
  });

  it('defaults errors to an empty array when not provided', () => {
    const dto = {
      success: false,
      raceId: 'race-2',
      driversProcessed: 0,
      resultsRecorded: 0,
    };

    const viewModel = new ImportRaceResultsSummaryViewModel(dto);

    expect(viewModel.errors).toEqual([]);
  });
});
