All files middleware.js

92.31% Statements 12/13
83.33% Branches 5/6
100% Functions 4/4
91.67% Lines 11/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    2x 2x 1x   1x     3x 3x   3x     3x 2x   3x         3x    
import { actionTypes as dataFetchActionTypes } from '@bufferapp/async-data-fetch';
 
const getRedirectURL = () => {
  if (window.location.hostname === 'analyze.local.buffer.com') {
    return 'https://local.buffer.com/analyze';
  }
  return 'https://buffer.com/analyze';
};
 
export default () => next => (action) => {
  switch (action.type) {
    case `profiles_${dataFetchActionTypes.FETCH_SUCCESS}`: {
      const profiles = action.result;
      // if there aren't any active analyze profiles
      // then redirect back to the home page
      if (profiles.length < 1) {
        window.location.assign(getRedirectURL());
      }
      break;
    }
    default:
      break;
  }
  return next(action);
};