@@ -23,7 +23,7 @@ import sinonChai from 'sinon-chai';
2323import { FirebaseApp } from '@firebase/app' ;
2424import { FirebaseError } from '@firebase/util' ;
2525
26- import { testAuth , testUser } from '../../../test/helpers/mock_auth' ;
26+ import { FAKE_HEARTBEAT_CONTROLLER , FAKE_HEARTBEAT_CONTROLLER_PROVIDER , testAuth , testUser } from '../../../test/helpers/mock_auth' ;
2727import { AuthInternal } from '../../model/auth' ;
2828import { UserInternal } from '../../model/user' ;
2929import { PersistenceInternal } from '../persistence' ;
@@ -53,7 +53,7 @@ describe('core/auth/auth_impl', () => {
5353
5454 beforeEach ( async ( ) => {
5555 persistenceStub = sinon . stub ( _getInstance ( inMemoryPersistence ) ) ;
56- const authImpl = new AuthImpl ( FAKE_APP , {
56+ const authImpl = new AuthImpl ( FAKE_APP , FAKE_HEARTBEAT_CONTROLLER_PROVIDER , {
5757 apiKey : FAKE_APP . options . apiKey ! ,
5858 apiHost : DefaultConfig . API_HOST ,
5959 apiScheme : DefaultConfig . API_SCHEME ,
@@ -431,7 +431,7 @@ describe('core/auth/auth_impl', () => {
431431 } ) ;
432432
433433 it ( 'prevents initialization from completing' , async ( ) => {
434- const authImpl = new AuthImpl ( FAKE_APP , {
434+ const authImpl = new AuthImpl ( FAKE_APP , FAKE_HEARTBEAT_CONTROLLER_PROVIDER , {
435435 apiKey : FAKE_APP . options . apiKey ! ,
436436 apiHost : DefaultConfig . API_HOST ,
437437 apiScheme : DefaultConfig . API_SCHEME ,
@@ -474,6 +474,29 @@ describe('core/auth/auth_impl', () => {
474474 'X-Client-Version' : 'v' ,
475475 'X-Firebase-gmpid' : 'app-id' ,
476476 } ) ;
477+ delete auth . app . options . appId ;
478+ } ) ;
479+
480+ it ( 'adds the heartbeat if available' , async ( ) => {
481+ sinon . stub ( FAKE_HEARTBEAT_CONTROLLER , 'getHeartbeatsHeader' ) . returns ( Promise . resolve ( 'heartbeat' ) ) ;
482+ expect ( await auth . _getAdditionalHeaders ( ) ) . to . eql ( {
483+ 'X-Client-Version' : 'v' ,
484+ 'X-Firebase-Client' : 'heartbeat' ,
485+ } ) ;
486+ } ) ;
487+
488+ it ( 'does not add heartbeat if none returned' , async ( ) => {
489+ sinon . stub ( FAKE_HEARTBEAT_CONTROLLER , 'getHeartbeatsHeader' ) . returns ( Promise . resolve ( '' ) ) ;
490+ expect ( await auth . _getAdditionalHeaders ( ) ) . to . eql ( {
491+ 'X-Client-Version' : 'v' ,
492+ } ) ;
493+ } ) ;
494+
495+ it ( 'does not add heartbeat if controller unavailable' , async ( ) => {
496+ sinon . stub ( FAKE_HEARTBEAT_CONTROLLER_PROVIDER , 'getImmediate' ) . returns ( undefined as any ) ;
497+ expect ( await auth . _getAdditionalHeaders ( ) ) . to . eql ( {
498+ 'X-Client-Version' : 'v' ,
499+ } ) ;
477500 } ) ;
478501 } ) ;
479502} ) ;
0 commit comments