All files / src/redux reducers.js

100% Statements 18/18
94.44% Branches 17/18
100% Functions 3/3
100% Lines 18/18
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74                        49x   1x   1x             47x             49x   1x 1x             1x   1x 1x             1x     45x             49x   1x   1x   1x   1x     45x    
import { LOGIN_SUCCESS, LOGIN_FAILURE, SEARCH_FAILED } from "./actionTypes";
import { SEARCH_SUCCEEDED, SEARCH_CLEAR, SEARCH_STARTED } from "./actionTypes";
import {
  RECOMMENDATIONS_SUCCEEDED,
  RECOMMENDATIONS_STARTED,
  RECOMMENDATIONS_FAILED
} from "./actionTypes";
 
/**
 *  LOGIN REDUCER
 */
export function loginReducer(prevState = {}, action) {
  switch (action.type) {
    case LOGIN_FAILURE:
      return { error: action.error };
    case LOGIN_SUCCESS:
      return {
        auth_token: action.payload.auth_token,
        refresh_token: action.payload.refresh_token,
        expiration: action.payload.expiration
      };
    default:
  }
  return prevState;
}
 
/**
 *  SEARCH REDUCER
 */
export function searchReducer(prevState = {}, action) {
  switch (action.type) {
    case SEARCH_SUCCEEDED:
      debugger;
      return {
        albums: {
          searchText: prevState.albums ? prevState.albums.searchText : "",
          result: action.payload.albums
        }
      };
    case SEARCH_FAILED:
      return { albums: JSON.parse(action.payload.response) };
    case SEARCH_STARTED:
      debugger;
      return {
        albums: {
          searchText: action.payload[0],
          loading: true
        }
      };
    case SEARCH_CLEAR:
      return { albums: {} };
    default:
  }
  return prevState;
}
 
/**
 * RECOMMENDATIONS REDUCER
 */
export function recommendationsReducer(prevState = {}, action) {
  switch (action.type) {
    case RECOMMENDATIONS_SUCCEEDED:
      return { album: prevState.album, results: action.payload };
    case RECOMMENDATIONS_FAILED:
      return { results: JSON.parse(action.payload.response) };
    case RECOMMENDATIONS_STARTED:
      return { album: action.payload[0].album, loading: true };
    case SEARCH_CLEAR:
      return {};
    default:
  }
  return prevState;
}