import * as actions from '@client/profile/profileActions' ; import { initialState } from '@client/profile/profileReducer' ; import { createStore , AppStore } from '@client/store' ; import { mockUserResponse , getItem , mockRegistrarUserResponse } from '@client/tests/util' ; import { storage } from '@client/storage' ; storage . removeItem = jest . fn ( ) ; const removeItem = window . localStorage . removeItem as jest . Mock ; describe ( 'profileReducer tests' , ( ) => { let store ; beforeEach ( ( ) => { getItem . mockReset ( ) ; store = createStore ( ) . store ; } ) ; it ( 'sets user as logged out on bad token' , async ( ) => { const expectedState = { ... initialState , authenticated : false } ; const action = { type : actions . CHECK_AUTH , payload : { badToken : '12345' } } ; store . dispatch ( action ) ; expect ( store . getState ( ) . profile ) . toEqual ( expectedState ) ; } ) ; it ( 'sets user details' , async ( ) => { const action = { type : actions . SET_USER_DETAILS , payload : mockUserResponse } ; store . dispatch ( action ) ; expect ( store . getState ( ) . profile . userDetailsFetched ) . toEqual ( true ) ; } ) ; it ( 'sets user details for registrar' , async ( ) => { const action = { type : actions . SET_USER_DETAILS , payload : mockRegistrarUserResponse } ; store . dispatch ( action ) ; expect ( store . getState ( ) . profile . userDetailsFetched ) . toEqual ( true ) ; } ) ; it ( 'removes details, tike and logs out a user' , async ( ) => { const action = { type : actions . REDIRECT_TO_AUTHENTICATION } ; store . dispatch ( action ) ; expect ( store . getState ( ) . profile . authenticated ) . toEqual ( false ) ; expect ( store . getState ( ) . profile . userDetailsFetched ) . toEqual ( false ) ; expect ( store . getState ( ) . profile . tokenPayload ) . toEqual ( null ) ; expect ( store . getState ( ) . profile . userDetails ) . toEqual ( null ) ; expect ( storage . removeItem ) . toBeCalled ( ) ; expect ( removeItem ) . toBeCalled ( ) ; } ) ; } ) ;