|
1 import { sessions } from '../sessionsReducer'; |
|
2 import SessionRecord from '../../store/sessionRecord'; |
|
3 import * as types from '../../constants/actionTypes'; |
|
4 import { ActionEnum } from '../../constants'; |
|
5 |
|
6 |
|
7 describe('sessions reducer lastSync', () => { |
|
8 |
|
9 it('should return the initial state', () => { |
|
10 expect( |
|
11 sessions(undefined, {}) |
|
12 ).toEqual([]) |
|
13 }); |
|
14 |
|
15 it('should handle types.CREATE_SESSION' , () => { |
|
16 const initialState = [ |
|
17 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
18 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
19 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
20 ]; |
|
21 |
|
22 expect( |
|
23 sessions(initialState, { |
|
24 type: types.CREATE_SESSION, |
|
25 session: { |
|
26 _id: 'session4', |
|
27 title: 'Session title 4' |
|
28 } |
|
29 }) |
|
30 ).toEqual([ |
|
31 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
32 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
33 SessionRecord({ _id: 'session3', title: 'Session title 3' }), |
|
34 SessionRecord({ _id: 'session4', title: 'Session title 4' }) |
|
35 ]); |
|
36 |
|
37 }); |
|
38 |
|
39 it('should handle types.UPDATE_SESSION' , () => { |
|
40 const initialState = [ |
|
41 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
42 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
43 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
44 ]; |
|
45 |
|
46 expect( |
|
47 sessions(initialState, { |
|
48 type: types.UPDATE_SESSION, |
|
49 sessionId: 'session2', |
|
50 values: { |
|
51 title: 'New session title 2' |
|
52 } |
|
53 }) |
|
54 ).toEqual([ |
|
55 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
56 SessionRecord({ _id: 'session2', title: 'New session title 2', action: ActionEnum.UPDATED }), |
|
57 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
58 ]); |
|
59 }); |
|
60 |
|
61 |
|
62 it('should handle types.UPDATE_SESSION not found', () => { |
|
63 const initialState = [ |
|
64 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
65 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
66 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
67 ]; |
|
68 |
|
69 expect( |
|
70 sessions(initialState, { |
|
71 type: types.UPDATE_SESSION, |
|
72 sessionId: 'session0', |
|
73 values: { |
|
74 title: 'New session title 0' |
|
75 } |
|
76 }) |
|
77 ).toEqual([ |
|
78 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
79 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
80 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
81 ]); |
|
82 }); |
|
83 |
|
84 it('should handle types.UPDATE_SESSION CREATED' , () => { |
|
85 const initialState = [ |
|
86 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
87 SessionRecord({ _id: 'session2', title: 'Session title 2', action: ActionEnum.CREATED }), |
|
88 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
89 ]; |
|
90 |
|
91 expect( |
|
92 sessions(initialState, { |
|
93 type: types.UPDATE_SESSION, |
|
94 sessionId: 'session2', |
|
95 values: { |
|
96 title: 'New session title 2' |
|
97 } |
|
98 }) |
|
99 ).toEqual([ |
|
100 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
101 SessionRecord({ _id: 'session2', title: 'New session title 2', action: ActionEnum.CREATED }), |
|
102 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
103 ]); |
|
104 }); |
|
105 |
|
106 |
|
107 it('should handle types.UPDATE_SESSION DELETED' , () => { |
|
108 const initialState = [ |
|
109 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
110 SessionRecord({ _id: 'session2', title: 'Session title 2', action: ActionEnum.DELETED }), |
|
111 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
112 ]; |
|
113 |
|
114 expect( |
|
115 sessions(initialState, { |
|
116 type: types.UPDATE_SESSION, |
|
117 sessionId: 'session2', |
|
118 values: { |
|
119 title: 'New session title 2' |
|
120 } |
|
121 }) |
|
122 ).toEqual([ |
|
123 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
124 SessionRecord({ _id: 'session2', title: 'New session title 2', action: ActionEnum.DELETED }), |
|
125 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
126 ]); |
|
127 }); |
|
128 |
|
129 |
|
130 it('should handle types.DO_DELETE_SESSION', () => { |
|
131 const initialState = [ |
|
132 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
133 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
134 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
135 ]; |
|
136 |
|
137 expect( |
|
138 sessions(initialState, { |
|
139 type: types.DO_DELETE_SESSION, |
|
140 sessionId: 'session2' |
|
141 }) |
|
142 ).toEqual([ |
|
143 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
144 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
145 ]); |
|
146 |
|
147 }); |
|
148 |
|
149 it('should handle types.DO_DELETE_SESSION unknown', () => { |
|
150 const initialState = [ |
|
151 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
152 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
153 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
154 ]; |
|
155 |
|
156 expect( |
|
157 sessions(initialState, { |
|
158 type: types.DO_DELETE_SESSION, |
|
159 sessionId: 'session0' |
|
160 }) |
|
161 ).toEqual([ |
|
162 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
163 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
164 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
165 ]); |
|
166 |
|
167 }); |
|
168 |
|
169 |
|
170 it('should handle types.DELETE_SESSION' , () => { |
|
171 const initialState = [ |
|
172 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
173 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
174 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
175 ]; |
|
176 |
|
177 expect( |
|
178 sessions(initialState, { |
|
179 type: types.DELETE_SESSION, |
|
180 sessionId: 'session2' |
|
181 }) |
|
182 ).toEqual([ |
|
183 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
184 SessionRecord({ _id: 'session2', title: 'Session title 2', action: ActionEnum.DELETED }), |
|
185 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
186 ]); |
|
187 |
|
188 }); |
|
189 |
|
190 it('should handle types.DELETE_SESSION unknown' , () => { |
|
191 const initialState = [ |
|
192 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
193 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
194 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
195 ]; |
|
196 |
|
197 expect( |
|
198 sessions(initialState, { |
|
199 type: types.DELETE_SESSION, |
|
200 sessionId: 'session0' |
|
201 }) |
|
202 ).toEqual([ |
|
203 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
204 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
205 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
206 ]); |
|
207 |
|
208 }); |
|
209 |
|
210 it('should handle types.LOAD_SESSIONS' , () => { |
|
211 const initialState = [ |
|
212 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
213 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
214 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
215 ]; |
|
216 |
|
217 expect( |
|
218 sessions(initialState, { |
|
219 type: types.LOAD_SESSIONS, |
|
220 sessions: [ |
|
221 SessionRecord({ _id: 'session1bis', title: 'Session title 1 bis' }), |
|
222 SessionRecord({ _id: 'session2bis', title: 'Session title 2 bis' }), |
|
223 SessionRecord({ _id: 'session3bis', title: 'Session title 3 bis' }) |
|
224 ] |
|
225 }) |
|
226 ).toEqual([ |
|
227 SessionRecord({ _id: 'session1bis', title: 'Session title 1 bis' }), |
|
228 SessionRecord({ _id: 'session2bis', title: 'Session title 2 bis' }), |
|
229 SessionRecord({ _id: 'session3bis', title: 'Session title 3 bis' }) |
|
230 ]); |
|
231 |
|
232 }); |
|
233 |
|
234 it('should handle types.LOAD_SESSION', () => { |
|
235 const newSession = SessionRecord({ _id: 'session2', title: 'New session title 2' }); |
|
236 const initialState = [ |
|
237 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
238 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
239 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
240 ]; |
|
241 |
|
242 expect( |
|
243 sessions(initialState, { |
|
244 type: types.LOAD_SESSION, |
|
245 session: newSession, |
|
246 }) |
|
247 ).toEqual([ |
|
248 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
249 SessionRecord({ _id: 'session2', title: 'New session title 2' }), |
|
250 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
251 ]); |
|
252 |
|
253 }); |
|
254 |
|
255 it('should handle types.LOAD_SESSION new', () => { |
|
256 const newSession = SessionRecord({ _id: 'session0', title: 'Session title 0' }); |
|
257 const initialState = [ |
|
258 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
259 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
260 SessionRecord({ _id: 'session3', title: 'Session title 3' }) |
|
261 ]; |
|
262 |
|
263 expect( |
|
264 sessions(initialState, { |
|
265 type: types.LOAD_SESSION, |
|
266 session: newSession, |
|
267 }) |
|
268 ).toEqual([ |
|
269 SessionRecord({ _id: 'session1', title: 'Session title 1' }), |
|
270 SessionRecord({ _id: 'session2', title: 'Session title 2' }), |
|
271 SessionRecord({ _id: 'session3', title: 'Session title 3' }), |
|
272 SessionRecord({ _id: 'session0', title: 'Session title 0' }) |
|
273 ]); |
|
274 |
|
275 }); |
|
276 |
|
277 |
|
278 it('should handle types.SYNC_RESET_ALL' , () => { |
|
279 const initialState = [ |
|
280 SessionRecord({ _id: 'session1', title: 'Session title 1', action: ActionEnum.DELETED }), |
|
281 SessionRecord({ _id: 'session2', title: 'Session title 2', action: ActionEnum.CREATED }), |
|
282 SessionRecord({ _id: 'session3', title: 'Session title 3', action: ActionEnum.UPDATED }), |
|
283 SessionRecord({ _id: 'session4', title: 'Session title 4', action: ActionEnum.NONE }) |
|
284 ]; |
|
285 |
|
286 expect( |
|
287 sessions(initialState, { |
|
288 type: types.SYNC_RESET_ALL |
|
289 }) |
|
290 ).toEqual([ |
|
291 SessionRecord({ _id: 'session1', title: 'Session title 1', action: ActionEnum.NONE }), |
|
292 SessionRecord({ _id: 'session2', title: 'Session title 2', action: ActionEnum.NONE }), |
|
293 SessionRecord({ _id: 'session3', title: 'Session title 3', action: ActionEnum.NONE }), |
|
294 SessionRecord({ _id: 'session4', title: 'Session title 4', action: ActionEnum.NONE }) |
|
295 ]); |
|
296 |
|
297 }); |
|
298 |
|
299 it('should handle types.RESET_ACTION_SESSION', () => { |
|
300 const initialState = [ |
|
301 SessionRecord({ _id: 'session1', title: 'Session title 1', action: ActionEnum.DELETED }), |
|
302 SessionRecord({ _id: 'session2', title: 'Session title 2', action: ActionEnum.CREATED }), |
|
303 SessionRecord({ _id: 'session3', title: 'Session title 3', action: ActionEnum.UPDATED }), |
|
304 SessionRecord({ _id: 'session4', title: 'Session title 4', action: ActionEnum.NONE }) |
|
305 ]; |
|
306 |
|
307 expect( |
|
308 sessions(initialState, { |
|
309 type: types.RESET_ACTION_SESSION, |
|
310 sessionId: 'session2' |
|
311 }) |
|
312 ).toEqual([ |
|
313 SessionRecord({ _id: 'session1', title: 'Session title 1', action: ActionEnum.DELETED }), |
|
314 SessionRecord({ _id: 'session2', title: 'Session title 2', action: ActionEnum.NONE }), |
|
315 SessionRecord({ _id: 'session3', title: 'Session title 3', action: ActionEnum.UPDATED }), |
|
316 SessionRecord({ _id: 'session4', title: 'Session title 4', action: ActionEnum.NONE }) |
|
317 ]); |
|
318 |
|
319 }); |
|
320 |
|
321 it('should handle types.AUTH_LOGOUT', () => { |
|
322 const initialState = [ |
|
323 SessionRecord({ _id: 'session1', title: 'Session title 1', action: ActionEnum.DELETED }), |
|
324 SessionRecord({ _id: 'session2', title: 'Session title 2', action: ActionEnum.CREATED }), |
|
325 SessionRecord({ _id: 'session3', title: 'Session title 3', action: ActionEnum.UPDATED }), |
|
326 SessionRecord({ _id: 'session4', title: 'Session title 4', action: ActionEnum.NONE }) |
|
327 ]; |
|
328 |
|
329 expect( |
|
330 sessions(initialState, { |
|
331 type: types.AUTH_LOGOUT |
|
332 }) |
|
333 ).toEqual([]); |
|
334 |
|
335 }); |
|
336 |
|
337 |
|
338 }); |