Newer
Older
import { authReducer, AuthState } from './auth.reducer';
import {
AddAuthenticationMessageAction,
AuthenticateAction,
AuthenticatedAction,
AuthenticatedErrorAction,
AuthenticatedSuccessAction,
AuthenticationErrorAction,
AuthenticationSuccessAction,
CheckAuthenticationTokenAction,
CheckAuthenticationTokenErrorAction,
LogOutAction,
LogOutErrorAction,
LogOutSuccessAction,
RedirectWhenAuthenticationIsRequiredAction,
RedirectWhenTokenExpiredAction,
ResetAuthenticationMessagesAction, RetrieveAuthenticatedEpersonErrorAction, RetrieveAuthenticatedEpersonSuccessAction,
} from './auth.actions';
import { AuthTokenInfo } from './models/auth-token-info.model';
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
describe('authReducer', () => {
let initialState: AuthState;
let state: AuthState;
const mockTokenInfo = new AuthTokenInfo('test_token');
const mockError = new Error('Test error message');
it('should properly set the state, in response to a AUTHENTICATE action', () => {
initialState = {
authenticated: false,
loaded: false,
loading: false,
};
const action = new AuthenticateAction('user', 'password');
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
error: undefined,
loading: true,
info: undefined
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a AUTHENTICATE_SUCCESS action', () => {
initialState = {
authenticated: false,
loaded: false,
error: undefined,
loading: true,
info: undefined
};
const action = new AuthenticationSuccessAction(mockTokenInfo);
const newState = authReducer(initialState, action);
expect(newState).toEqual(initialState);
});
it('should properly set the state, in response to a AUTHENTICATE_ERROR action', () => {
initialState = {
authenticated: false,
loaded: false,
error: undefined,
loading: true,
info: undefined
};
const action = new AuthenticationErrorAction(mockError);
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
loading: false,
info: undefined,
authToken: undefined,
error: 'Test error message'
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a AUTHENTICATED action', () => {
initialState = {
authenticated: false,
loaded: false,
error: undefined,
loading: true,
info: undefined
};
const action = new AuthenticatedAction(mockTokenInfo);
const newState = authReducer(initialState, action);
expect(newState).toEqual(initialState);
});
it('should properly set the state, in response to a AUTHENTICATED_SUCCESS action', () => {
initialState = {
authenticated: false,
loaded: false,
error: undefined,
loading: true,
info: undefined
};
const action = new AuthenticatedSuccessAction(true, mockTokenInfo, EPersonMock._links.self.href);
const newState = authReducer(initialState, action);
state = {
authenticated: true,
authToken: mockTokenInfo,
loading: true,
info: undefined
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a AUTHENTICATED_ERROR action', () => {
initialState = {
authenticated: false,
loaded: false,
error: undefined,
loading: true,
info: undefined
};
const action = new AuthenticatedErrorAction(mockError);
const newState = authReducer(initialState, action);
state = {
authenticated: false,
authToken: undefined,
error: 'Test error message',
loaded: true,
loading: false,
info: undefined
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a CHECK_AUTHENTICATION_TOKEN action', () => {
initialState = {
authenticated: false,
loaded: false,
loading: false,
};
const action = new CheckAuthenticationTokenAction();
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
loading: true,
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a CHECK_AUTHENTICATION_TOKEN_ERROR action', () => {
initialState = {
authenticated: false,
loaded: false,
loading: true,
};
const action = new CheckAuthenticationTokenErrorAction();
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
loading: false,
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a LOG_OUT action', () => {
initialState = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
};
const action = new LogOutAction();
const newState = authReducer(initialState, action);
expect(newState).toEqual(initialState);
});
it('should properly set the state, in response to a LOG_OUT_SUCCESS action', () => {
initialState = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
};
const action = new LogOutSuccessAction();
const newState = authReducer(initialState, action);
state = {
authenticated: false,
authToken: undefined,
error: undefined,
loaded: false,
loading: false,
info: undefined,
refreshing: false,
user: undefined
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a LOG_OUT_ERROR action', () => {
initialState = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
};
const action = new LogOutErrorAction(mockError);
const newState = authReducer(initialState, action);
state = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: 'Test error message',
loading: false,
info: undefined,
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
it('should properly set the state, in response to a RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS action', () => {
initialState = {
authenticated: true,
authToken: mockTokenInfo,
loaded: false,
error: undefined,
loading: true,
info: undefined
};
const action = new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock);
const newState = authReducer(initialState, action);
state = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
user: EPersonMock
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a RETRIEVE_AUTHENTICATED_EPERSON_ERROR action', () => {
initialState = {
authenticated: false,
loaded: false,
error: undefined,
loading: true,
info: undefined
};
const action = new RetrieveAuthenticatedEpersonErrorAction(mockError);
const newState = authReducer(initialState, action);
state = {
authenticated: false,
authToken: undefined,
error: 'Test error message',
loaded: true,
loading: false,
info: undefined
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a REFRESH_TOKEN action', () => {
initialState = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
};
const newTokenInfo = new AuthTokenInfo('Refreshed token');
const action = new RefreshTokenAction(newTokenInfo);
const newState = authReducer(initialState, action);
state = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
refreshing: true
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a REFRESH_TOKEN_SUCCESS action', () => {
initialState = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
refreshing: true
};
const newTokenInfo = new AuthTokenInfo('Refreshed token');
const action = new RefreshTokenSuccessAction(newTokenInfo);
const newState = authReducer(initialState, action);
state = {
authenticated: true,
authToken: newTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
refreshing: false
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a REFRESH_TOKEN_ERROR action', () => {
initialState = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
refreshing: true
};
const action = new RefreshTokenErrorAction();
const newState = authReducer(initialState, action);
state = {
authenticated: false,
authToken: undefined,
error: undefined,
loaded: false,
loading: false,
info: undefined,
refreshing: false,
user: undefined
};
expect(newState).toEqual(state);
});
beforeEach(() => {
initialState = {
authenticated: true,
authToken: mockTokenInfo,
loaded: true,
error: undefined,
loading: false,
info: undefined,
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
};
state = {
authenticated: false,
authToken: undefined,
loaded: false,
loading: false,
error: undefined,
info: 'Message',
user: undefined
};
});
it('should properly set the state, in response to a REDIRECT_AUTHENTICATION_REQUIRED action', () => {
const action = new RedirectWhenAuthenticationIsRequiredAction('Message');
const newState = authReducer(initialState, action);
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a REDIRECT_TOKEN_EXPIRED action', () => {
const action = new RedirectWhenTokenExpiredAction('Message');
const newState = authReducer(initialState, action);
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a ADD_MESSAGE action', () => {
initialState = {
authenticated: false,
loaded: false,
loading: false,
};
const action = new AddAuthenticationMessageAction('Message');
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
loading: false,
info: 'Message'
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a RESET_MESSAGES action', () => {
initialState = {
authenticated: false,
loaded: false,
loading: false,
error: 'Error',
info: 'Message'
};
const action = new ResetAuthenticationMessagesAction();
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
loading: false,
error: undefined,
info: undefined
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a SET_REDIRECT_URL action', () => {
initialState = {
authenticated: false,
loaded: false,
loading: false
};
const action = new SetRedirectUrlAction('redirect.url');
const newState = authReducer(initialState, action);
state = {
authenticated: false,
loaded: false,
loading: false,
redirectUrl: 'redirect.url'
};
expect(newState).toEqual(state);
});
});