import _ from 'lodash';
import { combineReducers } from 'redux';

import API from '../libs/middleware/api';
import settings from '../libs/reducers/settings';
import configureStore from '../libs/store/configure_store';

export default class Helper {

  // Create a fake store for testing
  static mockStore(state) {
    return {
      subscribe: () => {},
      dispatch: () => {},
      getState: () => ({ ...state })
    };
  }

  // Create a real store that can be used for testing
  static makeStore(initialSettings, additionalState) {
    const initialState = _.merge({
      settings: _.merge({
        csrf: 'csrf_token',
        apiUrl: 'http://www.example.com'
      }, initialSettings)
    }, additionalState);
    const rootReducer = combineReducers({
      settings,
    });
    const middleware = [API];
    return configureStore(initialState, rootReducer, middleware);
  }

  static testPayload() {
    return JSON.stringify([{
      id: 1,
      name: 'Starter App'
    }]);
  }

  static stubAjax() {
    beforeEach(() => {
      jasmine.Ajax.install();

      jasmine.Ajax.stubRequest(
          RegExp('.*/api/test')
        ).andReturn({
          status: 200,
          contentType: 'application/json',
          statusText: 'OK',
          responseText: Helper.testPayload()
        });

      jasmine.Ajax.stubRequest(
          RegExp('.*/api/test/.+')
        ).andReturn({
          status: 200,
          contentType: 'application/json',
          statusText: 'OK',
          responseText: Helper.testPayload()
        });
    });

    afterEach(() => {
      jasmine.Ajax.uninstall();
    });
  }

  static mockClock() {
    beforeEach(() => {
      jasmine.clock().install(); // Mock out the built in timers
    });

    afterEach(() => {
      jasmine.clock().uninstall();
    });
  }

}

@@ -469,32 +469,126 @@
 sed for testing%0A
+  // For any additional state provided you must also provide the corresponding%0A  // reducers.%0A
   static makeSto
@@ -618,24 +618,44 @@
 itionalState
+, additionalReducers
 ) %7B%0A    cons
@@ -885,16 +885,44 @@
 ttings,%0A
+      ...additionalReducers%0A
     %7D);%0A

Allow additional reducers along with additional state