@@ -15,27 +15,44 @@ const noAuth = { auth: null, profile: null }
1515const exampleData = { some : 'data' }
1616const externalState = { data : { asdfasdf : { } } }
1717const exampleState = fromJS ( { } )
18+ const exampleEmptyState = fromJS ( emptyState )
1819
1920describe ( 'reducer' , ( ) => {
2021 it ( 'is a function' , ( ) => {
2122 expect ( firebaseStateReducer )
2223 . to . be . a . function
2324 } )
2425
26+ it ( 'handles no initialState' , ( ) => {
27+ expect (
28+ JSON . stringify ( firebaseStateReducer ( undefined , { } ) . toJS ( ) ) )
29+ . to . equal ( JSON . stringify ( exampleEmptyState . toJS ( ) ) )
30+ } )
31+
2532 it ( 'returns state by default' , ( ) => {
2633 expect ( firebaseStateReducer ( exampleData ) )
2734 . to . equal ( exampleData )
2835 } )
2936
3037 describe ( 'SET action' , ( ) => {
31- it ( 'handles SET action ' , ( ) => {
38+ it ( 'deletes data from state when data is null ' , ( ) => {
3239 expect (
3340 firebaseStateReducer (
3441 exampleState ,
3542 { type : actionTypes . SET , path : 'asdfasdf' }
3643 )
3744 ) . to . equal ( exampleState )
3845 } )
46+ it ( 'sets state' , ( ) => {
47+ const path = 'asdfasdf'
48+ const pathArray = path . split ( / \/ / ) . filter ( p => ! ! p )
49+ expect (
50+ JSON . stringify ( firebaseStateReducer (
51+ exampleState ,
52+ { type : actionTypes . SET , path, data : { } }
53+ ) )
54+ ) . to . equal ( JSON . stringify ( exampleState . setIn ( [ 'data' , ...pathArray ] , fromJS ( { } ) ) ) )
55+ } )
3956 } )
4057
4158 describe ( 'NO_VALUE action' , ( ) => {
@@ -59,6 +76,15 @@ describe('reducer', () => {
5976 ) . toJS ( ) )
6077 ) . to . equal ( JSON . stringify ( { profile } ) )
6178 } )
79+ it ( 'removes for no profile' , ( ) => {
80+ const profile = { email :
'[email protected] ' } 81+ expect (
82+ JSON . stringify ( firebaseStateReducer (
83+ exampleState ,
84+ { type : actionTypes . SET_PROFILE }
85+ ) . toJS ( ) )
86+ ) . to . equal ( JSON . stringify ( exampleState . deleteIn ( [ 'profile' ] ) ) )
87+ } )
6288 } )
6389
6490 describe ( 'LOGOUT action' , ( ) => {
@@ -104,14 +130,27 @@ describe('reducer', () => {
104130 ) . to . equal ( JSON . stringify ( intializedState ) )
105131 } )
106132 } )
133+
107134 describe ( 'AUTHENTICATION_INIT_FINISHED action' , ( ) => {
108135 it ( 'sets state' , ( ) => {
109136 expect (
110137 JSON . stringify ( firebaseStateReducer (
111138 exampleState ,
112- { type : actionTypes . AUTHENTICATION_INIT_STARTED }
139+ { type : actionTypes . AUTHENTICATION_INIT_FINISHED }
113140 ) . toJS ( ) )
114- ) . to . equal ( JSON . stringify ( intializedState ) )
141+ ) . to . equal ( JSON . stringify ( exampleState . setIn ( [ 'isInitializing' ] , false ) . toJS ( ) ) )
142+ } )
143+ } )
144+
145+ describe ( 'UNAUTHORIZED_ERROR action' , ( ) => {
146+ it ( 'sets state' , ( ) => {
147+ const authError = { }
148+ expect (
149+ JSON . stringify ( firebaseStateReducer (
150+ exampleState ,
151+ { type : actionTypes . UNAUTHORIZED_ERROR , authError }
152+ ) . toJS ( ) )
153+ ) . to . equal ( JSON . stringify ( exampleState . setIn ( [ 'authError' ] , authError ) . toJS ( ) ) )
115154 } )
116155 } )
117156} )
0 commit comments