@@ -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,13 +43,19 @@ 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 ) ;
50
55
expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
51
56
expect ( mock . calls [ 0 ] . headers ) . to . eql ( {
52
- 'Content-Type' : 'application/json'
57
+ 'Content-Type' : 'application/json' ,
58
+ 'X-Client-Version' : 'testSDK/0.0.0'
53
59
} ) ;
54
60
} ) ;
55
61
@@ -69,7 +75,12 @@ describe('performApiRequest', () => {
69
75
} ,
70
76
400
71
77
) ;
72
- const promise = performApiRequest < typeof request , typeof serverResponse > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
78
+ const promise = performApiRequest < typeof request , typeof serverResponse > (
79
+ mockAuth ,
80
+ HttpMethod . POST ,
81
+ Endpoint . SIGN_UP ,
82
+ request
83
+ ) ;
73
84
await expect ( promise ) . to . be . rejectedWith (
74
85
FirebaseError ,
75
86
'Firebase: The email address is already in use by another account. (auth/email-already-in-use).'
@@ -93,7 +104,12 @@ describe('performApiRequest', () => {
93
104
} ,
94
105
400
95
106
) ;
96
- const promise = performApiRequest < typeof request , typeof serverResponse > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
107
+ const promise = performApiRequest < typeof request , typeof serverResponse > (
108
+ mockAuth ,
109
+ HttpMethod . POST ,
110
+ Endpoint . SIGN_UP ,
111
+ request
112
+ ) ;
97
113
await expect ( promise ) . to . be . rejectedWith (
98
114
FirebaseError ,
99
115
'Firebase: An internal AuthError has occurred. (auth/internal-error).'
@@ -117,7 +133,14 @@ describe('performApiRequest', () => {
117
133
} ,
118
134
400
119
135
) ;
120
- const promise = performApiRequest < typeof request , typeof serverResponse > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request , { [ ServerError . EMAIL_EXISTS ] : AuthErrorCode . ARGUMENT_ERROR } ) ;
136
+ const promise = performApiRequest < typeof request , typeof serverResponse > (
137
+ mockAuth ,
138
+ HttpMethod . POST ,
139
+ Endpoint . SIGN_UP ,
140
+ request ,
141
+ {
142
+ [ ServerError . EMAIL_EXISTS ] : AuthErrorCode . ARGUMENT_ERROR
143
+ } ) ;
121
144
await expect ( promise ) . to . be . rejectedWith (
122
145
FirebaseError ,
123
146
'Firebase: Error (auth/argument-error).'
@@ -142,8 +165,13 @@ describe('performApiRequest', () => {
142
165
fetchStub . callsFake ( ( ) => {
143
166
return new Promise < never > ( ( ) => null ) ;
144
167
} ) ;
145
- const promise = performApiRequest < typeof request , never > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
146
- clock . tick ( DEFAULT_API_TIMEOUT + 1 ) ;
168
+ const promise = performApiRequest < typeof request , never > (
169
+ mockAuth ,
170
+ HttpMethod . POST ,
171
+ Endpoint . SIGN_UP ,
172
+ request
173
+ ) ;
174
+ clock . tick ( DEFAULT_API_TIMEOUT_MS + 1 ) ;
147
175
await expect ( promise ) . to . be . rejectedWith ( FirebaseError , 'Firebase: The operation has timed out. (auth/timeout).' ) ;
148
176
clock . restore ( ) ;
149
177
} ) ;
@@ -152,7 +180,12 @@ describe('performApiRequest', () => {
152
180
fetchStub . callsFake ( ( ) => {
153
181
return new Promise < never > ( ( _ , reject ) => reject ( new Error ( 'network error' ) ) ) ;
154
182
} ) ;
155
- const promise = performApiRequest < typeof request , never > ( mockAuth , HttpMethod . POST , Endpoint . SIGN_UP , request ) ;
183
+ const promise = performApiRequest < typeof request , never > (
184
+ mockAuth ,
185
+ HttpMethod . POST ,
186
+ Endpoint . SIGN_UP ,
187
+ request
188
+ ) ;
156
189
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
190
} ) ;
158
191
} ) ;
0 commit comments