import { expectSaga } from 'redux-saga-test-plan';
import {  throwError } from 'redux-saga-test-plan/providers';
import * as Api from '../../../../services/api'; 
import * as types from '../constants'; 
import * as sagas from '../sagas'; 
import { call } from 'redux-saga/effects';

describe('fetchUserList Saga', () => {
    it.concurrent('handles fetching user list successfully', () => {
      const fakeResponse = {
        data: {
          result: [{ id: 1, name: 'User One' }]
        }
      };

      return expectSaga(sagas.fetchUserList)
        .provide([
          [call
          (Api.getUserList), fakeResponse]
        ])
        .put({
          type: types.GET_USER_LIST_SUCCESS,
          data: fakeResponse.data.result
        })
        .run();
    });

    it.concurrent('handles failure in fetching user list', () => {
      const error = new Error('Fetch failed');

      return expectSaga(sagas.fetchUserList)
        .provide([
          [call(Api.getUserList), throwError(error)]
        ])
        .put({
          type: types.GET_USER_LIST_FAILURE,
          data: error
        })
        .run();
    });
  });