18
18
import { FirebaseError } from '@firebase/util' ;
19
19
import { expect , use } from 'chai' ;
20
20
import * as chaiAsPromised from 'chai-as-promised' ;
21
- import { SinonStub , stub } from 'sinon' ;
21
+ import * as sinonChai from 'sinon-chai' ;
22
+ import { SinonStub , stub , restore } from 'sinon' ;
22
23
import { mockEndpoint } from '../../../test/api/helper' ;
23
- import { mockAuth } from '../../../test/mock_auth' ;
24
+ import { mockAuth , testUser } from '../../../test/mock_auth' ;
24
25
import * as mockFetch from '../../../test/mock_fetch' ;
25
26
import { Endpoint } from '../../api' ;
27
+ import { GetOobCodeRequestType } from '../../api/authentication/email_and_password' ;
26
28
import { ServerError } from '../../api/errors' ;
27
29
import { ProviderId } from '../providers' ;
28
30
import * as location from '../util/location' ;
29
- import { fetchSignInMethodsForEmail } from './email' ;
31
+ import { fetchSignInMethodsForEmail , sendEmailVerification } from './email' ;
30
32
31
33
use ( chaiAsPromised ) ;
34
+ use ( sinonChai ) ;
32
35
33
36
describe ( 'fetchSignInMethodsForEmail' , ( ) => {
34
37
const email = '[email protected] ' ;
@@ -94,3 +97,63 @@ describe('fetchSignInMethodsForEmail', () => {
94
97
expect ( mock . calls . length ) . to . eq ( 1 ) ;
95
98
} ) ;
96
99
} ) ;
100
+
101
+ describe ( 'sendEmailVerification' , ( ) => {
102
+ const email = '[email protected] ' ;
103
+ const user = testUser ( 'my-user-uid' , email ) ;
104
+ const idToken = 'id-token' ;
105
+ let idTokenStub : SinonStub ;
106
+ let reloadStub : SinonStub ;
107
+
108
+ beforeEach ( ( ) => {
109
+ mockFetch . setUp ( ) ;
110
+ idTokenStub = stub ( user , 'getIdToken' ) ;
111
+ idTokenStub . callsFake ( async ( ) => idToken ) ;
112
+ reloadStub = stub ( user , 'reload' ) ;
113
+ } ) ;
114
+
115
+ afterEach ( ( ) => {
116
+ mockFetch . tearDown ( ) ;
117
+ restore ( ) ;
118
+ } ) ;
119
+
120
+ it ( 'should send the email verification' , async ( ) => {
121
+ const mock = mockEndpoint ( Endpoint . SEND_OOB_CODE , {
122
+ email
123
+ } ) ;
124
+
125
+ await sendEmailVerification ( mockAuth , user ) ;
126
+
127
+ expect ( reloadStub ) . to . not . have . been . called ;
128
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( {
129
+ requestType : GetOobCodeRequestType . VERIFY_EMAIL ,
130
+ idToken
131
+ } ) ;
132
+ } ) ;
133
+
134
+ it ( 'should reload the user if the API returns a different email' , async ( ) => {
135
+ const mock = mockEndpoint ( Endpoint . SEND_OOB_CODE , {
136
+
137
+ } ) ;
138
+
139
+ await sendEmailVerification ( mockAuth , user ) ;
140
+
141
+ expect ( reloadStub ) . to . have . been . calledOnce ;
142
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( {
143
+ requestType : GetOobCodeRequestType . VERIFY_EMAIL ,
144
+ idToken
145
+ } ) ;
146
+ } ) ;
147
+
148
+ context ( 'on iOS' , ( ) => {
149
+ it ( 'should pass action code parameters' , ( ) => {
150
+
151
+ } ) ;
152
+ } ) ;
153
+
154
+ context ( 'on Android' , ( ) => {
155
+ it ( 'should pass action code parameters' , ( ) => {
156
+
157
+ } ) ;
158
+ } ) ;
159
+ } ) ;
0 commit comments