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

const createDto = (overrides: Partial<CreateLeagueOutputDTO> = {}): CreateLeagueOutputDTO => ({
  leagueId: 'league-1',
  success: true,
  ...overrides,
} as CreateLeagueOutputDTO);

describe('CreateLeagueViewModel', () => {
  it('maps leagueId and success from DTO', () => {
    const dto = createDto({ leagueId: 'league-123', success: true });

    const vm = new CreateLeagueViewModel(dto);

    expect(vm.leagueId).toBe('league-123');
    expect(vm.success).toBe(true);
  });

  it('returns success successMessage when creation succeeded', () => {
    const dto = createDto({ success: true });

    const vm = new CreateLeagueViewModel(dto);

    expect(vm.successMessage).toBe('League created successfully!');
  });

  it('returns failure successMessage when creation failed', () => {
    const dto = createDto({ success: false });

    const vm = new CreateLeagueViewModel(dto);

    expect(vm.successMessage).toBe('Failed to create league.');
  });
});
