All files / src/background/redux/reducers tokens.tsx

27.27% Statements 3/11
33.33% Branches 2/6
100% Functions 1/1
27.27% Lines 3/11

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 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                      2x                   7x                                                                   7x      
import {
  AccessToken,
  ADD_ACCESS_TOKEN,
  ADD_REFRESH_TOKEN,
  CHECKED_COOKIES,
  CookieStatus,
  REMOVE_TOKENS,
  TokenActionsTypes,
  TokensState
} from "../actions/tokenTypes";
 
const initialState: TokensState = {
  refreshToken: null,
  accessToken: null,
  checkedCookies: CookieStatus.NOT_STARTED
};
 
export default function tokens(
  state = initialState,
  action: TokenActionsTypes
) {
  switch (action.type) {
    case ADD_REFRESH_TOKEN: {
      console.log("[Redux] adding refreshToken");
      const refreshToken: string = action.payload;
      return {
        refreshToken: refreshToken,
        accessToken: state.accessToken,
        checkedCookies: state.checkedCookies
      };
    }
    case ADD_ACCESS_TOKEN: {
      console.log("[Redux] adding accessToken");
      const accessToken: AccessToken = action.payload;
      return {
        refreshToken: state.refreshToken,
        accessToken: accessToken,
        checkedCookies: state.checkedCookies
      };
    }
    case REMOVE_TOKENS: {
      return {
        refreshToken: null,
        accessToken: null,
        checkedCookies: state.checkedCookies
      };
    }
    case CHECKED_COOKIES: {
      return {
        refreshToken: state.refreshToken,
        accessToken: state.accessToken,
        checkedCookies: action.payload
      };
    }
    default:
      return state;
  }
}