-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathauth.spec.js
More file actions
81 lines (68 loc) · 1.57 KB
/
auth.spec.js
File metadata and controls
81 lines (68 loc) · 1.57 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
import { call, put, apply } from 'redux-saga/effects'
import firebase from 'firebase/app'
import {
SIGN_UP_REQUEST,
SIGN_UP_SUCCESS,
SIGN_IN_REQUEST,
SIGN_IN_SUCCESS,
signUpSaga,
signInSaga
} from './auth'
describe('Auth duck sign up saga', () => {
it('should sign up with new email and password', () => {
const auth = firebase.auth()
const credentials = {
email: `test${+new Date()}@test.com`,
password: 'qwerty123'
}
const action = {
type: SIGN_UP_REQUEST,
payload: credentials
}
const saga = signUpSaga(action)
expect(saga.next().value).toEqual(
call(
[auth, auth.createUserWithEmailAndPassword],
credentials.email,
credentials.password
)
)
const user = {
email: credentials.email,
uid: '123'
}
expect(saga.next(user).value).toEqual(
put({
type: SIGN_UP_SUCCESS,
payload: { user }
})
)
})
it('should sign in', () => {
const auth = firebase.auth()
const credentials = {
email: `test${+new Date()}@test.com`,
password: 'qwerty123'
}
const action = {
type: SIGN_IN_REQUEST,
payload: credentials
}
const saga = signInSaga(action)
expect(saga.next().value).toEqual(
apply(auth, auth.signInWithEmailAndPassword, [
credentials.email,
credentials.password
])
)
const user = {
email: credentials.email
}
expect(saga.next(user).value).toEqual(
put({
type: SIGN_IN_SUCCESS,
payload: { user }
})
)
})
})