import {getFilCommunautaire} from './communauteService';
import http from '@/http';

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

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

  it('shouldLoadTheLatestCommunityItems', async () => {
    const fil = {commentaires: [{id: 1}], annonces: [], covoiturages: [], inscrits: []};
    mockedHttp.get.mockResolvedValueOnce({status: 200, data: fil});

    expect(await getFilCommunautaire(6)).toEqual(fil);
    expect(mockedHttp.get).toHaveBeenCalledWith('/communaute/fil?limit=6');
  });

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

    expect(await getFilCommunautaire()).toEqual({commentaires: [], annonces: [], covoiturages: [], inscrits: []});
  });
});
