import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { environment } from '../../../environments/environment';
import { PublicTeamApi } from './public-team-api';

describe('PublicTeamApi', () => {
  let api: PublicTeamApi;
  let httpMock: HttpTestingController;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [provideHttpClient(), provideHttpClientTesting()],
    });
    api = TestBed.inject(PublicTeamApi);
    httpMock = TestBed.inject(HttpTestingController);
  });

  afterEach(() => httpMock.verify());

  it('loads a public team by access token', () => {
    api.loadTeam('public-token').subscribe();
    const request = httpMock.expectOne(`${environment.apiUrl}public/teams/public-token`);
    expect(request.request.method).toBe('GET');
    request.flush({ name: 'Team A', balance: 0, outstanding: 0, players: [], penalties: [] });
  });

  it('loads public player history by access token and player id', () => {
    api.loadPlayerHistory('public-token', 7).subscribe();
    const request = httpMock.expectOne(
      `${environment.apiUrl}public/teams/public-token/players/7/transactions`,
    );
    expect(request.request.method).toBe('GET');
    request.flush({ player: { id: 7 }, transactions: [] });
  });
});
