FIRMessagingLinkHandlingTest.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <OCMock/OCMock.h>
  17. #import <XCTest/XCTest.h>
  18. #import <FirebaseMessaging/FIRMessaging.h>
  19. #import "Example/Messaging/Tests/FIRMessagingTestNotificationUtilities.h"
  20. #import "Example/Messaging/Tests/FIRMessagingTestUtilities.h"
  21. #import "Firebase/Messaging/FIRMessagingConstants.h"
  22. NSString *const kFIRMessagingTestsLinkHandlingSuiteName = @"com.messaging.test_linkhandling";
  23. @interface FIRMessaging ()
  24. - (NSURL *)linkURLFromMessage:(NSDictionary *)message;
  25. @end
  26. @interface FIRMessagingLinkHandlingTest : XCTestCase
  27. @property(nonatomic, readonly, strong) FIRMessaging *messaging;
  28. @property(nonatomic, strong) FIRMessagingTestUtilities * testUtil;
  29. @end
  30. @implementation FIRMessagingLinkHandlingTest
  31. - (void)setUp {
  32. [super setUp];
  33. NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingTestsLinkHandlingSuiteName];
  34. _testUtil = [[FIRMessagingTestUtilities alloc] initWithUserDefaults:defaults withRMQManager:NO];
  35. _messaging = _testUtil.messaging;
  36. }
  37. - (void)tearDown {
  38. [_testUtil cleanupAfterTest];
  39. _messaging = nil;
  40. [super tearDown];
  41. }
  42. #pragma mark - Link Handling Testing
  43. - (void)testNonExistentLinkInMessage {
  44. NSMutableDictionary *notification =
  45. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  46. NSURL *url = [_messaging linkURLFromMessage:notification];
  47. XCTAssertNil(url);
  48. }
  49. - (void)testEmptyLinkInMessage {
  50. NSMutableDictionary *notification =
  51. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  52. notification[kFIRMessagingMessageLinkKey] = @"";
  53. NSURL *url = [_messaging linkURLFromMessage:notification];
  54. XCTAssertNil(url);
  55. }
  56. - (void)testNonStringLinkInMessage {
  57. NSMutableDictionary *notification =
  58. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  59. notification[kFIRMessagingMessageLinkKey] = @(5);
  60. NSURL *url = [_messaging linkURLFromMessage:notification];
  61. XCTAssertNil(url);
  62. }
  63. - (void)testInvalidURLStringLinkInMessage {
  64. NSMutableDictionary *notification =
  65. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  66. notification[kFIRMessagingMessageLinkKey] = @"This is not a valid url string";
  67. NSURL *url = [_messaging linkURLFromMessage:notification];
  68. XCTAssertNil(url);
  69. }
  70. - (void)testValidURLStringLinkInMessage {
  71. NSMutableDictionary *notification =
  72. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  73. notification[kFIRMessagingMessageLinkKey] = @"https://www.google.com/";
  74. NSURL *url = [_messaging linkURLFromMessage:notification];
  75. XCTAssertTrue([url.absoluteString isEqualToString:@"https://www.google.com/"]);
  76. }
  77. @end