-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathauth.test.js
More file actions
96 lines (76 loc) · 2.19 KB
/
auth.test.js
File metadata and controls
96 lines (76 loc) · 2.19 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
import firebase from 'firebase'
import {push} from 'react-router-redux'
import {all, cps, call, put, take, takeEvery} from 'redux-saga/effects'
import {
signUpSaga, signOutSaga, watchStatusChange, signInSaga, saga as authSaga,
SIGN_UP_REQUEST, SIGN_UP_SUCCESS, SIGN_UP_ERROR,
SIGN_IN_REQUEST, SIGN_IN_SUCCESS, SIGN_IN_ERROR,
SIGN_OUT_REQUEST, SIGN_OUT_SUCCESS,
} from './auth';
const auth = firebase.auth()
const user = {
email: 'a@a.aa',
password: 'aaaaaaaaaa',
}
describe('test auth sagas', () => {
it('should sign up', () => {
const saga = signUpSaga();
expect(saga.next().value).toEqual(take(SIGN_UP_REQUEST))
const action = {
type: SIGN_UP_REQUEST,
payload: { ...user }
}
expect(saga.next(action).value).toEqual(
call([auth, auth.createUserWithEmailAndPassword], user.email, user.password)
)
expect(saga.next(user).value).toEqual(put({
type: SIGN_UP_SUCCESS,
payload: { user }
}))
expect(saga.throw('test').value).toEqual(put({
type: SIGN_UP_ERROR,
error: 'test',
}))
})
it('should sign in', () => {
const action = {
type: SIGN_IN_REQUEST,
payload: { ...user }
}
const saga = signInSaga(action);
expect(saga.next().value).toEqual(
call([auth, auth.signInWithEmailAndPassword], user.email, user.password)
)
expect(saga.next(user).value).toEqual(put({
type: SIGN_IN_SUCCESS,
payload: { user }
}))
expect(saga.throw('test').value).toEqual(put({
type: SIGN_IN_ERROR,
error: 'test',
}))
})
it('should sign out', () => {
const action = {
type: SIGN_OUT_REQUEST,
}
const saga = signOutSaga(action);
expect(saga.next().value).toEqual(
call([auth, auth.signOut])
)
expect(saga.next().value).toEqual(put({
type: SIGN_OUT_SUCCESS
}))
expect(saga.next().value).toEqual(put(push('/auth/signin')))
})
it('should watch auth status', () => {
const saga = watchStatusChange();
expect(saga.next().value).toEqual(
cps([auth, auth.onAuthStateChanged])
)
expect(saga.throw(user).value).toEqual(put({
type: SIGN_IN_SUCCESS,
payload: { user },
}))
})
})