import {getEnsembleEvenementFront} from './ensembleEvenementService';
import http from '@/http';

const mockedHttp = http as jest.Mocked<typeof http>;

describe('ensembleEvenementService', () => {
  beforeEach(() => {
    jest.clearAllMocks();
  });

  it('shouldLoadTheEnsembleWithItsEvents', async () => {
    const ens = {eesId: 5, eesLibelle: 'Festival Interceltique', evenements: [{eveId: 1, eveDate: '2026-08-05', eveTev: {tevLibelle: 'Fest-noz'}, eveVil: {vilNom: 'Lorient'}}]};
    mockedHttp.get.mockResolvedValueOnce({status: 200, data: ens});

    expect(await getEnsembleEvenementFront(5)).toEqual(ens);
    expect(mockedHttp.get).toHaveBeenCalledWith('/evenement_ensembles/5/front');
  });

  it('shouldReturnNullWhenTheApiFails', async () => {
    mockedHttp.get.mockRejectedValueOnce(new Error('HTTP 404'));

    expect(await getEnsembleEvenementFront(5)).toBeNull();
  });
});
