@@ -23,7 +23,7 @@ import sinonChai from 'sinon-chai';
23
23
import { FirebaseApp } from '@firebase/app' ;
24
24
import { FirebaseError } from '@firebase/util' ;
25
25
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' ;
27
27
import { AuthInternal } from '../../model/auth' ;
28
28
import { UserInternal } from '../../model/user' ;
29
29
import { PersistenceInternal } from '../persistence' ;
@@ -53,7 +53,7 @@ describe('core/auth/auth_impl', () => {
53
53
54
54
beforeEach ( async ( ) => {
55
55
persistenceStub = sinon . stub ( _getInstance ( inMemoryPersistence ) ) ;
56
- const authImpl = new AuthImpl ( FAKE_APP , {
56
+ const authImpl = new AuthImpl ( FAKE_APP , FAKE_HEARTBEAT_CONTROLLER_PROVIDER , {
57
57
apiKey : FAKE_APP . options . apiKey ! ,
58
58
apiHost : DefaultConfig . API_HOST ,
59
59
apiScheme : DefaultConfig . API_SCHEME ,
@@ -431,7 +431,7 @@ describe('core/auth/auth_impl', () => {
431
431
} ) ;
432
432
433
433
it ( 'prevents initialization from completing' , async ( ) => {
434
- const authImpl = new AuthImpl ( FAKE_APP , {
434
+ const authImpl = new AuthImpl ( FAKE_APP , FAKE_HEARTBEAT_CONTROLLER_PROVIDER , {
435
435
apiKey : FAKE_APP . options . apiKey ! ,
436
436
apiHost : DefaultConfig . API_HOST ,
437
437
apiScheme : DefaultConfig . API_SCHEME ,
@@ -474,6 +474,29 @@ describe('core/auth/auth_impl', () => {
474
474
'X-Client-Version' : 'v' ,
475
475
'X-Firebase-gmpid' : 'app-id' ,
476
476
} ) ;
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
+ } ) ;
477
500
} ) ;
478
501
} ) ;
479
502
} ) ;
0 commit comments