FIRMessagingLinkHandlingTest.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 XCTest;
  17. #import <OCMock/OCMock.h>
  18. #import "FIRMessaging.h"
  19. #import "FIRMessagingConfig.h"
  20. #import "FIRMessagingConstants.h"
  21. #import "FIRMessagingTestNotificationUtilities.h"
  22. @interface FIRMessaging ()
  23. - (instancetype)initWithConfig:(FIRMessagingConfig *)config;
  24. - (NSURL *)linkURLFromMessage:(NSDictionary *)message;
  25. @end
  26. @interface FIRMessagingLinkHandlingTest : XCTestCase
  27. @property(nonatomic, readonly, strong) FIRMessaging *messaging;
  28. @end
  29. @implementation FIRMessagingLinkHandlingTest
  30. - (void)setUp {
  31. [super setUp];
  32. FIRMessagingConfig *config = [FIRMessagingConfig defaultConfig];
  33. _messaging = [[FIRMessaging alloc] initWithConfig:config];
  34. }
  35. - (void)tearDown {
  36. _messaging = nil;
  37. [super tearDown];
  38. }
  39. #pragma mark - Link Handling Testing
  40. - (void)testNonExistentLinkInMessage {
  41. NSMutableDictionary *notification =
  42. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  43. NSURL *url = [self.messaging linkURLFromMessage:notification];
  44. XCTAssertNil(url);
  45. }
  46. - (void)testEmptyLinkInMessage {
  47. NSMutableDictionary *notification =
  48. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  49. notification[kFIRMessagingMessageLinkKey] = @"";
  50. NSURL *url = [self.messaging linkURLFromMessage:notification];
  51. XCTAssertNil(url);
  52. }
  53. - (void)testNonStringLinkInMessage {
  54. NSMutableDictionary *notification =
  55. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  56. notification[kFIRMessagingMessageLinkKey] = @(5);
  57. NSURL *url = [self.messaging linkURLFromMessage:notification];
  58. XCTAssertNil(url);
  59. }
  60. - (void)testInvalidURLStringLinkInMessage {
  61. NSMutableDictionary *notification =
  62. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  63. notification[kFIRMessagingMessageLinkKey] = @"This is not a valid url string";
  64. NSURL *url = [self.messaging linkURLFromMessage:notification];
  65. XCTAssertNil(url);
  66. }
  67. - (void)testValidURLStringLinkInMessage {
  68. NSMutableDictionary *notification =
  69. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  70. notification[kFIRMessagingMessageLinkKey] = @"https://www.google.com/";
  71. NSURL *url = [self.messaging linkURLFromMessage:notification];
  72. XCTAssertTrue([url.absoluteString isEqualToString:@"https://www.google.com/"]);
  73. }
  74. @end