@@ -38,7 +38,6 @@ @interface FIRMessaging ()
38
38
39
39
@property (nonatomic , readwrite , strong ) NSString *defaultFcmToken;
40
40
@property (nonatomic , readwrite , strong ) FIRInstanceID *instanceID;
41
- @property (nonatomic , readwrite , strong ) FIRMessagingRmqManager *rmq2Manager;
42
41
43
42
- (BOOL )handleContextManagerMessage : (NSDictionary *)message ;
44
43
- (void )handleIncomingLinkIfNeededFromMessage : (NSDictionary *)message ;
@@ -52,12 +51,10 @@ - (void)handleIncomingLinkIfNeededFromMessage:(NSDictionary *)message;
52
51
*/
53
52
@interface FIRMessagingHandlingTest : XCTestCase
54
53
55
- @property (nonatomic , readonly , strong ) FIRMessaging *messaging;
56
54
@property (nonatomic , strong ) FIRMessagingAnalytics *messageAnalytics;
57
- @property (nonatomic , strong ) id mockMessaging;
58
- @property (nonatomic , strong ) id mockInstanceID;
59
55
@property (nonatomic , strong ) id mockFirebaseApp;
60
56
@property (nonatomic , strong ) id mockMessagingAnalytics;
57
+ @property (nonatomic , strong ) FIRMessagingTestUtilities *testUtil;
61
58
62
59
@end
63
60
@@ -69,30 +66,23 @@ - (void)setUp {
69
66
// Create the messaging instance with all the necessary dependencies.
70
67
NSUserDefaults *defaults =
71
68
EF2F
[[NSUserDefaults alloc ] initWithSuiteName: kFIRMessagingDefaultsTestDomain ];
72
- _messaging = [FIRMessagingTestUtilities messagingForTestsWithUserDefaults : defaults];
69
+ _testUtil = [[ FIRMessagingTestUtilities alloc ] initWithUserDefaults : defaults withRMQManager: YES ];
73
70
_mockFirebaseApp = OCMClassMock ([FIRApp class ]);
74
71
OCMStub ([_mockFirebaseApp defaultApp ]).andReturn (_mockFirebaseApp);
75
- _mockInstanceID = OCMPartialMock (self.messaging .instanceID );
76
72
[[NSUserDefaults standardUserDefaults ]
77
73
removePersistentDomainForName: [NSBundle mainBundle ].bundleIdentifier];
78
- _mockMessaging = OCMPartialMock (_messaging);
79
74
_mockMessagingAnalytics = OCMClassMock ([FIRMessagingAnalytics class ]);
80
75
}
81
76
82
77
- (void )tearDown {
83
- [self .messaging.messagingUserDefaults removePersistentDomainForName: kFIRMessagingDefaultsTestDomain ];
84
- self.messaging .shouldEstablishDirectChannel = NO ;
85
- self.messaging .defaultFcmToken = nil ;
78
+ [_testUtil cleanupAfterTest ];
86
79
[_mockMessagingAnalytics stopMocking ];
87
- [_mockMessaging stopMocking ];
88
- [_mockInstanceID stopMocking ];
89
80
[_mockFirebaseApp stopMocking ];
90
- _messaging = nil ;
91
81
[super tearDown ];
92
82
}
93
83
94
84
-(void )testEmptyNotification {
95
- XCTAssertEqualObjects (@(FIRMessagingMessageStatusUnknown), @([_mockMessaging appDidReceiveMessage: @{}].status ));
85
+ XCTAssertEqualObjects (@(FIRMessagingMessageStatusUnknown), @([_testUtil.mockMessaging appDidReceiveMessage: @{}].status ));
96
86
}
97
87
98
88
-(void )testAPNSDisplayNotification {
@@ -110,22 +100,21 @@ -(void)testAPNSDisplayNotification {
110
100
@" google.c.a.ts" : @1566515009 ,
111
101
@" google.c.a.udt" : @0
112
102
};
113
- OCMExpect ([_mockMessaging handleContextManagerMessage: notificationPayload]);
114
- OCMExpect ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
103
+ OCMExpect ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
104
+ OCMExpect ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
115
105
OCMExpect ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
116
106
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
117
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
118
- OCMVerifyAll (_mockMessaging );
107
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
108
+ OCMVerifyAll (_testUtil. mockMessaging );
119
109
120
- OCMReject ([_mockMessaging handleContextManagerMessage: notificationPayload]);
121
- OCMReject ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
110
+ OCMReject ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
111
+ OCMReject ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
122
112
OCMReject ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
123
113
124
114
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
125
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
126
- OCMVerifyAll (_mockMessaging);
127
- // Clear database
128
- [_messaging.rmq2Manager deleteSyncMessageWithRmqID: @" 1566515013484879" ];
115
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
116
+ OCMVerifyAll (_testUtil.mockMessaging );
117
+
129
118
}
130
119
131
120
-(void )testAPNSContentAvailableNotification {
@@ -137,25 +126,25 @@ -(void)testAPNSContentAvailableNotification {
137
126
@" image" : @" bunny.png" ,
138
127
@" google.c.a.e" : @1
139
128
};
140
- OCMExpect ([_mockMessaging handleContextManagerMessage: notificationPayload]);
141
- OCMExpect ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
129
+ OCMExpect ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
130
+ OCMExpect ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
142
131
OCMExpect ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
143
132
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
144
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
145
- OCMVerifyAll (_mockMessaging );
133
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
134
+ OCMVerifyAll (_testUtil. mockMessaging );
146
135
147
- OCMReject ([_mockMessaging handleContextManagerMessage: notificationPayload]);
148
- OCMReject ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
136
+ OCMReject ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
137
+ OCMReject ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
149
138
OCMReject ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
150
139
151
140
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
152
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
153
- OCMVerifyAll (_mockMessaging);
154
- [_messaging.rmq2Manager deleteSyncMessageWithRmqID: @" 1566513591299872" ];
141
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
142
+ OCMVerifyAll (_testUtil.mockMessaging );
155
143
156
144
}
157
145
158
146
-(void )testAPNSContentAvailableContextualNotification {
147
+
159
148
NSDictionary *notificationPayload = @{
160
149
@" aps" : @{
161
150
@" content-available" : @1
@@ -173,21 +162,20 @@ -(void)testAPNSContentAvailableContextualNotification {
173
162
@" google.c.cm.lt_end" : @" 2019-09-20 13:12:00" ,
174
163
@" google.c.cm.lt_start" : @" 2019-08-23 13:12:00" ,
175
164
};
176
- OCMExpect ([_mockMessaging handleContextManagerMessage: notificationPayload]);
177
- OCMExpect ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
165
+ OCMExpect ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
166
+ OCMExpect ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
178
167
OCMExpect ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
179
168
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
180
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
181
- OCMVerifyAll (_mockMessaging );
169
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
170
+ OCMVerifyAll (_testUtil. mockMessaging );
182
171
183
- OCMReject ([_mockMessaging handleContextManagerMessage: notificationPayload]);
184
- OCMReject ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
172
+ OCMReject ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
173
+ OCMReject ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
185
174
OCMReject ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
186
175
187
176
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
188
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
189
- OCMVerifyAll (_mockMessaging);
190
- [_messaging.rmq2Manager deleteSyncMessageWithRmqID: @" 1566515531287827" ];
177
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
178
+ OCMVerifyAll (_testUtil.mockMessaging );
191
179
192
180
}
193
181
@@ -203,42 +191,41 @@ -(void)testContextualLocalNotification {
203
191
@" google.c.a.ts" : @1566565920 ,
204
192
@" google.c.a.udt" : @1 ,
205
193
};
206
- OCMExpect ([_mockMessaging handleContextManagerMessage: notificationPayload]);
207
- OCMExpect ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
194
+ OCMExpect ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
195
+ OCMExpect ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
208
196
OCMExpect ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
209
197
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
210
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
211
- OCMVerifyAll (_mockMessaging );
198
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
199
+ OCMVerifyAll (_testUtil. mockMessaging );
212
200
213
- OCMReject ([_mockMessaging handleContextManagerMessage: notificationPayload]);
214
- OCMReject ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
201
+ OCMReject ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
202
+ OCMReject ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
215
203
OCMReject ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
216
204
217
205
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
218
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
219
- OCMVerifyAll (_mockMessaging);
220
- [_messaging.rmq2Manager deleteSyncMessageWithRmqID: @" 1566515531281975" ];
206
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
207
+ OCMVerifyAll (_testUtil.mockMessaging );
221
208
}
222
209
223
210
-(void )testMCSNotification {
224
211
NSDictionary *notificationPayload = @{
225
212
@" from" : @" 35006771263" ,
226
<
A839
/td>213
@" image" : @" bunny.png"
227
214
};
228
- OCMExpect ([_mockMessaging handleContextManagerMessage: notificationPayload]);
229
- OCMExpect ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
215
+ OCMExpect ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
216
+ OCMExpect ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
230
217
OCMExpect ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
231
218
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
232
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
233
- OCMVerifyAll (_mockMessaging );
219
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
220
+ OCMVerifyAll (_testUtil. mockMessaging );
234
221
235
- OCMExpect ([_mockMessaging handleContextManagerMessage: notificationPayload]);
236
- OCMExpect ([_mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
222
+ OCMExpect ([_testUtil.mockMessaging handleContextManagerMessage: notificationPayload]);
223
+ OCMExpect ([_testUtil.mockMessaging handleIncomingLinkIfNeededFromMessage: notificationPayload]);
237
224
OCMExpect ([_mockMessagingAnalytics logMessage: notificationPayload toAnalytics: [OCMArg any ]]);
238
225
239
226
XCTAssertEqualObjects (@(FIRMessagingMessageStatusNew),
240
- @([_messaging appDidReceiveMessage: notificationPayload].status ));
241
- OCMVerifyAll (_mockMessaging );
227
+ @([_testUtil.messaging appDidReceiveMessage: notificationPayload].status ));
228
+ OCMVerifyAll (_testUtil. mockMessaging );
242
229
}
243
230
244
231
@end
0 commit comments