@@ -19,7 +19,7 @@ import { FirebaseError } from '@firebase/util';
19
19
import { expect , use } from 'chai' ;
20
20
import * as chaiAsPromised from 'chai-as-promised' ;
21
21
import { SinonStub , stub , useFakeTimers } from 'sinon' ;
22
- import { DEFAULT_API_TIMEOUT , Endpoint , HttpMethod , performApiRequest } from '.' ;
22
+ import { DEFAULT_API_TIMEOUT_MS , Endpoint , HttpMethod , performApiRequest } from '.' ;
23
23
import { mockEndpoint } from '../../test/api/helper' ;
24
24
import { mockAuth } from '../../test/mock_auth' ;
25
25
import * as mockFetch from '../../test/mock_fetch' ;
@@ -43,7 +43,12 @@ describe('performApiRequest', () => {
43
43
44
44
it ( 'should set the correct request, method and HTTP Headers' , async ( ) => {
45
45
const mock = mockEndpoint ( Endpoint . SIGN_UP , serverResponse ) ;
46
- const response = await performApiRequest < typeof request , typeof serverResponse > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
46
+ const response = await performApiRequest < typeof request , typeof serverResponse > (
47
+ mockAuth ,
48
+ HttpMethod . POST ,
49
+ Endpoint . SIGN_UP ,
50
+ request
51
+ ) ;
47
52
expect ( response ) . to . eql ( serverResponse ) ;
48
53
expect ( mock . calls . length ) . to . eq ( 1 ) ;
49
54
expect ( mock . calls [ 0 ] . method ) . to . eq ( HttpMethod . POST ) ;
@@ -69,7 +74,12 @@ describe('performApiRequest', () => {
69
74
} ,
70
75
400
71
76
) ;
72
- const promise = performApiRequest < typeof request , typeof serverResponse > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
77
+ const promise = performApiRequest < typeof request , typeof serverResponse > (
78
+ mockAuth ,
79
+ HttpMethod . POST ,
80
+ Endpoint . SIGN_UP ,
81
+ request
82
+ ) ;
73
83
await expect ( promise ) . to . be . rejectedWith (
74
84
FirebaseError ,
75
85
'Firebase: The email address is already in use by another account. (auth/email-already-in-use).'
@@ -93,7 +103,12 @@ describe('performApiRequest', () => {
93
103
} ,
94
104
400
95
105
) ;
96
- const promise = performApiRequest < typeof request , typeof serverResponse > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
106
+ const promise = performApiRequest < typeof request , typeof serverResponse > (
107
+ mockAuth ,
108
+ HttpMethod . POST ,
109
+ Endpoint . SIGN_UP ,
110
+ request
111
+ ) ;
97
112
await expect ( promise ) . to . be . rejectedWith (
98
113
FirebaseError ,
99
114
'Firebase: An internal AuthError has occurred. (auth/internal-error).'
@@ -117,7 +132,14 @@ describe('performApiRequest', () => {
117
132
} ,
118
133
400
119
134
) ;
120
- const promise = performApiRequest < typeof request , typeof serverResponse > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request , { [ ServerError . EMAIL_EXISTS ] : AuthErrorCode . ARGUMENT_ERROR } ) ;
135
+ const promise = performApiRequest < typeof request , typeof serverResponse > (
136
+ mockAuth ,
137
+ HttpMethod . POST ,
138
+ Endpoint . SIGN_UP ,
139
+ request ,
140
+ {
141
+ [ ServerError . EMAIL_EXISTS ] : AuthErrorCode . ARGUMENT_ERROR
142
+ } ) ;
121
143
await expect ( promise ) . to . be . rejectedWith (
122
144
FirebaseError ,
123
145
'Firebase: Error (auth/argument-error).'
@@ -142,8 +164,13 @@ describe('performApiRequest', () => {
142
164
fetchStub . callsFake ( ( ) => {
143
165
return new Promise < never > ( ( ) => null ) ;
144
166
} ) ;
145
- const promise = performApiRequest < typeof request , never > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
146
- clock . tick ( DEFAULT_API_TIMEOUT + 1 ) ;
167
+ const promise = performApiRequest < typeof request , never > (
168
+ mockAuth ,
169
+ HttpMethod . POST ,
170
+ Endpoint . SIGN_UP ,
171
+ request
172
+ ) ;
173
+ clock . tick ( DEFAULT_API_TIMEOUT_MS + 1 ) ;
147
174
await expect ( promise ) . to . be . rejectedWith ( FirebaseError , 'Firebase: The operation has timed out. (auth/timeout).' ) ;
148
175
clock . restore ( ) ;
149
176
} ) ;
@@ -152,7 +179,12 @@ describe('performApiRequest', () => {
152
179
fetchStub . callsFake ( ( ) => {
153
180
return new Promise < never > ( ( _ , reject ) => reject ( new Error ( 'network error' ) ) ) ;
154
181
} ) ;
155
- const promise = performApiRequest < typeof request , never > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
182
+ const promise = performApiRequest < typeof request , never > (
183
+ mockAuth ,
184
+ HttpMethod . POST ,
185
+ Endpoint . SIGN_UP ,
186
+ request
187
+ ) ;
156
188
await expect ( promise ) . to . be . rejectedWith ( FirebaseError , 'Firebase: A network AuthError (such as timeout]: interrupted connection or unreachable host) has occurred. (auth/network-request-failed).' ) ;
157
189
} ) ;
158
190
} ) ;
0 commit comments