-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathauth.spec.js
More file actions
107 lines (93 loc) · 2.67 KB
/
auth.spec.js
File metadata and controls
107 lines (93 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { call, take, put, apply } from 'redux-saga/effects'
import firebase from 'firebase/app'
import {
SIGN_IN_REQUEST,
SIGN_IN_ERROR,
SIGN_UP_SUCCESS,
SIGN_UP_ERROR,
SIGN_IN_MAX_TRIES_ERROR,
signInSaga,
signUpSaga
} from './auth'
describe('Saga', () => {
describe('sign in', () => {
it('should success', () => {
const saga = signInSaga()
expect(saga.next().value).toEqual(take(SIGN_IN_REQUEST))
const payload = { email: 'test@test.com', password: 'test password' }
const auth = firebase.auth()
expect(saga.next({ payload }).value).toEqual(
apply(auth, auth.signInWithEmailAndPassword, [
payload.email,
payload.password
])
)
})
const checkIncorrectSignIn = (saga) => {
expect(saga.next().value).toEqual(take(SIGN_IN_REQUEST))
const payload = { email: 'test@test.com', password: 'test password' }
const auth = firebase.auth()
expect(saga.next({ payload }).value).toEqual(
apply(auth, auth.signInWithEmailAndPassword, [
payload.email,
payload.password
])
)
const error = new Error('error')
expect(saga.throw(error).value).toEqual(
put({ type: SIGN_IN_ERROR, error })
)
}
it('should error', () => {
const saga = signInSaga()
for (let i = 0; i < 3; i++) {
checkIncorrectSignIn(saga)
}
expect(saga.next().value).toEqual(
put({
type: SIGN_IN_MAX_TRIES_ERROR
})
)
})
})
describe('sign up', () => {
it('should success', () => {
const action = {
payload: { email: 'test@test.conm', password: 'pass12345678' }
}
const { payload } = action
const auth = firebase.auth()
const saga = signUpSaga(action)
expect(saga.next().value).toEqual(
call(
[auth, auth.createUserWithEmailAndPassword],
payload.email,
payload.password
)
)
const user = { firstName: 'testName' }
expect(saga.next(user).value).toEqual(
put({ type: SIGN_UP_SUCCESS, payload: { user } })
)
})
it('should error', () => {
const action = {
payload: { email: 'test@test.conm', password: 'pass12345678' }
}
const { payload } = action
const auth = firebase.auth()
const saga = signUpSaga(action)
expect(saga.next().value).toEqual(
call(
[auth, auth.createUserWithEmailAndPassword],
payload.email,
payload.password
)
)
const error = new Error('error msg')
expect(saga.throw(error).value).toEqual(
put({ type: SIGN_UP_ERROR, error })
)
})
})
})