import { fromJS } from 'immutable';
import mobilePushReducer from '../reducer';
import * as types from '../constants';

describe('MobilePushNew Reducer', () => {
  const initialState = fromJS({
    createTemplateInProgress: false,
    response: {},
    editTemplateInProgress: false,
    editResponse: {},
    getTemplateDetailsInProgress: false,
    templateDetails: {},
    createTemplateErrorMessage: '',
  });

  describe('Initial State', () => {
    it('should return the initial state', () => {
      expect(mobilePushReducer(undefined, {})).toEqual(initialState);
    });
  });

  describe('DEFAULT_ACTION', () => {
    it('should return the current state unchanged', () => {
      const currentState = initialState.set('createTemplateInProgress', true);
      const action = { type: types.DEFAULT_ACTION };
      expect(mobilePushReducer(currentState, action)).toEqual(currentState);
    });
  });

  describe('CREATE_TEMPLATE_REQUEST', () => {
    it('should set createTemplateInProgress to true and reset error states', () => {
      const action = { type: types.CREATE_TEMPLATE_REQUEST };
      const expectedState = initialState
        .set('createTemplateInProgress', true)
        .set('createTemplateError', false)
        .set('createTemplateErrorMessage', fromJS(''));

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });

    it('should reset error states when request is made', () => {
      const currentState = initialState
        .set('createTemplateError', true)
        .set('createTemplateErrorMessage', fromJS('Previous error'));

      const action = { type: types.CREATE_TEMPLATE_REQUEST };
      const expectedState = currentState
        .set('createTemplateInProgress', true)
        .set('createTemplateError', false)
        .set('createTemplateErrorMessage', fromJS(''));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('CREATE_TEMPLATE_SUCCESS', () => {
    it('should set createTemplateInProgress to false and store response with successful status', () => {
      const mockData = { id: 1, name: 'Test Template' };
      const action = {
        type: types.CREATE_TEMPLATE_SUCCESS,
        data: mockData,
        statusCode: 200,
      };

      const currentState = initialState.set('createTemplateInProgress', true);
      const expectedState = currentState
        .set('createTemplateInProgress', false)
        .set('response', mockData)
        .set('createTemplateError', false);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should set createTemplateError to true when statusCode is greater than 300', () => {
      const mockData = { error: 'Template creation failed' };
      const action = {
        type: types.CREATE_TEMPLATE_SUCCESS,
        data: mockData,
        statusCode: 400,
      };

      const currentState = initialState.set('createTemplateInProgress', true);
      const expectedState = currentState
        .set('createTemplateInProgress', false)
        .set('response', mockData)
        .set('createTemplateError', true);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle success without statusCode', () => {
      const mockData = { id: 1, name: 'Test Template' };
      const action = {
        type: types.CREATE_TEMPLATE_SUCCESS,
        data: mockData,
      };

      const currentState = initialState.set('createTemplateInProgress', true);
      const expectedState = currentState
        .set('createTemplateInProgress', false)
        .set('response', mockData)
        .set('createTemplateError', false);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('CREATE_TEMPLATE_FAILURE', () => {
    it('should set createTemplateInProgress to false and store error message', () => {
      const errorMessage = 'Template creation failed';
      const action = {
        type: types.CREATE_TEMPLATE_FAILURE,
        error: errorMessage,
      };

      const currentState = initialState.set('createTemplateInProgress', true);
      const expectedState = currentState
        .set('createTemplateInProgress', false)
        .set('createTemplateError', true)
        .set('createTemplateErrorMessage', fromJS(errorMessage));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('CLEAR_CREATE_RESPONSE_REQUEST', () => {
    it('should clear the response', () => {
      const currentState = initialState.set('response', { id: 1, name: 'Test' });
      const action = { type: types.CLEAR_CREATE_RESPONSE_REQUEST };
      const expectedState = currentState.set('response', {});

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('UPLOAD_ASSET_REQUEST', () => {
    it('should set uploadAssetSuccess to false and assetUploading to true', () => {
      const action = { type: types.UPLOAD_ASSET_REQUEST };
      const expectedState = initialState
        .set('uploadAssetSuccess', false)
        .set('assetUploading', true);

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });
  });

  describe('UPLOAD_ASSET_SUCCESS', () => {
    it('should set uploadAssetSuccess to true and store asset data with successful status', () => {
      const mockData = { url: 'https://example.com/image.jpg' };
      const action = {
        type: types.UPLOAD_ASSET_SUCCESS,
        data: mockData,
        statusCode: 200,
      };

      const currentState = initialState.set('assetUploading', true);
      const expectedState = currentState
        .set('uploadAssetSuccess', true)
        .set('assetUploading', false)
        .set('uploadedAssetData', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should set uploadAssetSuccess to false when statusCode is greater than or equal to 300', () => {
      const mockData = { error: 'Upload failed' };
      const action = {
        type: types.UPLOAD_ASSET_SUCCESS,
        data: mockData,
        statusCode: 400,
      };

      const currentState = initialState.set('assetUploading', true);
      const expectedState = currentState
        .set('uploadAssetSuccess', false)
        .set('assetUploading', false)
        .set('uploadedAssetData', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle success without statusCode', () => {
      const mockData = { url: 'https://example.com/image.jpg' };
      const action = {
        type: types.UPLOAD_ASSET_SUCCESS,
        data: mockData,
      };

      const currentState = initialState.set('assetUploading', true);
      const expectedState = currentState
        .set('uploadAssetSuccess', false)
        .set('assetUploading', false)
        .set('uploadedAssetData', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle empty statusCode', () => {
      const mockData = { url: 'https://example.com/image.jpg' };
      const action = {
        type: types.UPLOAD_ASSET_SUCCESS,
        data: mockData,
        statusCode: '',
      };

      const currentState = initialState.set('assetUploading', true);
      const expectedState = currentState
        .set('uploadAssetSuccess', false)
        .set('assetUploading', false)
        .set('uploadedAssetData', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('UPLOAD_ASSET_FAILURE', () => {
    it('should set uploadAssetSuccess to false and assetUploading to false', () => {
      const action = { type: types.UPLOAD_ASSET_FAILURE };
      const currentState = initialState
        .set('uploadAssetSuccess', true)
        .set('assetUploading', true);

      const expectedState = currentState
        .set('uploadAssetSuccess', false)
        .set('assetUploading', false);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('CLEAR_ASSET', () => {
    it('should remove uploadedAssetData from state', () => {
      const currentState = initialState.set('uploadedAssetData', { url: 'test.jpg' });
      const action = { type: types.CLEAR_ASSET };
      const expectedState = currentState.delete('uploadedAssetData');

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle clearing asset when no asset data exists', () => {
      const action = { type: types.CLEAR_ASSET };
      const expectedState = initialState.delete('uploadedAssetData');

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });
  });

  describe('GET_IOS_CTAS', () => {
    it('should set getIosCtasSucccess to false and iosCtasLoading to true', () => {
      const action = { type: types.GET_IOS_CTAS };
      const expectedState = initialState
        .set('getIosCtasSucccess', false)
        .set('iosCtasLoading', true);

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });
  });

  describe('GET_IOS_CTAS_SUCCESS', () => {
    it('should set getIosCtasSucccess to true and store CTA data with successful status', () => {
      const mockData = [{ id: 1, text: 'Button 1' }];
      const action = {
        type: types.GET_IOS_CTAS_SUCCESS,
        data: mockData,
        statusCode: 200,
      };

      const currentState = initialState.set('iosCtasLoading', true);
      const expectedState = currentState
        .set('getIosCtasSucccess', true)
        .set('iosCtasLoading', false)
        .set('iosCtasData', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should set getIosCtasSucccess to false when statusCode is greater than or equal to 300', () => {
      const mockData = { error: 'CTA fetch failed' };
      const action = {
        type: types.GET_IOS_CTAS_SUCCESS,
        data: mockData,
        statusCode: 400,
      };

      const currentState = initialState.set('iosCtasLoading', true);
      const expectedState = currentState
        .set('getIosCtasSucccess', false)
        .set('iosCtasLoading', false)
        .set('iosCtasData', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle success without statusCode', () => {
      const mockData = [{ id: 1, text: 'Button 1' }];
      const action = {
        type: types.GET_IOS_CTAS_SUCCESS,
        data: mockData,
      };

      const currentState = initialState.set('iosCtasLoading', true);
      const expectedState = currentState
        .set('getIosCtasSucccess', false)
        .set('iosCtasLoading', false)
        .set('iosCtasData', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('GET_IOS_CTAS_FAILURE', () => {
    it('should set getIosCtasSucccess to false and iosCtasLoading to false', () => {
      const action = { type: types.GET_IOS_CTAS_FAILURE };
      const currentState = initialState
        .set('getIosCtasSucccess', true)
        .set('iosCtasLoading', true);

      const expectedState = currentState
        .set('getIosCtasSucccess', false)
        .set('iosCtasLoading', false);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('RESET_STORE', () => {
    it('should remove uploadedAssetData and iosCtasData from state', () => {
      const currentState = initialState
        .set('uploadedAssetData', { url: 'test.jpg' })
        .set('iosCtasData', [{ id: 1, text: 'Button' }]);

      const action = { type: types.RESET_STORE };
      const expectedState = currentState
        .delete('uploadedAssetData')
        .delete('iosCtasData');

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle reset when no data exists', () => {
      const action = { type: types.RESET_STORE };
      const expectedState = initialState
        .delete('uploadedAssetData')
        .delete('iosCtasData');

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });
  });

  describe('EDIT_TEMPLATE_REQUEST', () => {
    it('should set editTemplateInProgress to true and reset error states', () => {
      const action = { type: types.EDIT_TEMPLATE_REQUEST };
      const expectedState = initialState
        .set('editTemplateInProgress', true)
        .set('editTemplateError', false)
        .set('editTemplateErrorMessage', fromJS(''));

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });

    it('should reset error states when request is made', () => {
      const currentState = initialState
        .set('editTemplateError', true)
        .set('editTemplateErrorMessage', fromJS('Previous error'));

      const action = { type: types.EDIT_TEMPLATE_REQUEST };
      const expectedState = currentState
        .set('editTemplateInProgress', true)
        .set('editTemplateError', false)
        .set('editTemplateErrorMessage', fromJS(''));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('EDIT_TEMPLATE_SUCCESS', () => {
    it('should set editTemplateInProgress to false and store response with successful status', () => {
      const mockData = { id: 1, name: 'Updated Template' };
      const errorMsg = 'Success';
      const action = {
        type: types.EDIT_TEMPLATE_SUCCESS,
        data: mockData,
        statusCode: 200,
        errorMsg,
      };

      const currentState = initialState.set('editTemplateInProgress', true);
      const expectedState = currentState
        .set('editTemplateInProgress', false)
        .set('editResponse', mockData)
        .set('editTemplateError', false)
        .set('editTemplateErrorMessage', fromJS(errorMsg));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should set editTemplateError to true when statusCode is greater than 300', () => {
      const mockData = { error: 'Template update failed' };
      const errorMsg = 'Update failed';
      const action = {
        type: types.EDIT_TEMPLATE_SUCCESS,
        data: mockData,
        statusCode: 400,
        errorMsg,
      };

      const currentState = initialState.set('editTemplateInProgress', true);
      const expectedState = currentState
        .set('editTemplateInProgress', false)
        .set('editResponse', mockData)
        .set('editTemplateError', true)
        .set('editTemplateErrorMessage', fromJS(errorMsg));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle success without statusCode', () => {
      const mockData = { id: 1, name: 'Updated Template' };
      const errorMsg = 'Success';
      const action = {
        type: types.EDIT_TEMPLATE_SUCCESS,
        data: mockData,
        errorMsg,
      };

      const currentState = initialState.set('editTemplateInProgress', true);
      const expectedState = currentState
        .set('editTemplateInProgress', false)
        .set('editResponse', mockData)
        .set('editTemplateError', false)
        .set('editTemplateErrorMessage', fromJS(errorMsg));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('EDIT_TEMPLATE_FAILURE', () => {
    it('should set editTemplateInProgress to false and store error message', () => {
      const errorMessage = 'Template update failed';
      const action = {
        type: types.EDIT_TEMPLATE_FAILURE,
        errorMsg: errorMessage,
      };

      const currentState = initialState.set('editTemplateInProgress', true);
      const expectedState = currentState
        .set('editTemplateInProgress', false)
        .set('editTemplateError', true)
        .set('editTemplateErrorMessage', fromJS(errorMessage));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('GET_TEMPLATE_DETAILS_REQUEST', () => {
    it('should set getTemplateDetailsInProgress to true', () => {
      const action = { type: types.GET_TEMPLATE_DETAILS_REQUEST };
      const expectedState = initialState.set('getTemplateDetailsInProgress', true);

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });
  });

  describe('GET_TEMPLATE_DETAILS_SUCCESS', () => {
    it('should set getTemplateDetailsInProgress to false and store template details', () => {
      const mockData = { id: 1, name: 'Template Details', content: 'Template content' };
      const action = {
        type: types.GET_TEMPLATE_DETAILS_SUCCESS,
        data: mockData,
      };

      const currentState = initialState.set('getTemplateDetailsInProgress', true);
      const expectedState = currentState
        .set('getTemplateDetailsInProgress', false)
        .set('templateDetails', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('SET_SELECTED_TEMPLATE', () => {
    it('should set getTemplateDetailsInProgress to false and store template details', () => {
      const mockData = { id: 2, name: 'Selected Template', content: 'Selected content' };
      const action = {
        type: types.SET_SELECTED_TEMPLATE,
        data: mockData,
      };

      const currentState = initialState.set('getTemplateDetailsInProgress', true);
      const expectedState = currentState
        .set('getTemplateDetailsInProgress', false)
        .set('templateDetails', mockData);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('GET_TEMPLATE_DETAILS_FAILURE', () => {
    it('should set getTemplateDetailsInProgress to false', () => {
      const action = { type: types.GET_TEMPLATE_DETAILS_FAILURE };
      const currentState = initialState.set('getTemplateDetailsInProgress', true);
      const expectedState = currentState.set('getTemplateDetailsInProgress', false);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('CLEAR_EDIT_RESPONSE_REQUEST', () => {
    it('should clear the edit response', () => {
      const currentState = initialState.set('editResponse', { id: 1, name: 'Test' });
      const action = { type: types.CLEAR_EDIT_RESPONSE_REQUEST };
      const expectedState = currentState.set('editResponse', {});

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('CLEAR_DATA', () => {
    it('should remove uploadedAssetData, metaEntities, templateDetails, and iosCtasData from state', () => {
      const currentState = initialState
        .set('uploadedAssetData', { url: 'test.jpg' })
        .set('metaEntities', { entities: [] })
        .set('templateDetails', { id: 1, name: 'Template' })
        .set('iosCtasData', [{ id: 1, text: 'Button' }]);

      const action = { type: types.CLEAR_DATA };
      const expectedState = currentState
        .delete('uploadedAssetData')
        .delete('metaEntities')
        .delete('templateDetails')
        .delete('iosCtasData');

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle clearing data when no data exists', () => {
      const action = { type: types.CLEAR_DATA };
      const expectedState = initialState
        .delete('uploadedAssetData')
        .delete('metaEntities')
        .delete('templateDetails')
        .delete('iosCtasData');

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });
  });

  describe('GET_WECRM_ACCOUNTS_REQUEST', () => {
    it('should set fetchingWeCrmAccounts to true and weCrmAccountFetchingError to false', () => {
      const action = { type: types.GET_WECRM_ACCOUNTS_REQUEST };
      const expectedState = initialState
        .set('fetchingWeCrmAccounts', true)
        .set('weCrmAccountFetchingError', false);

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });

    it('should reset error state when request is made', () => {
      const currentState = initialState.set('weCrmAccountFetchingError', true);
      const action = { type: types.GET_WECRM_ACCOUNTS_REQUEST };
      const expectedState = currentState
        .set('fetchingWeCrmAccounts', true)
        .set('weCrmAccountFetchingError', false);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('GET_WECRM_ACCOUNTS_SUCCESS', () => {
    it('should set fetchingWeCrmAccounts to false and store accounts data', () => {
      const mockData = [{ id: 1, name: 'Account 1' }, { id: 2, name: 'Account 2' }];
      const action = {
        type: types.GET_WECRM_ACCOUNTS_SUCCESS,
        data: mockData,
      };

      const currentState = initialState.set('fetchingWeCrmAccounts', true);
      const expectedState = currentState
        .set('fetchingWeCrmAccounts', false)
        .set('weCrmAccounts', fromJS(mockData));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('GET_WECRM_ACCOUNTS_FAILURE', () => {
    it('should set fetchingWeCrmAccounts to false and weCrmAccountFetchingError to true', () => {
      const action = { type: types.GET_WECRM_ACCOUNTS_FAILURE };
      const currentState = initialState.set('fetchingWeCrmAccounts', true);
      const expectedState = currentState
        .set('fetchingWeCrmAccounts', false)
        .set('weCrmAccountFetchingError', true);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('SET_WECHAT_ACCOUNT', () => {
    it('should set selectedWeChatAccount and remove mobilepushTemplates', () => {
      const mockWeChatAccount = { id: 1, name: 'WeChat Account' };
      const action = {
        type: types.SET_WECHAT_ACCOUNT,
        weChatAccount: mockWeChatAccount,
      };

      const currentState = initialState.set('mobilepushTemplates', [{ id: 1, name: 'Template' }]);
      const expectedState = currentState
        .set('selectedWeChatAccount', fromJS(mockWeChatAccount))
        .delete('mobilepushTemplates');

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle setting WeChat account when no templates exist', () => {
      const mockWeChatAccount = { id: 1, name: 'WeChat Account' };
      const action = {
        type: types.SET_WECHAT_ACCOUNT,
        weChatAccount: mockWeChatAccount,
      };

      const expectedState = initialState
        .set('selectedWeChatAccount', fromJS(mockWeChatAccount))
        .delete('mobilepushTemplates');

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });
  });

  describe('GET_MOBILEPUSH_TEMPLATES_LIST_REQUEST', () => {
    it('should set fetchingDefaultTemplates to true', () => {
      const action = { type: types.GET_MOBILEPUSH_TEMPLATES_LIST_REQUEST };
      const expectedState = initialState.set('fetchingDefaultTemplates', true);

      expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
    });
  });

  describe('GET_MOBILEPUSH_TEMPLATES_LIST_SUCCESS', () => {
    it('should set fetchingDefaultTemplates to false and store templates data', () => {
      const mockData = [{ id: 1, name: 'Template 1' }, { id: 2, name: 'Template 2' }];
      const action = {
        type: types.GET_MOBILEPUSH_TEMPLATES_LIST_SUCCESS,
        data: mockData,
      };

      const currentState = initialState.set('fetchingDefaultTemplates', true);
      const expectedState = currentState
        .set('fetchingDefaultTemplates', false)
        .set('mobilepushTemplates', fromJS(mockData));

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('GET_MOBILEPUSH_TEMPLATES_LIST_FAILURE', () => {
    it('should set fetchingDefaultTemplates to false and errorFetchingDefaultTempalte to true', () => {
      const action = { type: types.GET_MOBILEPUSH_TEMPLATES_LIST_FAILURE };
      const currentState = initialState.set('fetchingDefaultTemplates', true);
      const expectedState = currentState
        .set('fetchingDefaultTemplates', false)
        .set('errorFetchingDefaultTempalte', true);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });
  });

  describe('Unknown Action', () => {
    it('should return the current state for unknown action types', () => {
      const unknownAction = { type: 'UNKNOWN_ACTION' };
      const currentState = initialState.set('createTemplateInProgress', true);

      expect(mobilePushReducer(currentState, unknownAction)).toEqual(currentState);
    });
  });

  describe('Edge Cases', () => {
    it('should handle null action', () => {
      expect(mobilePushReducer(initialState, null)).toEqual(initialState);
    });

    it('should handle undefined action', () => {
      expect(mobilePushReducer(initialState, undefined)).toEqual(initialState);
    });

    it('should handle action without type', () => {
      expect(mobilePushReducer(initialState, {})).toEqual(initialState);
    });

    it('should handle action with null data', () => {
      const action = {
        type: types.CREATE_TEMPLATE_SUCCESS,
        data: null,
        statusCode: 200,
      };

      const currentState = initialState.set('createTemplateInProgress', true);
      const expectedState = currentState
        .set('createTemplateInProgress', false)
        .set('response', null)
        .set('createTemplateError', false);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle action with undefined data', () => {
      const action = {
        type: types.GET_TEMPLATE_DETAILS_SUCCESS,
        data: undefined,
      };

      const currentState = initialState.set('getTemplateDetailsInProgress', true);
      const expectedState = currentState
        .set('getTemplateDetailsInProgress', false)
        .set('templateDetails', undefined);

      expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
    });

    it('should handle multiple consecutive actions', () => {
      let state = initialState;

      // First action
      state = mobilePushReducer(state, { type: types.CREATE_TEMPLATE_REQUEST });
      expect(state.get('createTemplateInProgress')).toBe(true);

      // Second action
      state = mobilePushReducer(state, {
        type: types.CREATE_TEMPLATE_SUCCESS,
        data: { id: 1 },
        statusCode: 200,
      });
      expect(state.get('createTemplateInProgress')).toBe(false);
      expect(state.get('response')).toEqual({ id: 1 });
      expect(state.get('createTemplateError')).toBe(false);

      // Third action
      state = mobilePushReducer(state, { type: types.CLEAR_CREATE_RESPONSE_REQUEST });
      expect(state.get('response')).toEqual({});
    });
  });
});
