@@ -22,10 +22,11 @@ import chaiAsPromised from 'chai-as-promised';
22
22
import { FirebaseError , getUA , querystringDecode } from '@firebase/util' ;
23
23
24
24
import { Endpoint , HttpHeader } from '../' ;
25
+ import { mockEndpoint } from '../../../test/helpers/api/helper' ;
25
26
import { testAuth , TestAuth } from '../../../test/helpers/mock_auth' ;
26
27
import * as fetch from '../../../test/helpers/mock_fetch' ;
27
28
import { ServerError } from '../errors' ;
28
- import { requestStsToken } from './token' ;
29
+ import { TokenType , requestStsToken , revokeToken } from './token' ;
29
30
import { SDK_VERSION } from '@firebase/app' ;
30
31
import { _getBrowserName } from '../../core/util/browser' ;
31
32
@@ -143,3 +144,63 @@ describe('requestStsToken', () => {
143
144
} ) ;
144
145
} ) ;
145
146
} ) ;
147
+
148
+ describe ( 'api/authentication/revokeToken' , ( ) => {
149
+ const request = {
150
+ provider_id : 'provider-id' ,
151
+ tokenType : TokenType . ACCESS_TOKEN ,
152
+ token : 'token' ,
153
+ idToken : 'id-token'
154
+ } ;
155
+
156
+ let auth : TestAuth ;
157
+
158
+ beforeEach ( async ( ) => {
159
+ auth = await testAuth ( ) ;
160
+ fetch . setUp ( ) ;
161
+ } ) ;
162
+
163
+ afterEach ( ( ) => {
164
+ fetch . tearDown ( ) ;
165
+ } ) ;
166
+
167
+ it ( 'should POST to the correct endpoint' , async ( ) => {
168
+ const mock = mockEndpoint ( Endpoint . REVOKE_TOKEN , { } ) ;
169
+
170
+ auth . tenantId = 'tenant-id' ;
171
+ const response = await revokeToken ( auth , request ) ;
172
+ // Currently, backend returns an empty response.
173
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( { ...request , tenantId : 'tenant-id' } ) ;
174
+ expect ( mock . calls [ 0 ] . method ) . to . eq ( 'POST' ) ;
175
+ expect ( mock . calls [ 0 ] . headers ! . get ( HttpHeader . CONTENT_TYPE ) ) . to . eq (
176
+ 'application/json'
177
+ ) ;
178
+ expect ( mock . calls [ 0 ] . headers ! . get ( HttpHeader . X_CLIENT_VERSION ) ) . to . eq (
179
+ 'testSDK/0.0.0'
180
+ ) ;
181
+ } ) ;
182
+
183
+ it ( 'should handle errors' , async ( ) => {
184
+ const mock = mockEndpoint (
185
+ Endpoint . REVOKE_TOKEN ,
186
+ {
187
+ error : {
188
+ code : 400 ,
189
+ message : ServerError . INVALID_IDP_RESPONSE ,
190
+ errors : [
191
+ {
192
+ message : ServerError . INVALID_IDP_RESPONSE
193
+ }
194
+ ]
195
+ }
196
+ } ,
197
+ 400
198
+ ) ;
199
+
200
+ await expect ( revokeToken ( auth , request ) ) . to . be . rejectedWith (
201
+ FirebaseError ,
202
+ 'Firebase: The supplied auth credential is malformed or has expired. (auth/invalid-credential).'
203
+ ) ;
204
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
205
+ } ) ;
206
+ } ) ;
0 commit comments