8000 feat(tests): tests added for `userFirestoreForProfile` · srsedev/react-redux-firebase@c51e01a · GitHub
[go: up one dir, main page]

Skip to content

Commit c51e01a

Browse files
committed
feat(tests): tests added for userFirestoreForProfile
1 parent d82b80c commit c51e01a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

test/unit/actions/auth.spec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
confirmPasswordReset,
1818
verifyPasswordResetCode
1919
} from '../../../src/actions/auth'
20+
import { cloneDeep } from 'lodash'
2021
import { actionTypes } from '../../../src/constants'
2122
import {
2223
fakeFirebase,
@@ -76,6 +77,19 @@ describe('Actions: Auth -', () => {
7677
unWatchUserProfile(fakeFirebase)
7778
expect(fakeFirebase._.profileWatch).to.equal(null)
7879
})
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+
})
7993
})
8094

8195
describe('handleProfileWatchResponse -', () => {
@@ -86,7 +100,46 @@ describe('Actions: Auth -', () => {
86100
profile = { email: 'test@test.com' }
87101
profileSnap = { val: () => profile }
88102
})
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+
89134
describe('profileParamsToPopulate setting -', () => {
135+
let consoleWarnSpy
136+
137+
beforeEach(() => {
138+
consoleWarnSpy = sinon.spy(console, 'warn')
139+
})
140+
afterEach(() => {
141+
consoleWarnSpy.restore()
142+
})
90143
it('undefined - dispatches SET_PROFILE with profile', () => {
91144
firebase._.config.profileParamsToPopulate = undefined
92145
handleProfileWatchResponse(dispatchSpy, firebase, profileSnap)
@@ -113,6 +166,18 @@ describe('Actions: Auth -', () => {
113166
// expect(dispatchSpy)
114167
// .to.be.calledWith({ type: actionTypes.SET_PROFILE })
115168
})
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+
})
116181
})
117182
})
118183

0 commit comments

Comments
 (0)
0