All files / comparison_chart middleware.js

100% Statements 15/15
80% Branches 4/5
100% Functions 5/5
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42          3x 3x 3x   4x 1x               1x     4x 1x 1x                   1x     1x   3x      
import { actions } from '@bufferapp/async-data-fetch';
import { actionTypes as profileActionTypes } from '@bufferapp/multi-profile-selector';
import { actionTypes as dateActionTypes } from '@bufferapp/analyze-date-picker';
 
 
export default store => next => (action) => { // eslint-disable-line no-unused-vars
  const { dispatch, getState } = store;
  switch (action.type) {
    case profileActionTypes.COMPARE_PROFILES: {
      const selectedProfileIds = action.selectedProfiles.map(p => p.id);
      dispatch(actions.fetch({
        name: 'comparison',
        args: {
          profileIds: selectedProfileIds,
          startDate: getState().date.startDate,
          endDate: getState().date.endDate,
        },
      }));
      break;
    }
    case dateActionTypes.SET_DATE_RANGE: {
      const selectedProfileIds = getState().multiProfileSelector.selectedProfiles.map(p => p.id);
      Eif (selectedProfileIds.length > 0) {
        dispatch(actions.fetch({
          name: 'comparison',
          args: {
            profileIds: selectedProfileIds,
            profileService: getState().profiles.selectedProfileService,
            startDate: action.startDate,
            endDate: action.endDate,
          },
        }));
      }
      break;
    }
    default:
      break;
  }
  return next(action);
};