2019-08-21 14:26:41 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2019 Google
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import <XCTest/XCTest.h>
|
2020-07-10 14:25:05 -07:00
|
|
|
#import "OCMock.h"
|
2019-08-21 14:26:41 -07:00
|
|
|
|
2020-07-10 14:25:05 -07:00
|
|
|
//#import "RCNConfigAnalytics.h"
|
2019-08-21 14:26:41 -07:00
|
|
|
|
|
|
|
|
@interface RCNConfigAnalyticsTest : XCTestCase {
|
|
|
|
|
id _mockAnalytics;
|
|
|
|
|
RCNConfigAnalytics *_configAnalytics;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation RCNConfigAnalyticsTest
|
|
|
|
|
|
|
|
|
|
- (void)setUp {
|
|
|
|
|
[super setUp];
|
|
|
|
|
_mockAnalytics = OCMClassMock([FIRAnalytics class]);
|
|
|
|
|
_configAnalytics = [[RCNConfigAnalytics alloc] init];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testFetchUserProperty {
|
|
|
|
|
XCTestExpectation *fetchExpectation =
|
|
|
|
|
[self expectationWithDescription:@"Test fetch user property."];
|
|
|
|
|
|
|
|
|
|
// Mocks the user property fetching response.
|
|
|
|
|
OCMStub([_mockAnalytics userPropertiesIncludingInternal:NO
|
|
|
|
|
queue:[OCMArg any]
|
|
|
|
|
callback:([OCMArg invokeBlockWithArgs:@{
|
|
|
|
|
@"user_property_event_name" : @"level up",
|
|
|
|
|
@"user_property_gold_amount" : @"1800",
|
|
|
|
|
@"user_property_level" : @20
|
|
|
|
|
},
|
|
|
|
|
nil])]);
|
|
|
|
|
|
|
|
|
|
[_configAnalytics fetchUserPropertiesWithCompletionHandler:^(NSDictionary *userProperties) {
|
|
|
|
|
XCTAssertNotNil(userProperties);
|
|
|
|
|
XCTAssertEqual(userProperties.count, 3);
|
|
|
|
|
XCTAssertEqualObjects(@"level up", userProperties[@"user_property_event_name"]);
|
|
|
|
|
XCTAssertEqualObjects(@20, userProperties[@"user_property_level"]);
|
|
|
|
|
XCTAssertEqualObjects(@"1800", userProperties[@"user_property_gold_amount"]);
|
|
|
|
|
|
|
|
|
|
[fetchExpectation fulfill];
|
|
|
|
|
}];
|
|
|
|
|
[self waitForExpectationsWithTimeout:1.0
|
|
|
|
|
handler:^(NSError *error) {
|
|
|
|
|
XCTAssertNil(error);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testFetchUserPropertyWithEmptyResponse {
|
|
|
|
|
XCTestExpectation *fetchExpectation =
|
|
|
|
|
[self expectationWithDescription:@"Test fetch empty user property."];
|
|
|
|
|
|
|
|
|
|
// Mocks the user property fetching response.
|
|
|
|
|
OCMStub([_mockAnalytics userPropertiesIncludingInternal:NO
|
|
|
|
|
queue:[OCMArg any]
|
|
|
|
|
callback:([OCMArg invokeBlockWithArgs:@{}, nil])]);
|
|
|
|
|
|
|
|
|
|
// Tests passing nil callback won't crash.
|
|
|
|
|
[_configAnalytics fetchUserPropertiesWithCompletionHandler:nil];
|
|
|
|
|
|
|
|
|
|
[_configAnalytics fetchUserPropertiesWithCompletionHandler:^(NSDictionary *userProperties) {
|
|
|
|
|
XCTAssertNotNil(userProperties);
|
|
|
|
|
XCTAssertEqual(userProperties.count, 0);
|
|
|
|
|
[fetchExpectation fulfill];
|
|
|
|
|
}];
|
|
|
|
|
[self waitForExpectationsWithTimeout:1.0
|
|
|
|
|
handler:^(NSError *error) {
|
|
|
|
|
XCTAssertNil(error);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
@end
|