FIRMessagingLinkHandlingTest.m 2.8 KB

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