18
18
19
19
#import " OCMock.h"
20
20
21
- #import < GoogleUtilities/GULHeartbeatDateStorage.h>
22
21
#import " FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
23
22
#import " FirebaseInstallations/Source/Library/Private/FirebaseInstallationsInternal.h"
24
23
#import " FirebaseMessaging/Sources/FIRMessagingConstants.h"
@@ -78,6 +77,7 @@ @interface FIRMessagingTokenOperationsTest : XCTestCase
78
77
@property (strong , readonly , nonatomic ) FIRMessagingCheckinService *checkinService;
79
78
@property (strong , readonly , nonatomic ) id mockCheckinService;
80
79
@property (strong , readonly , nonatomic ) id mockInstallations;
80
+ @property (strong , readonly , nonatomic ) id mockHeartbeatInfo;
81
81
82
82
@property (strong , readonly , nonatomic ) NSString *instanceID;
83
83
@@ -107,10 +107,9 @@ - (void)setUp {
107
107
// Stub `FIRInstallations` to avoid using a real object.
108
108
[self stubInstallations ];
109
109
110
- NSString *const kHeartbeatStorageFile = @" HEARTBEAT_INFO_STORAGE" ;
111
- GULHeartbeatDateStorage *dataStorage =
112
- [[GULHeartbeatDateStorage alloc ] initWithFileName: kHeartbeatStorageFile ];
113
- [[NSFileManager defaultManager ] removeItemAtURL: [dataStorage fileURL ] error: nil ];
110
+ // `FIRMessagingTokenFetchOperation` uses `FIRHeartbeatInfo` to retrieve a heartbeat code.
111
+ // Stub `FIRHeartbeatInfo` to avoid using a real object.
112
+ [self stubHeartbeatInfo ];
114
113
}
115
114
116
115
- (void )tearDown {
@@ -120,6 +119,7 @@ - (void)tearDown {
120
119
_checkinService = nil ;
121
120
_mockTokenStore = nil ;
122
121
[_mockInstallations stopMocking ];
122
+ [_mockHeartbeatInfo stopMocking ];
123
123
}
124
124
125
125
- (void )testThatTokenOperationsAuthHeaderStringMatchesCheckin {
@@ -390,7 +390,9 @@ - (void)testTokenFetchOperationFirebaseUserAgentAndHeartbeatHeader {
390
390
XCTAssertEqualObjects (userAgentValue, [FIRApp firebaseUserAgent ]);
391
391
NSString *heartBeatCode =
392
392
sentRequest.allHTTPHeaderFields [kFIRMessagingFirebaseHeartbeatKey ];
393
- XCTAssertEqualObjects (heartBeatCode, @" 3" );
393
+ // It is expected that both the SDK and global heartbeat are requested.
394
+ XCTAssertEqual (heartBeatCode.integerValue , FIRHeartbeatInfoCodeCombined,
395
+ @" Heartbeat storage info needed to be updated but was not." );
394
396
[completionExpectation fulfill ];
395
397
396
398
return YES ;
@@ -438,4 +440,10 @@ - (void)stubInstallations {
438
440
OCMStub ([_mockInstallations authTokenWithCompletion: authTokenWithCompletionArg]);
439
441
}
440
442
443
+ - (void )stubHeartbeatInfo {
444
+ _mockHeartbeatInfo = OCMClassMock ([FIRHeartbeatInfo class ]);
445
+ OCMStub ([_mockHeartbeatInfo heartbeatCodeForTag: @" fire-iid" ])
446
+ .andReturn (FIRHeartbeatInfoCodeCombined);
447
+ }
448
+
441
449
@end
0 commit comments