@@ -17,6 +17,7 @@ import {
17
17
confirmPasswordReset ,
18
18
verifyPasswordResetCode
19
19
} from '../../../src/actions/auth'
20
+ import { cloneDeep } from 'lodash'
20
21
import { actionTypes } from '../../../src/constants'
21
22
import {
22
23
fakeFirebase ,
@@ -76,6 +77,19 @@ describe('Actions: Auth -', () => {
76
77
unWatchUserProfile ( fakeFirebase )
77
78
expect ( fakeFirebase . _ . profileWatch ) . to . equal ( null )
78
79
} )
80
+
81
+ it ( 'calls profile watch then sets to null when useFirestoreForProfile: true' , ( ) => {
82
+ let profileCalled
83
+ let currentFake = cloneDeep ( fakeFirebase )
84
+ currentFake . _ . profileWatch = ( ) => {
85
+ profileCalled = true
86
+ }
87
+ currentFake . _ . config . useFirestoreForProfile = true
88
+ currentFake . firestore = { }
89
+ unWatchUserProfile ( currentFake )
90
+ expect ( currentFake . _ . profileWatch ) . to . equal ( null )
91
+ expect ( profileCalled ) . to . equal ( true )
92
+ } )
79
93
} )
80
94
81
95
describe ( 'handleProfileWatchResponse -' , ( ) => {
@@ -86,7 +100,46 @@ describe('Actions: Auth -', () => {
86
100
profile = { email : 'test@test.com' }
87
101
profileSnap = { val : ( ) => profile }
88
102
} )
103
+
104
+ describe ( 'dispatches SET_PROFILE with profile' , ( ) => {
105
+ it ( 'from RTDB data' , ( ) => {
106
+ firebase . _ . config . profileParamsToPopulate = undefined
107
+ handleProfileWatchResponse ( dispatchSpy , firebase , profileSnap )
108
+ expect ( dispatchSpy ) . to . be . calledWith ( {
109
+ type : actionTypes . SET_PROFILE ,
110
+ profile
111
+ } )
112
+ } )
113
+
114
+ it ( 'from Firestore data' , ( ) => {
115
+ firebase . _ . config . profileParamsToPopulate = undefined
116
+ const firestoreProfileSnap = { data : ( ) => profile , exists : true }
117
+ handleProfileWatchResponse ( dispatchSpy , firebase , firestoreProfileSnap )
118
+ expect ( dispatchSpy ) . to . be . calledWith ( {
119
+ type : actionTypes . SET_PROFILE ,
120
+ profile
121
+ } )
122
+ } )
123
+
124
+ it ( 'that is an empty object (sets profile to null)' , ( ) => {
125
+ firebase . _ . config . profileParamsToPopulate = undefined
126
+ handleProfileWatchResponse ( dispatchSpy , firebase , { } )
127
+ expect ( dispatchSpy ) . to . be . calledWith ( {
128
+ type : actionTypes . SET_PROFILE ,
129
+ profile : null
130
+ } )
131
+ } )
132
+ } )
133
+
89
134
describe ( 'profileParamsToPopulate setting -' , ( ) => {
135
+ let consoleWarnSpy
136
+
137
+ beforeEach ( ( ) => {
138
+ consoleWarnSpy = sinon . spy ( console , 'warn' )
139
+ } )
140
+ afterEach ( ( ) => {
141
+ consoleWarnSpy . restore ( )
142
+ } )
90
143
it ( 'undefined - dispatches SET_PROFILE with profile' , ( ) => {
91
144
firebase . _ . config . profileParamsToPopulate = undefined
92
145
handleProfileWatchResponse ( dispatchSpy , firebase , profileSnap )
@@ -113,6 +166,18 @@ describe('Actions: Auth -', () => {
113
166
// expect(dispatchSpy)
114
167
// .to.be.calledWith({ type: actionTypes.SET_PROFILE })
115
168
} )
169
+
170
+ it ( 'Any when useFirestoreForProfile: true - calls console.warn' , ( ) => {
171
+ let currentFake = cloneDeep ( fakeFirebase )
172
+ currentFake . _ . profileWatch = ( ) => { }
173
+ currentFake . _ . config . useFirestoreForProfile = true
174
+ currentFake . _ . config . profileParamsToPopulate = [ 'some' ]
175
+ currentFake . firestore = { }
176
+ handleProfileWatchResponse ( dispatchSpy , currentFake )
177
+ expect ( consoleWarnSpy ) . to . be . calledWith (
178
+ 'Profile population is not yet supported for Firestore'
5016
179
+ )
180
+ } )
116
181
} )
117
182
} )
118
183
0 commit comments