import { describe, it, expect, beforeEach } from 'vitest';
import { CompleteOnboardingPresenter } from './CompleteOnboardingPresenter';
import type { CompleteDriverOnboardingResultDTO } from '../../../../../core/racing/application/presenters/ICompleteDriverOnboardingPresenter';

describe('CompleteOnboardingPresenter', () => {
  let presenter: CompleteOnboardingPresenter;

  beforeEach(() => {
    presenter = new CompleteOnboardingPresenter();
  });

  describe('present', () => {
    it('should map successful core DTO to API view model', () => {
      const dto: CompleteDriverOnboardingResultDTO = {
        success: true,
        driverId: 'driver-123',
      };

      presenter.present(dto);

      const result = presenter.viewModel;

      expect(result).toEqual({
        success: true,
        driverId: 'driver-123',
        errorMessage: undefined,
      });
    });

    it('should map failed core DTO to API view model', () => {
      const dto: CompleteDriverOnboardingResultDTO = {
        success: false,
        errorMessage: 'Driver already exists',
      };

      presenter.present(dto);

      const result = presenter.viewModel;

      expect(result).toEqual({
        success: false,
        driverId: undefined,
        errorMessage: 'Driver already exists',
      });
    });
  });

  describe('reset', () => {
    it('should reset the result', () => {
      const dto: CompleteDriverOnboardingResultDTO = {
        success: true,
        driverId: 'driver-123',
      };

      presenter.present(dto);
      expect(presenter.viewModel).toBeDefined();

      presenter.reset();
      expect(() => presenter.viewModel).toThrow('Presenter not presented');
    });
  });
});