11import { isEmpty } from 'lodash' ;
22import { authReducer } from '../authReducer' ;
3- import { SET_CURRENT_USER , SET_HEADER_DATA } from '../../constants/auth' ;
3+ import { SET_CURRENT_USER , SET_HEADER_DATA , START_FORCE_LOGOUT } from '../../constants/auth' ;
44
55describe ( 'authReducer' , ( ) => {
66 const initialState = {
77 isAuthenticated : false ,
88 user : { } ,
99 firstName : '' ,
1010 profilePic : '' ,
11+ forceLogoutAt : null ,
12+ timerId : null ,
1113 } ;
1214
1315 it ( 'should return the initial state when action type is unknown' , ( ) => {
1416 const action = { type : 'UNKNOWN_ACTION' } ;
1517 expect ( authReducer ( undefined , action ) ) . toEqual ( initialState ) ;
1618 } ) ;
17-
1819 it ( 'should handle SET_CURRENT_USER with null payload (logout scenario)' , ( ) => {
1920 const action = { type : SET_CURRENT_USER , payload : null } ;
2021 expect ( authReducer ( initialState , action ) ) . toEqual ( initialState ) ;
2122 } ) ;
22-
2323 it ( 'should handle SET_CURRENT_USER with a new user' , ( ) => {
2424 const newUser = { new : true , id : '1' , name : 'New User' } ;
2525 const action = { type : SET_CURRENT_USER , payload : newUser } ;
@@ -30,7 +30,6 @@ describe('authReducer', () => {
3030 } ;
3131 expect ( authReducer ( initialState , action ) ) . toEqual ( expectedState ) ;
3232 } ) ;
33-
3433 it ( 'should handle SET_CURRENT_USER with a valid user (login scenario)' , ( ) => {
3534 const userPayload = { id : '123' , name : 'John Doe' } ;
3635 const action = { type : SET_CURRENT_USER , payload : userPayload } ;
@@ -41,7 +40,6 @@ describe('authReducer', () => {
4140 } ;
4241 expect ( authReducer ( initialState , action ) ) . toEqual ( expectedState ) ;
4342 } ) ;
44-
4543 it ( 'should handle SET_HEADER_DATA' , ( ) => {
4644 const headerData = {
4745 firstName : 'John' ,
@@ -55,4 +53,21 @@ describe('authReducer', () => {
5553 } ;
5654 expect ( authReducer ( initialState , action ) ) . toEqual ( expectedState ) ;
5755 } ) ;
56+ it ( 'should handle START_FORCE_LOGOUT' , ( ) => {
57+ const logoutTime = Date . now ( ) + 60000 ; // 1 minute from now
58+ const timerId = 123 ;
59+ const action = {
60+ type : START_FORCE_LOGOUT ,
61+ payload : {
62+ forceLogoutAt : logoutTime ,
63+ timerId,
64+ } ,
65+ } ;
66+ const expectedState = {
67+ ...initialState ,
68+ forceLogoutAt : logoutTime ,
69+ timerId,
70+ } ;
71+ expect ( authReducer ( initialState , action ) ) . toEqual ( expectedState ) ;
72+ } ) ;
5873} ) ;
0 commit comments