|
24 | 24 | #import "FirebaseMessaging/Sources/FIRMessagingContextManagerService.h"
|
25 | 25 |
|
26 | 26 | static NSString *const kBody = @"Save 20% off!";
|
| 27 | +static NSString *const kTitle = @"Sparky WFH"; |
| 28 | +static NSString *const kSoundName = @"default"; |
| 29 | +static NSString *const kAction = @"open"; |
27 | 30 | static NSString *const kUserInfoKey1 = @"level";
|
28 | 31 | static NSString *const kUserInfoKey2 = @"isPayUser";
|
29 | 32 | static NSString *const kUserInfoValue1 = @"5";
|
30 | 33 | static NSString *const kUserInfoValue2 = @"Yes";
|
31 | 34 | static NSString *const kMessageIdentifierKey = @"gcm.message_id";
|
32 | 35 | static NSString *const kMessageIdentifierValue = @"1584748495200141";
|
33 | 36 |
|
| 37 | +@interface FIRMessagingContextManagerService (ExposedForTest) |
| 38 | ++ (void)scheduleiOS10LocalNotificationForMessage:(NSDictionary *)message atDate:(NSDate *)date; |
| 39 | ++ (UNMutableNotificationContent *)contentFromContextualMessage:(NSDictionary *)message; |
| 40 | +@end |
| 41 | + |
34 | 42 | API_AVAILABLE(macos(10.14))
|
35 | 43 | @interface FIRMessagingContextManagerServiceTest : XCTestCase
|
36 | 44 |
|
@@ -269,4 +277,85 @@ - (void)mockSchedulingLocalNotifications {
|
269 | 277 | #endif
|
270 | 278 | }
|
271 | 279 |
|
| 280 | +- (void)testScheduleiOS10LocalNotification { |
| 281 | + if (@available(macOS 10.14, iOS 10.0, watchOS 3.0, tvOS 10.0, *)) { |
| 282 | + id mockContextManagerService = OCMClassMock([FIRMessagingContextManagerService class]); |
| 283 | + NSDictionary *message = @{}; |
| 284 | + |
| 285 | + [FIRMessagingContextManagerService scheduleiOS10LocalNotificationForMessage:message |
| 286 | + atDate:[NSDate date]]; |
| 287 | + OCMVerify([mockContextManagerService contentFromContextualMessage:message]); |
| 288 | + [mockContextManagerService stopMocking]; |
| 289 | + } |
| 290 | +} |
| 291 | + |
| 292 | +- (void)testContentFromConetxtualMessage { |
| 293 | + if (@available(macOS 10.14, iOS 10.0, watchOS 3.0, tvOS 10.0, *)) { |
| 294 | + NSDictionary *message = @{ |
| 295 | + @"aps" : @{@"content-available" : @1}, |
| 296 | + @"gcm.message_id" : @1623702615599207, |
| 297 | + @"gcm.n.e" : @1, |
| 298 | + @"gcm.notification.badge" : @1, |
| 299 | + @"gcm.notification.body" : kBody, |
| 300 | + @"gcm.notification.image" : |
| 301 | + @"https://firebasestorage.googleapis.com/v0/b/fir-ios-app-extensions.appspot.com/o/" |
| 302 | + @"sparkyWFH.png?alt=media&token=f4dc1533-4d80-4ed6-9870-8df528593157", |
| 303 | + @"gcm.notification.mutable_content" : @1, |
| 304 | + @"gcm.notification.sound" : kSoundName, |
| 305 | + @"gcm.notification.sound2" : kSoundName, |
| 306 | + @"gcm.notification.title" : kTitle, |
| 307 | + // This field is not popped out from console |
| 308 | + // Manual add here to test unit test |
| 309 | + @"gcm.notification.click_action" : kAction, |
| 310 | + @"gcms" : @"gcm.gmsproc.cm", |
| 311 | + @"google.c.a.c_id" : @2159728303499680621, |
| 312 | + @"google.c.a.c_l" : @"test local send with sound", |
| 313 | + @"google.c.a.e" : @1, |
| 314 | + @"google.c.a.ts" : @1623753000, |
| 315 | + @"google.c.a.udt" : @1, |
| 316 | + @"google.c.cm.lt_end" : @"2021-07-13 10:30:00", |
| 317 | + @"google.c.cm.lt_start" : @"2021-06-15 10:30:00", |
| 318 | + @"google.c.sender.id" : @449451107265, |
| 319 | + }; |
| 320 | + UNMutableNotificationContent *content = |
| 321 | + [FIRMessagingContextManagerService contentFromContextualMessage:message]; |
| 322 | + XCTAssertEqualObjects(content.badge, @1); |
| 323 | + |
| 324 | +#if TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_WATCH |
| 325 | + XCTAssertEqualObjects(content.body, kBody); |
| 326 | + XCTAssertEqualObjects(content.title, kTitle); |
| 327 | +#if !TARGET_OS_WATCH |
| 328 | + XCTAssertEqualObjects(content.sound, [UNNotificationSound soundNamed:kSoundName]); |
| 329 | +#else // !TARGET_OS_WATCH |
| 330 | + XCTAssertEqualObjects(content.sound, [UNNotificationSound defaultSound]); |
| 331 | +#endif // !TARGET_OS_WATCH |
| 332 | + XCTAssertEqualObjects(content.categoryIdentifier, kAction); |
| 333 | + NSDictionary *userInfo = @{ |
| 334 | + @"gcm.message_id" : @1623702615599207, |
| 335 | + @"gcm.n.e" : @1, |
| 336 | + @"gcm.notification.badge" : @1, |
| 337 | + @"gcm.notification.body" : kBody, |
| 338 | + @"gcm.notification.image" : |
| 339 | + @"https://firebasestorage.googleapis.com/v0/b/fir-ios-app-extensions.appspot.com/o/" |
| 340 | + @"sparkyWFH.png?alt=media&token=f4dc1533-4d80-4ed6-9870-8df528593157", |
| 341 | + @"gcm.notification.mutable_content" : @1, |
| 342 | + @"gcm.notification.sound" : kSoundName, |
| 343 | + @"gcm.notification.sound2" : kSoundName, |
| 344 | + @"gcm.notification.title" : kTitle, |
| 345 | + // This field is not popped out from console |
| 346 | + // Manual add here to test unit test |
| 347 | + @"gcm.notification.click_action" : kAction, |
| 348 | + @"gcms" : @"gcm.gmsproc.cm", |
| 349 | + @"google.c.a.c_id" : @2159728303499680621, |
| 350 | + @"google.c.a.c_l" : @"test local send with sound", |
| 351 | + @"google.c.a.e" : @1, |
| 352 | + @"google.c.a.ts" : @1623753000, |
| 353 | + @"google.c.a.udt" : @1, |
| 354 | + @"google.c.sender.id" : @449451107265 |
| 355 | + }; |
| 356 | + XCTAssertEqualObjects(content.userInfo, userInfo); |
| 357 | +#endif // TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_WATCH |
| 358 | + } |
| 359 | +} |
| 360 | + |
272 | 361 | @end
|
0 commit comments