18
18
import { FirebaseError } from '@firebase/util' ;
19
19
import { expect , use } from 'chai' ;
20
20
import * as sinon from 'sinon' ;
21
+ import sinonChai from 'sinon-chai' ;
21
22
import chaiAsPromised from 'chai-as-promised' ;
22
23
23
24
import {
@@ -29,6 +30,7 @@ import { AuthInternal } from '../../model/auth';
29
30
import { UserInternal } from '../../model/user' ;
30
31
import { AuthInterop } from './firebase_internal' ;
31
32
33
+ use ( sinonChai ) ;
32
34
use ( chaiAsPromised ) ;
33
35
34
36
describe ( 'core/auth/firebase_internal' , ( ) => {
@@ -240,29 +242,29 @@ describe('core/auth/firebase_internal - Regional Firebase Auth', () => {
240
242
241
243
context ( 'getFirebaseToken' , ( ) => {
242
244
it ( 'returns null if firebase token is undefined' , async ( ) => {
243
- expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . be . null ;
245
+ expect ( await regionalAuthInternal . getToken ( ) ) . to . be . null ;
244
246
} ) ;
245
247
246
248
it ( 'returns the id token correctly' , async ( ) => {
247
249
await regionalAuth . _updateFirebaseToken ( {
248
250
token : 'access-token' ,
249
251
expirationTime : now + 300_000
250
252
} ) ;
251
- expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . eql ( {
253
+ expect ( await regionalAuthInternal . getToken ( ) ) . to . eql ( {
252
254
accessToken : 'access-token'
253
255
} ) ;
254
256
} ) ;
255
257
256
258
it ( 'logs out the the id token expires in next 30 seconds' , async ( ) => {
257
- expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . be . null ;
259
+ expect ( await regionalAuthInternal . getToken ( ) ) . to . be . null ;
258
260
} ) ;
259
261
260
262
it ( 'logs out if token has expired' , async ( ) => {
261
263
await regionalAuth . _updateFirebaseToken ( {
262
264
token : 'access-token' ,
263
265
expirationTime : now - 5_000
264
266
} ) ;
265
- expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . null ;
267
+ expect ( await regionalAuthInternal . getToken ( ) ) . to . null ;
266
268
expect ( regionalAuth . firebaseToken ) . to . null ;
267
269
} ) ;
268
270
@@ -271,8 +273,23 @@ describe('core/auth/firebase_internal - Regional Firebase Auth', () => {
271
273
token : 'access-token' ,
272
274
expirationTime : now + 5_000
273
275
} ) ;
274
- expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . null ;
276
+ expect ( await regionalAuthInternal . getToken ( ) ) . to . null ;
275
277
expect ( regionalAuth . firebaseToken ) . to . null ;
276
278
} ) ;
279
+
280
+ it ( 'logs warning if getToken is called with forceRefresh true' , async ( ) => {
281
+ sinon . stub ( console , 'warn' ) ;
282
+ await regionalAuth . _updateFirebaseToken ( {
283
+ token : 'access-token' ,
284
+ expirationTime : now + 300_000
285
+ } ) ;
286
+ expect ( await regionalAuthInternal . getToken ( true ) ) . to . eql ( {
287
+ accessToken : 'access-token'
288
+ } ) ;
289
+ expect ( console . warn ) . to . have . been . calledWith (
290
+ sinon . match . string ,
291
+ sinon . match ( / R e f r e s h t o k e n i s n o t a v a l i d o p e r a t i o n f o r R e g i o n a l A u t h i n s t a n c e i n i t i a l i z e d \. / )
292
+ ) ;
293
+ } ) ;
277
294
} ) ;
278
295
} ) ;
0 commit comments