|
32 | 32 | #import "LeanplumReachability+Category.h" |
33 | 33 | #import "Leanplum+Extensions.h" |
34 | 34 | #import "LPActionManager.h" |
| 35 | +#import "LPCountaggregator.h" |
| 36 | +#import "LPFeatureFlagManager.h" |
35 | 37 | #import "Constants.h" |
36 | 38 | #import "LPRegisterDevice.h" |
37 | 39 |
|
|
40 | 42 | * and validate whether sdk properly parses the response and calls appropriate methods |
41 | 43 | * the test all verifies whether request is properly packed with all necessary data. |
42 | 44 | */ |
| 45 | +@interface Leanplum (Test) |
| 46 | + |
| 47 | ++ (NSSet<NSString *> *)parseEnabledCountersFromResponse:(NSDictionary *)response; |
| 48 | ++ (NSSet<NSString *> *)parseEnabledFeatureFlagsFromResponse:(NSDictionary *)response; |
| 49 | + |
| 50 | +@end |
| 51 | + |
43 | 52 | @interface LeanplumTest : XCTestCase |
44 | 53 |
|
45 | 54 | @end |
@@ -1673,6 +1682,86 @@ - (void)test_configuration |
1673 | 1682 | XCTAssertEqual([LPConstantsState sharedState].networkTimeoutSecondsForDownloads, timeout); |
1674 | 1683 | } |
1675 | 1684 |
|
| 1685 | +- (void)testStartResponseShouldParseCounters |
| 1686 | +{ |
| 1687 | + //Given: start request |
| 1688 | + // This stub have to be removed when start command is successfully executed. |
| 1689 | + id<OHHTTPStubsDescriptor> startStub = [OHHTTPStubs stubRequestsPassingTest: |
| 1690 | + ^BOOL(NSURLRequest * _Nonnull request) { |
| 1691 | + return [request.URL.host isEqualToString:API_HOST]; |
| 1692 | + } withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) { |
| 1693 | + NSString* response_file = OHPathForFile(@"simple_start_response.json", self.class); |
| 1694 | + return [OHHTTPStubsResponse responseWithFileAtPath:response_file statusCode:200 |
| 1695 | + headers:@{@"Content-Type":@"application/json"}]; |
| 1696 | + }]; |
| 1697 | + |
| 1698 | + [LeanplumHelper setup_development_test]; |
| 1699 | + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
| 1700 | + [Leanplum startWithResponseHandler:^(BOOL success) { |
| 1701 | + XCTAssertTrue(success); |
| 1702 | + [OHHTTPStubs removeStub:startStub]; |
| 1703 | + // Then: enabledCounters should be parsed |
| 1704 | + XCTAssertNotNil([[LPCountAggregator sharedAggregator] enabledCounters]); |
| 1705 | + NSSet *enabledCounters = [[LPCountAggregator sharedAggregator] enabledCounters]; |
| 1706 | + NSSet *expected = [NSSet setWithArray:@[@"testCounter1", @"testCounter2"]]; |
| 1707 | + XCTAssertEqualObjects(expected, enabledCounters); |
| 1708 | + |
| 1709 | + dispatch_semaphore_signal(semaphore); |
| 1710 | + }]; |
| 1711 | + dispatch_semaphore_wait(semaphore, [LeanplumHelper default_dispatch_time]); |
| 1712 | +} |
| 1713 | + |
| 1714 | +- (void)testStartResponseShouldParseFeatureFlags |
| 1715 | +{ |
| 1716 | + //Given: start request |
| 1717 | + // This stub have to be removed when start command is successfully executed. |
| 1718 | + id<OHHTTPStubsDescriptor> startStub = [OHHTTPStubs stubRequestsPassingTest: |
| 1719 | + ^BOOL(NSURLRequest * _Nonnull request) { |
| 1720 | + return [request.URL.host isEqualToString:API_HOST]; |
| 1721 | + } withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) { |
| 1722 | + NSString* response_file = OHPathForFile(@"simple_start_response.json", self.class); |
| 1723 | + return [OHHTTPStubsResponse responseWithFileAtPath:response_file statusCode:200 |
| 1724 | + headers:@{@"Content-Type":@"application/json"}]; |
| 1725 | + }]; |
| 1726 | + |
| 1727 | + [LeanplumHelper setup_development_test]; |
| 1728 | + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
| 1729 | + [Leanplum startWithResponseHandler:^(BOOL success) { |
| 1730 | + XCTAssertTrue(success); |
| 1731 | + [OHHTTPStubs removeStub:startStub]; |
| 1732 | + // Then: enabledFeatureFlags should be parsed |
| 1733 | + XCTAssertNotNil([[LPFeatureFlagManager sharedManager] enabledFeatureFlags]); |
| 1734 | + NSSet<NSString *> *enabledFeatureFlags = [[LPFeatureFlagManager sharedManager] enabledFeatureFlags]; |
| 1735 | + NSSet<NSString *> *expected = [NSSet setWithArray:@[@"testFeatureFlag1", @"testFeatureFlag2"]]; |
| 1736 | + XCTAssertEqualObjects(expected, enabledFeatureFlags); |
| 1737 | + |
| 1738 | + dispatch_semaphore_signal(semaphore); |
| 1739 | + }]; |
| 1740 | + dispatch_semaphore_wait(semaphore, [LeanplumHelper default_dispatch_time]); |
| 1741 | +} |
| 1742 | + |
| 1743 | +- (void)test_parseEnabledCounters |
| 1744 | +{ |
| 1745 | + NSMutableDictionary *response = [[NSMutableDictionary alloc] init]; |
| 1746 | + NSSet<NSString *> *enabledCounters = [Leanplum parseEnabledCountersFromResponse:response]; |
| 1747 | + XCTAssertNil(enabledCounters); |
| 1748 | + |
| 1749 | + [response setObject:@[@"test"] forKey:LP_KEY_ENABLED_COUNTERS]; |
| 1750 | + enabledCounters = [Leanplum parseEnabledCountersFromResponse:response]; |
| 1751 | + XCTAssertEqualObjects([NSSet setWithArray:@[@"test"]], enabledCounters); |
| 1752 | +} |
| 1753 | + |
| 1754 | +- (void)test_parseEnabledFeatureFlags |
| 1755 | +{ |
| 1756 | + NSMutableDictionary *response = [[NSMutableDictionary alloc] init]; |
| 1757 | + NSSet<NSString *> *enabledFeatureFlags = [Leanplum parseEnabledFeatureFlagsFromResponse:response]; |
| 1758 | + XCTAssertNil(enabledFeatureFlags); |
| 1759 | + |
| 1760 | + [response setObject:@[@"test"] forKey:LP_KEY_ENABLED_FEATURE_FLAGS]; |
| 1761 | + enabledFeatureFlags = [Leanplum parseEnabledFeatureFlagsFromResponse:response]; |
| 1762 | + XCTAssertEqualObjects([NSSet setWithArray:@[@"test"]], enabledFeatureFlags); |
| 1763 | +} |
| 1764 | + |
1676 | 1765 | #pragma mark - Selectors |
1677 | 1766 |
|
1678 | 1767 | /** |
|
0 commit comments