RCNConfigAnalyticsTest.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2019 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/XCTest.h>
  17. #import <OCMock/OCMock.h>
  18. #import "RCNConfigAnalytics.h"
  19. @interface RCNConfigAnalyticsTest : XCTestCase {
  20. id _mockAnalytics;
  21. RCNConfigAnalytics *_configAnalytics;
  22. }
  23. @end
  24. @implementation RCNConfigAnalyticsTest
  25. - (void)setUp {
  26. [super setUp];
  27. _mockAnalytics = OCMClassMock([FIRAnalytics class]);
  28. _configAnalytics = [[RCNConfigAnalytics alloc] init];
  29. }
  30. - (void)testFetchUserProperty {
  31. XCTestExpectation *fetchExpectation =
  32. [self expectationWithDescription:@"Test fetch user property."];
  33. // Mocks the user property fetching response.
  34. OCMStub([_mockAnalytics userPropertiesIncludingInternal:NO
  35. queue:[OCMArg any]
  36. callback:([OCMArg invokeBlockWithArgs:@{
  37. @"user_property_event_name" : @"level up",
  38. @"user_property_gold_amount" : @"1800",
  39. @"user_property_level" : @20
  40. },
  41. nil])]);
  42. [_configAnalytics fetchUserPropertiesWithCompletionHandler:^(NSDictionary *userProperties) {
  43. XCTAssertNotNil(userProperties);
  44. XCTAssertEqual(userProperties.count, 3);
  45. XCTAssertEqualObjects(@"level up", userProperties[@"user_property_event_name"]);
  46. XCTAssertEqualObjects(@20, userProperties[@"user_property_level"]);
  47. XCTAssertEqualObjects(@"1800", userProperties[@"user_property_gold_amount"]);
  48. [fetchExpectation fulfill];
  49. }];
  50. [self waitForExpectationsWithTimeout:1.0
  51. handler:^(NSError *error) {
  52. XCTAssertNil(error);
  53. }];
  54. }
  55. - (void)testFetchUserPropertyWithEmptyResponse {
  56. XCTestExpectation *fetchExpectation =
  57. [self expectationWithDescription:@"Test fetch empty user property."];
  58. // Mocks the user property fetching response.
  59. OCMStub([_mockAnalytics userPropertiesIncludingInternal:NO
  60. queue:[OCMArg any]
  61. callback:([OCMArg invokeBlockWithArgs:@{}, nil])]);
  62. // Tests passing nil callback won't crash.
  63. [_configAnalytics fetchUserPropertiesWithCompletionHandler:nil];
  64. [_configAnalytics fetchUserPropertiesWithCompletionHandler:^(NSDictionary *userProperties) {
  65. XCTAssertNotNil(userProperties);
  66. XCTAssertEqual(userProperties.count, 0);
  67. [fetchExpectation fulfill];
  68. }];
  69. [self waitForExpectationsWithTimeout:1.0
  70. handler:^(NSError *error) {
  71. XCTAssertNil(error);
  72. }];
  73. }
  74. @end