1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ import * as mockFetch from '../../mock_fetch' ;
19
+ import { signUp , SignUpRequest } from '../../../src/api/authentication/sign_up' ;
20
+ import { expect } from 'chai' ;
21
+ import { Endpoint } from '../../../src/api' ;
22
+ import { ServerError } from '../../../src/api/errors' ;
23
+ import { mockEndpoint , mockAuth } from '../helper' ;
24
+
25
+ describe ( 'signUp' , ( ) => {
26
+ const request : SignUpRequest = {
27
+ returnSecureToken : true ,
28
+
29
+ password : 'my-password'
30
+ } ;
31
+
32
+ beforeEach ( mockFetch . setUp ) ;
33
+ afterEach ( mockFetch . tearDown ) ;
34
+
35
+ it ( 'should POST to the correct endpoint' , async ( ) => {
36
+ const mock = mockEndpoint ( Endpoint . SIGN_UP , { displayName :
'my-name' , email :
'[email protected] ' } ) ;
37
+
38
+ const response = await signUp ( mockAuth , request ) ;
39
+ expect ( response . displayName ) . to . eq ( 'my-name' ) ;
40
+ expect ( response . email ) . to . eq ( '[email protected] ' ) ;
41
+ expect ( mock . calls [ 0 ] ) . to . eql ( {
42
+ request
43
+ } ) ;
44
+ } ) ;
45
+
46
+ it ( 'should handle errors' , async ( ) => {
47
+ const mock = mockEndpoint ( Endpoint . SIGN_UP , {
48
+ error : {
49
+ code : 400 ,
50
+ message : ServerError . EMAIL_EXISTS ,
51
+ errors : [
52
+ {
53
+ message : ServerError . EMAIL_EXISTS ,
54
+ }
55
+ ]
56
+ }
57
+ } , 400 ) ;
58
+
59
+ try {
60
+ await signUp ( mockAuth , request ) ;
61
+ } catch ( e ) {
62
+ expect ( e . name ) . to . eq ( 'FirebaseError' ) ;
63
+ expect ( e . message ) . to . eq ( 'Firebase: The email address is already in use by another account. (auth/email-already-in-use).' ) ;
64
+ expect ( mock . calls [ 0 ] ) . to . eql ( {
65
+ request
66
+ } ) ;
67
+ }
68
+ } ) ;
69
+ } ) ;
0 commit comments