|
1 | | -/* eslint-disable no-undefined */ |
2 | 1 | import { |
3 | 2 | INIT_AUTH, |
4 | 3 | SIGN_IN_SUCCESS, |
5 | 4 | SIGN_OUT_SUCCESS |
6 | 5 | } from './action-types'; |
7 | 6 |
|
8 | | -import { |
9 | | - authReducer, |
10 | | - initialState |
11 | | -} from './reducer'; |
| 7 | +import { authReducer } from './reducer'; |
12 | 8 |
|
13 | 9 |
|
14 | 10 | describe('Auth reducer', () => { |
15 | | - it('should return the initial state when action.type is not found', () => { |
16 | | - expect(authReducer(undefined, {})).toEqual(initialState); |
17 | | - }); |
18 | | - |
19 | | - |
20 | 11 | describe('INIT_AUTH', () => { |
21 | | - it('should return state as `unauthenticated` when payload is `null`', () => { |
22 | | - let state = authReducer(initialState, { |
| 12 | + it('should set AuthState.authenticated to false when payload is null', () => { |
| 13 | + let state = authReducer(undefined, { |
23 | 14 | type: INIT_AUTH, |
24 | 15 | payload: null |
25 | 16 | }); |
26 | 17 |
|
27 | | - expect(state).toEqual(initialState); |
| 18 | + expect(state.authenticated).toBe(false); |
| 19 | + expect(state.id).toBe(null); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should set AuthState.authenticated to true when payload provided', () => { |
| 23 | + let state = authReducer(undefined, { |
| 24 | + type: INIT_AUTH, |
| 25 | + payload: {uid: '123'} |
| 26 | + }); |
| 27 | + |
| 28 | + expect(state.authenticated).toBe(true); |
| 29 | + expect(state.id).toBe('123'); |
28 | 30 | }); |
29 | 31 | }); |
30 | 32 |
|
31 | 33 |
|
32 | 34 | describe('SIGN_IN_SUCCESS', () => { |
33 | | - it('should return state as `authenticated`', () => { |
34 | | - let state = authReducer(initialState, { |
| 35 | + it('should set AuthState.authenticated to true', () => { |
| 36 | + let state = authReducer(undefined, { |
35 | 37 | type: SIGN_IN_SUCCESS, |
36 | 38 | payload: {uid: '123'} |
37 | 39 | }); |
38 | 40 |
|
39 | | - expect(state).toEqual({ |
40 | | - authenticated: true, |
41 | | - id: '123' |
42 | | - }); |
| 41 | + expect(state.authenticated).toBe(true); |
| 42 | + expect(state.id).toBe('123'); |
43 | 43 | }); |
44 | 44 | }); |
45 | 45 |
|
46 | 46 |
|
47 | 47 | describe('SIGN_OUT_SUCCESS', () => { |
48 | | - it('should return state as `unauthenticated`', () => { |
49 | | - let state = authReducer(initialState, { |
50 | | - type: SIGN_OUT_SUCCESS, |
51 | | - payload: null |
| 48 | + it('should set AuthState.authenticated to false', () => { |
| 49 | + let state = authReducer(undefined, { |
| 50 | + type: SIGN_OUT_SUCCESS |
52 | 51 | }); |
53 | 52 |
|
54 | | - expect(state).toEqual(initialState); |
| 53 | + expect(state.authenticated).toBe(false); |
| 54 | + expect(state.id).toBe(null); |
55 | 55 | }); |
56 | 56 | }); |
57 | 57 | }); |
0 commit comments