@@ -20,7 +20,11 @@ import { expect, use } from 'chai';
20
20
import * as sinon from 'sinon' ;
21
21
import chaiAsPromised from 'chai-as-promised' ;
22
22
23
- import { regionalTestAuth , testAuth , testUser } from '../../../test/helpers/mock_auth' ;
23
+ import {
24
+ regionalTestAuth ,
25
+ testAuth ,
26
+ testUser
27
+ } from '../../../test/helpers/mock_auth' ;
24
28
import { AuthInternal } from '../../model/auth' ;
25
29
import { UserInternal } from '../../model/user' ;
26
30
import { AuthInterop } from './firebase_internal' ;
@@ -38,8 +42,8 @@ describe('core/auth/firebase_internal', () => {
38
42
afterEach ( ( ) => {
39
43
sinon . restore ( ) ;
40
44
delete ( auth as unknown as Record < string , unknown > ) [
41
- '_initializationPromise'
42
- ] ;
45
+ '_initializationPromise'
46
+ ] ;
43
47
} ) ;
44
48
45
49
context ( 'getUid' , ( ) => {
@@ -222,9 +226,12 @@ describe('core/auth/firebase_internal', () => {
222
226
describe ( 'core/auth/firebase_internal - Regional Firebase Auth' , ( ) => {
223
227
let regionalAuth : AuthInternal ;
224
228
let regionalAuthInternal : AuthInterop ;
229
+ let now : number ;
225
230
beforeEach ( async ( ) => {
226
231
regionalAuth = await regionalTestAuth ( ) ;
227
232
regionalAuthInternal = new AuthInterop ( regionalAuth ) ;
233
+ now = Date . now ( ) ;
234
+ sinon . stub ( Date , 'now' ) . returns ( now ) ;
228
235
} ) ;
229
236
230
237
afterEach ( ( ) => {
@@ -235,5 +242,37 @@ describe('core/auth/firebase_internal - Regional Firebase Auth', () => {
235
242
it ( 'returns null if firebase token is undefined' , async ( ) => {
236
243
expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . be . null ;
237
244
} ) ;
245
+
246
+ it ( 'returns the id token correctly' , async ( ) => {
247
+ await regionalAuth . _updateFirebaseToken ( {
248
+ token : 'access-token' ,
249
+ expirationTime : now + 300_000
250
+ } ) ;
251
+ expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . eql ( {
252
+ accessToken : 'access-token'
253
+ } ) ;
254
+ } ) ;
255
+
256
+ it ( 'logs out the the id token expires in next 30 seconds' , async ( ) => {
257
+ expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . be . null ;
258
+ } ) ;
259
+
260
+ it ( 'logs out if token has expired' , async ( ) => {
261
+ await regionalAuth . _updateFirebaseToken ( {
262
+ token : 'access-token' ,
263
+ expirationTime : now - 5_000
264
+ } ) ;
265
+ expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . null ;
266
+ expect ( regionalAuth . firebaseToken ) . to . null ;
267
+ } ) ;
268
+
269
+ it ( 'logs out if token is expiring in next 5 seconds' , async ( ) => {
270
+ await regionalAuth . _updateFirebaseToken ( {
271
+ token : 'access-token' ,
272
+ expirationTime : now + 5_000
273
+ } ) ;
274
+ expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . null ;
275
+ expect ( regionalAuth . firebaseToken ) . to . null ;
276
+ } ) ;
238
277
} ) ;
239
278
} ) ;
0 commit comments