17
17
#import < XCTest/XCTest.h>
18
18
19
19
#import < FirebaseInstanceID/FIRInstanceID.h>
20
+
20
21
#import < OCMock/OCMock.h>
22
+
21
23
#import " Firebase/InstanceID/FIRInstanceIDAuthService.h"
22
24
#import " Firebase/InstanceID/FIRInstanceIDCheckinPreferences+Internal.h"
23
25
#import " Firebase/InstanceID/FIRInstanceIDCheckinService.h"
31
33
#import " Firebase/InstanceID/NSError+FIRInstanceID.h"
32
34
33
35
#import < FirebaseCore/FIRAppInternal.h>
36
+ #import < FirebaseInstallations/FirebaseInstallations.h>
34
37
#import < GoogleUtilities/GULHeartbeatDateStorage.h>
35
38
36
39
static NSString *kDeviceID = @" fakeDeviceID" ;
@@ -45,6 +48,10 @@ @interface FIRInstanceIDTokenOperation (ExposedForTest)
45
48
- (void )performTokenOperation ;
46
49
@end
47
50
51
+ @interface FIRInstallationsAuthTokenResult (Tests)
52
+ - (instancetype )initWithToken : (NSString *)token expirationDate : (NSDate *)expirationDate ;
53
+ @end
54
+
48
55
@interface FIRInstanceIDTokenOperationsTest : XCTestCase
49
56
50
57
@property (strong , readonly , nonatomic ) FIRInstanceIDAuthService *authService;
@@ -53,6 +60,7 @@ @interface FIRInstanceIDTokenOperationsTest : XCTestCase
53
60
@property (strong , readonly , nonatomic ) id mockStore;
54
61
@property (strong , readonly , nonatomic ) FIRInstanceIDCheckinService *checkinService;
55
62
@property (strong , readonly , nonatomic ) id mockCheckinService;
63
+ @property (strong , readonly , nonatomic ) id mockInstallations;
56
64
57
65
@property (strong , readonly , nonatomic ) NSString *instanceID;
58
66
@@ -71,12 +79,26 @@ - (void)setUp {
71
79
store: _mockStore];
72
80
_instanceID = @" instanceID" ;
73
81
82
+ // `FIRInstanceIDTokenOperation` uses `FIRInstallations` under the hood to get FIS auth token.
83
+ // Stub `FIRInstallations` to avoid using a real object.
84
+ [self stubInstallations ];
85
+
74
86
NSString *const kHeartbeatStorageFile = @" HEARTBEAT_INFO_STORAGE" ;
75
87
GULHeartbeatDateStorage *dataStorage =
76
88
[[GULHeartbeatDateStorage alloc ] initWithFileName: kHeartbeatStorageFile ];
77
89
[[NSFileManager defaultManager ] removeItemAtURL: [dataStorage fileURL ] error: nil ];
78
90
}
79
91
92
+ - (void )tearDown {
93
+ [_mockInstallations stopMocking ];
94
+ _mockInstallations = nil ;
95
+ _authService = nil ;
96
+ [_mockCheckinService stopMocking ];
97
+ _mockCheckinService = nil ;
98
+ _checkinService = nil ;
99
+ _mockStore = nil ;
100
+ }
101
+
80
102
- (void )testThatTokenOperationsAuthHeaderStringMatchesCheckin {
81
103
int64_t tenHoursAgo = FIRInstanceIDCurrentTimestampInMilliseconds () - 10 * 60 * 60 * 1000 ;
82
104
FIRInstanceIDCheckinPreferences *checkin =
@@ -371,4 +393,14 @@ - (FIRInstanceIDCheckinPreferences *)setCheckinPreferencesWithLastCheckinTime:(i
371
393
return checkinPreferences;
372
394
}
373
395
396
+ - (void )stubInstallations {
397
+ _mockInstallations = OCMClassMock ([FIRInstallations class ]);
398
+ OCMStub ([_mockInstallations installations ]).andReturn (_mockInstallations);
399
+ FIRInstallationsAuthTokenResult *authToken =
400
+ [[FIRInstallationsAuthTokenResult alloc ] initWithToken: @" fis-auth-token"
401
+ expirationDate: [NSDate distantFuture ]];
402
+ id authTokenWithCompletionArg = [OCMArg invokeBlockWithArgs: authToken, [NSNull null ], nil ];
403
+ OCMStub ([_mockInstallations authTokenWithCompletion: authTokenWithCompletionArg]);
404
+ }
405
+
374
406
@end
0 commit comments