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

describe('getLocizMessage saga', () => {
  const locale = 'en-US';
  const action = { locale };

  it.concurrent('handles successful API call', () => {
    const response = { messages: { hello: "Hello" } }; // Example response structure

    return expectSaga(getLocizMessage, action)
      .provide([
        [call(api.getLocizMessage, locale), response]
      ])
      .put({
        type: types.GET_LOCIZ_MESSAGE_SUCCESS,
        data: response,
        locale: locale,
      })
      .run();
  });

  it.concurrent('handles failure when API call fails', () => {
    const error = new Error('Failed to fetch localization messages');

    return expectSaga(getLocizMessage, action)
      .provide([
        [call(api.getLocizMessage, locale), throwError(error)]
      ])
      .put({
        type: types.GET_LOCIZ_MESSAGE_FAILURE,
        data: error,
      })
      .run();
  });
});