All files / @gce/configuration/store reducers.js

92.31% Statements 12/13
100% Branches 5/5
80% Functions 4/5
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    1x             1x 1x 1x 1x   1x               5x 3x     2x    
import { SET_HIDE_CONTRACT_MUTATION, SET_HIDE_CONSENT, SET_MARKETING_URL, SET_HIDE_MARKETING } from './constants';
 
const initialState = {
  hideContractMutation: false,
  hideConsent: true,
  marketingURL: null,
  hideMarketing: false,
};
 
const setHideConsent = (state, action) => ({ ...state, hideConsent: action.payload.hideConsent === 'yes' });
const setHideContractMutation = (state, action) => ({ ...state, hideContractMutation: action.payload.hideContractMutation === 'yes' });
const setMarketingURL = (state, action) => ({ ...state, marketingURL: action.payload.marketingURL });
const setHideMarketing = (state, action) => ({ ...state, hideMarketing: action.payload.hideMarketing === 'yes' });
 
const FUNCTION_BY_ACTION = {
  [SET_HIDE_CONSENT]: setHideConsent,
  [SET_HIDE_CONTRACT_MUTATION]: setHideContractMutation,
  [SET_MARKETING_URL]: setMarketingURL,
  [SET_HIDE_MARKETING]: setHideMarketing,
};
 
export default (state = initialState, action) => {
  if (action && action.type in FUNCTION_BY_ACTION) {
    return FUNCTION_BY_ACTION[action.type](state, action);
  }
 
  return state;
};