import { Test, TestingModule } from '@nestjs/testing';
import { LeagueController } from './LeagueController';
import { LeagueService } from './LeagueService';
import { LeagueProviders } from './LeagueProviders';

describe('LeagueController (integration)', () => {
  let controller: LeagueController;
  let service: LeagueService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [LeagueController],
      providers: [LeagueService, ...LeagueProviders],
    }).compile();

    controller = module.get<LeagueController>(LeagueController);
    service = module.get<LeagueService>(LeagueService);
  });

  it('should get total leagues', async () => {
    const result = await controller.getTotalLeagues();
    expect(result).toHaveProperty('totalLeagues');
    expect(typeof result.totalLeagues).toBe('number');
  });

  it('should get all leagues with capacity', async () => {
    const result = await controller.getAllLeaguesWithCapacity();
    expect(result).toHaveProperty('leagues');
    expect(result).toHaveProperty('totalCount');
    expect(Array.isArray(result.leagues)).toBe(true);
  });

  it('should get league standings', async () => {
    try {
      const result = await controller.getLeagueStandings('non-existent-league');
      expect(result).toHaveProperty('standings');
      expect(Array.isArray(result.standings)).toBe(true);
    } catch (error) {
      // Expected for non-existent league
      expect(error.message).toContain('not found');
    }
  });
});