@@ -20,7 +20,11 @@ import { expect, use } from 'chai';
2020import * as sinon from 'sinon' ;
2121import chaiAsPromised from 'chai-as-promised' ;
2222
23- import { regionalTestAuth , testAuth , testUser } from '../../../test/helpers/mock_auth' ;
23+ import {
24+ regionalTestAuth ,
25+ testAuth ,
26+ testUser
27+ } from '../../../test/helpers/mock_auth' ;
2428import { AuthInternal } from '../../model/auth' ;
2529import { UserInternal } from '../../model/user' ;
2630import { AuthInterop } from './firebase_internal' ;
@@ -38,8 +42,8 @@ describe('core/auth/firebase_internal', () => {
3842 afterEach ( ( ) => {
3943 sinon . restore ( ) ;
4044 delete ( auth as unknown as Record < string , unknown > ) [
41- '_initializationPromise'
42- ] ;
45+ '_initializationPromise'
46+ ] ;
4347 } ) ;
4448
4549 context ( 'getUid' , ( ) => {
@@ -222,9 +226,12 @@ describe('core/auth/firebase_internal', () => {
222226describe ( 'core/auth/firebase_internal - Regional Firebase Auth' , ( ) => {
223227 let regionalAuth : AuthInternal ;
224228 let regionalAuthInternal : AuthInterop ;
229+ let now : number ;
225230 beforeEach ( async ( ) => {
226231 regionalAuth = await regionalTestAuth ( ) ;
227232 regionalAuthInternal = new AuthInterop ( regionalAuth ) ;
233+ now = Date . now ( ) ;
234+ sinon . stub ( Date , 'now' ) . returns ( now ) ;
228235 } ) ;
229236
230237 afterEach ( ( ) => {
@@ -235,5 +242,37 @@ describe('core/auth/firebase_internal - Regional Firebase Auth', () => {
235242 it ( 'returns null if firebase token is undefined' , async ( ) => {
236243 expect ( await regionalAuthInternal . getFirebaseToken ( ) ) . to . be . null ;
237244 } ) ;
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+ } ) ;
238277 } ) ;
239278} ) ;
0 commit comments