This repository was archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsession.test.js
More file actions
140 lines (112 loc) · 3.82 KB
/
Copy pathsession.test.js
File metadata and controls
140 lines (112 loc) · 3.82 KB
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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import {
call, race, take, put, takeLatest, delay, spawn,
} from 'redux-saga/effects'
import { cloneableGenerator } from '@redux-saga/testing-utils'
import { loggedOutWatcher } from 'sagas/initialize'
import { sessionWatcher, sessionTimeout, handleLogout } from 'sagas/session'
import * as actionTypes from 'constants/actionTypes'
import { env } from 'config'
const timeoutLength = env.SessionTimeout()
describe('The handleLogout saga', () => {
describe('if the user logged out', () => {
const generator = handleLogout()
it('spawns the loggedOutWatcher', () => {
expect(generator.next().value)
.toEqual(spawn(loggedOutWatcher))
})
it('redirects to the login screen', () => {
expect(generator.next().value)
.toEqual(call(env.History().push, '/login'))
})
it('is done', () => {
expect(generator.next().done).toEqual(true)
})
})
describe('if the session timed out', () => {
const generator = handleLogout(true)
it('spawns the loggedOutWatcher', () => {
expect(generator.next().value)
.toEqual(spawn(loggedOutWatcher))
})
it('redirects to the token error screen', () => {
expect(generator.next().value)
.toEqual(call(env.History().push, '/token'))
})
it('is done', () => {
expect(generator.next().done).toEqual(true)
})
})
})
describe('The sessionTimeout saga', () => {
const generator = cloneableGenerator(sessionTimeout)()
it('waits for the RENEW_SESSION action or the timeout length to pass', () => {
expect(generator.next().value)
.toEqual(race({
timeout: delay((timeoutLength - 1) * 60000),
renew: take(actionTypes.RENEW_SESSION),
}))
})
describe('if the session is renewed', () => {
const renewed = generator.clone()
renewed.next()
it('restarts the sessionTimeout', () => {
expect(renewed.next({ renew: { type: actionTypes.RENEW_SESSION } }).value)
.toEqual(call(sessionTimeout))
})
it('is done', () => {
expect(renewed.next().done).toEqual(true)
})
})
describe('if the session times out', () => {
const timeout = generator.clone()
timeout.next()
it('displays the Timeout Warning', () => {
expect(timeout.next({ timeout: true }).value)
.toEqual(put({ type: actionTypes.SHOW_SESSION_WARNING }))
})
it('waits for the RENEW_SESSION action or one minute to pass', () => {
expect(timeout.next().value)
.toEqual(race({
logout: delay(60000),
renew: take(actionTypes.RENEW_SESSION),
}))
})
describe('if the Timeout Warning times out', () => {
const logout = generator.clone()
logout.next()
logout.next({ timeout: true })
logout.next()
it('calls handleLogout', () => {
expect(logout.next({ logout: true }).value)
.toEqual(call(handleLogout, true))
})
it('is done', () => {
expect(logout.next().done).toEqual(true)
})
})
describe('if the session is renwed', () => {
const renewed = generator.clone()
renewed.next()
renewed.next({ timeout: true })
renewed.next()
it('hides the TimeoutWarning', () => {
expect(renewed.next({ renew: { type: actionTypes.RENEW_SESSION } }).value)
.toEqual(put({ type: actionTypes.HIDE_SESSION_WARNING }))
})
it('restarts the sessionTimeout', () => {
expect(renewed.next().value)
.toEqual(call(sessionTimeout))
})
it('is done', () => {
expect(renewed.next().done).toEqual(true)
})
})
})
})
describe('The sessionWatcher saga', () => {
const generator = sessionWatcher()
it('starts a session with the FETCH_STATUS_SUCCESS action', () => {
expect(generator.next().value)
.toEqual(takeLatest(actionTypes.FETCH_STATUS_SUCCESS, sessionTimeout))
})
})