diff --git a/.github/workflows/automation-trigger-test.yml b/.github/workflows/automation-trigger-test.yml index d9cd2343a..58de2ac06 100644 --- a/.github/workflows/automation-trigger-test.yml +++ b/.github/workflows/automation-trigger-test.yml @@ -80,7 +80,7 @@ jobs: distribution: 'temurin' cache: maven - name: Setup Node.js environment - uses: actions/setup-node@v3.8.2 + uses: actions/setup-node@v4.0.1 - name: Build with Maven id: build_maven run: | diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 3adc37e2c..305206370 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/stale@v8 with: - repo-token: ${{ secrets.STALE_PERSONAL_ACCESS_TOKEN }} + repo-token: ${{ github.token }} days-before-issue-stale: 60 days-before-close: 7 stale-issue-message: 'This issue has been automatically marked as stale due to inactivity for 60 days. If this issue is still relevant, please respond with any updates or this issue will be closed in 7 days. If you believe this is a mistake, please comment to let us know. Thank you for your contributions.' diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index bb594cba0..b7eb8c880 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -31,8 +31,8 @@ jobs: # This happens automatically with the unit_tests lane, but adding it here # makes it easier to keep track of installation time via GHA without # adding execution time to the next step. - - name: Install CocoaPods dependencies - run: bundle exec fastlane prepare_pods + #- name: Install CocoaPods dependencies + # run: bundle exec fastlane prepare_pods - name: Run unit tests run: bundle exec fastlane unit_tests - name: Upload test results diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCApplication.Test.m b/Branch-TestBed/Branch-SDK-Tests/BNCApplicationTests.m similarity index 87% rename from Branch-TestBed/Branch-SDK-Tests/BNCApplication.Test.m rename to Branch-TestBed/Branch-SDK-Tests/BNCApplicationTests.m index e32c1c359..eb48b00e6 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCApplication.Test.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCApplicationTests.m @@ -6,14 +6,22 @@ // Copyright © 2018 Branch, Inc. All rights reserved. // -#import "BNCTestCase.h" +#import #import "BNCApplication.h" #import "BNCKeyChain.h" -@interface BNCApplicationTest : BNCTestCase +@interface BNCApplicationTests : XCTestCase @end -@implementation BNCApplicationTest +@implementation BNCApplicationTests + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} - (void)testApplication { // Test general info: diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCCrashlyticsWrapper.Test.m b/Branch-TestBed/Branch-SDK-Tests/BNCCrashlyticsWrapperTests.m similarity index 76% rename from Branch-TestBed/Branch-SDK-Tests/BNCCrashlyticsWrapper.Test.m rename to Branch-TestBed/Branch-SDK-Tests/BNCCrashlyticsWrapperTests.m index d6d8fc3d7..4b9be75a4 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCCrashlyticsWrapper.Test.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCCrashlyticsWrapperTests.m @@ -6,8 +6,8 @@ // Copyright © 2017 Branch Metrics. All rights reserved. // +#import #import "BNCCrashlyticsWrapper.h" -#import "BNCTestCase.h" #pragma mark Crashlytics SDK Stand-In @@ -42,13 +42,20 @@ -(id)getCustomValueForKey:(NSString *)key { #pragma mark - BNCCrashlyticsWrapperTest -@interface BNCCrashlyticsWrapperTest : BNCTestCase +@interface BNCCrashlyticsWrapperTests : XCTestCase @end -@implementation BNCCrashlyticsWrapperTest +@implementation BNCCrashlyticsWrapperTests -- (void) testSetValue { +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} +- (void)testSetValue { BNCCrashlyticsWrapper *wrapper = [BNCCrashlyticsWrapper wrapper]; NSString *value = @"TestString"; NSString *key = @"TestKey"; diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtils.Test.m b/Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtilsTests.m similarity index 98% rename from Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtils.Test.m rename to Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtilsTests.m index f851e8573..54107d2b5 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtils.Test.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtilsTests.m @@ -8,13 +8,20 @@ #import #import "BNCEncodingUtils.h" -#import "BNCTestCase.h" -@interface BNCEncodingUtilsTests : BNCTestCase +@interface BNCEncodingUtilsTests : XCTestCase @end @implementation BNCEncodingUtilsTests +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + #pragma mark - EncodeDictionaryToJsonString tests - (void)testEncodeDictionaryToJsonStringWithExpectedParams { diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCLinkDataTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCLinkDataTests.m index 9f1096811..10eb3cb25 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCLinkDataTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCLinkDataTests.m @@ -6,14 +6,22 @@ // Copyright (c) 2015 Branch Metrics. All rights reserved. // -#import "BNCTestCase.h" +#import #import "BNCLinkData.h" -@interface BNCLinkDataTests : BNCTestCase +@interface BNCLinkDataTests : XCTestCase @end @implementation BNCLinkDataTests +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + - (void)testBasicObjectHash { BNCLinkData *a = [[BNCLinkData alloc] init]; BNCLinkData *b = [[BNCLinkData alloc] init]; diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCLog.Test.m b/Branch-TestBed/Branch-SDK-Tests/BNCLogTests.m similarity index 74% rename from Branch-TestBed/Branch-SDK-Tests/BNCLog.Test.m rename to Branch-TestBed/Branch-SDK-Tests/BNCLogTests.m index c7349bf31..32e6fcd82 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCLog.Test.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCLogTests.m @@ -1,5 +1,5 @@ /** - @file BNCLog.Test.m + @file BNCLogTests.m @package BranchTests @brief Tests for BNCLog. @@ -10,14 +10,21 @@ #import #import "BNCLog.h" -#import "BNCTestCase.h" -@interface BNCLogTest : BNCTestCase +@interface BNCLogTests : XCTestCase @end -@implementation BNCLogTest +@implementation BNCLogTests -- (void) testLogLevelString { +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +- (void)testLogLevelString { XCTAssertEqual(BNCLogLevelAll, BNCLogLevelFromString(@"BNCLogLevelAll")); XCTAssertEqual(BNCLogLevelDebugSDK, BNCLogLevelFromString(@"BNCLogLevelDebugSDK")); XCTAssertEqual(BNCLogLevelWarning, BNCLogLevelFromString(@"BNCLogLevelWarning")); @@ -25,7 +32,7 @@ - (void) testLogLevelString { XCTAssertEqual(BNCLogLevelMax, BNCLogLevelFromString(@"BNCLogLevelMax")); } -- (void) testLogLevelEnum { +- (void)testLogLevelEnum { XCTAssertEqualObjects(@"BNCLogLevelAll", BNCLogStringFromLogLevel(BNCLogLevelAll)); XCTAssertEqualObjects(@"BNCLogLevelAll", BNCLogStringFromLogLevel(BNCLogLevelDebugSDK)); XCTAssertEqualObjects(@"BNCLogLevelWarning", BNCLogStringFromLogLevel(BNCLogLevelWarning)); diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m index 668c69a36..249fbe2de 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m @@ -10,7 +10,6 @@ #import "BNCPreferenceHelper.h" #import "BNCEncodingUtils.h" #import "Branch.h" -#import "BranchPluginSupport.h" #import "BNCConfig.h" @interface BNCPreferenceHelper() @@ -32,7 +31,7 @@ - (void)setUp { } - (void)tearDown { - + } - (void)testPreferenceDefaults { @@ -42,18 +41,17 @@ - (void)testPreferenceDefaults { XCTAssertFalse(self.prefHelper.disableAdNetworkCallouts); } -//- (void)testPreferenceSets { -// self.prefHelper.retryCount = NSIntegerMax; -// self.prefHelper.retryInterval = NSIntegerMax; -// self.prefHelper.timeout = NSIntegerMax; -// -// XCTAssertEqual(self.prefHelper.retryCount, NSIntegerMax); -// XCTAssertEqual(self.prefHelper.retryInterval, NSIntegerMax); -// XCTAssertEqual(self.prefHelper.timeout, NSIntegerMax); -//} +- (void)testPreferenceSets { + self.prefHelper.retryCount = NSIntegerMax; + self.prefHelper.retryInterval = NSIntegerMax; + self.prefHelper.timeout = NSIntegerMax; + + XCTAssertEqual(self.prefHelper.retryCount, NSIntegerMax); + XCTAssertEqual(self.prefHelper.retryInterval, NSIntegerMax); + XCTAssertEqual(self.prefHelper.timeout, NSIntegerMax); +} -/* - // This test is not reliable when run concurrently with other tests that set the patterListURL +// This test is not reliable when run concurrently with other tests that set the patterListURL - (void)testURLFilter { XCTAssertTrue([@"https://cdn.branch.io" isEqualToString:self.prefHelper.patternListURL]); @@ -61,7 +59,6 @@ - (void)testURLFilter { self.prefHelper.patternListURL = customURL; XCTAssertTrue([customURL isEqualToString:self.prefHelper.patternListURL]); } - */ - (void)testSerializeDict_Nil { NSMutableDictionary *dict = nil; @@ -202,125 +199,123 @@ - (void)testURLSkipList { XCTAssert([filterDesc isEqualToString:valueDesc]); } -/* - (void)testSetAPIURL_Example { NSString *url = @"https://www.example.com/"; - [BranchPluginSupport setAPIUrl:url] ; + [self.prefHelper setBranchAPIURL:url] ; - NSString *urlStored = [BNCPreferenceHelper sharedInstance].branchAPIURL ; + NSString *urlStored = self.prefHelper.branchAPIURL ; XCTAssert([url isEqualToString:urlStored]); } - (void)testSetAPIURL_InvalidHttp { NSString *url = @"Invalid://www.example.com/"; - [BranchPluginSupport setAPIUrl:url] ; + [self.prefHelper setBranchAPIURL:url] ; - NSString *urlStored = [BNCPreferenceHelper sharedInstance].branchAPIURL ; + NSString *urlStored = self.prefHelper.branchAPIURL ; XCTAssert(![url isEqualToString:urlStored]); - XCTAssert([urlStored isEqualToString:BNC_API_BASE_URL]); + XCTAssert([urlStored isEqualToString:BNC_API_URL]); } - (void)testSetAPIURL_InvalidEmpty { - [BranchPluginSupport setAPIUrl:@""] ; + [self.prefHelper setBranchAPIURL:@""] ; - NSString *urlStored = [BNCPreferenceHelper sharedInstance].branchAPIURL ; + NSString *urlStored = self.prefHelper.branchAPIURL ; XCTAssert(![urlStored isEqualToString:@""]); - XCTAssert([urlStored isEqualToString:BNC_API_BASE_URL]); + XCTAssert([urlStored isEqualToString:BNC_API_URL]); } - (void)testSetCDNBaseURL_Example { NSString *url = @"https://www.example.com/"; - [BranchPluginSupport setCDNBaseUrl:url] ; + [self.prefHelper setPatternListURL:url]; - NSString *urlStored = [BNCPreferenceHelper sharedInstance].patternListURL ; + NSString *urlStored = self.prefHelper.patternListURL ; XCTAssert([url isEqualToString:urlStored]); } - (void)testSetCDNBaseURL_InvalidHttp { NSString *url = @"Invalid://www.example.com/"; - [BranchPluginSupport setCDNBaseUrl:url] ; + [self.prefHelper setPatternListURL:url] ; - NSString *urlStored = [BNCPreferenceHelper sharedInstance].patternListURL ; + NSString *urlStored = self.prefHelper.patternListURL ; XCTAssert(![url isEqualToString:urlStored]); XCTAssert([urlStored isEqualToString:BNC_CDN_URL]); } - (void)testSetCDNBaseURL_InvalidEmpty { - [BranchPluginSupport setCDNBaseUrl:@""] ; + [self.prefHelper setPatternListURL:@""] ; - NSString *urlStored = [BNCPreferenceHelper sharedInstance].patternListURL ; + NSString *urlStored = self.prefHelper.patternListURL ; XCTAssert(![urlStored isEqualToString:@""]); XCTAssert([urlStored isEqualToString:BNC_CDN_URL]); } - */ - (void)testSetPatternListURL { NSString *expectedURL = @"https://example.com"; - [[BNCPreferenceHelper sharedInstance] setPatternListURL: expectedURL]; + [self.prefHelper setPatternListURL:expectedURL]; - NSString *patternListURL = [BNCPreferenceHelper sharedInstance].patternListURL; + NSString *patternListURL = self.prefHelper.patternListURL; XCTAssert([patternListURL isEqualToString: expectedURL]); } - (void)testSetLastStrongMatchDate { NSDate *expectedDate = [NSDate date]; - [[BNCPreferenceHelper sharedInstance] setLastStrongMatchDate: expectedDate]; + [self.prefHelper setLastStrongMatchDate: expectedDate]; - NSDate *actualDate = [[BNCPreferenceHelper sharedInstance] lastStrongMatchDate]; + NSDate *actualDate = [self.prefHelper lastStrongMatchDate]; XCTAssertEqualObjects(expectedDate, actualDate); } - (void)testSetAppVersion { NSString *expectedVersion = @"1.0.0"; - [[BNCPreferenceHelper sharedInstance] setAppVersion: expectedVersion]; + [self.prefHelper setAppVersion: expectedVersion]; - NSString *actualVersion = [[BNCPreferenceHelper sharedInstance] appVersion]; + NSString *actualVersion = [self.prefHelper appVersion]; XCTAssertEqualObjects(expectedVersion, actualVersion); } - (void)testSetLocalUrl { NSString *expectedLocalURL = @"https://local.example.com"; - [[BNCPreferenceHelper sharedInstance] setLocalUrl:expectedLocalURL]; + [self.prefHelper setLocalUrl:expectedLocalURL]; - NSString *localURL = [[BNCPreferenceHelper sharedInstance] localUrl]; + NSString *localURL = [self.prefHelper localUrl]; XCTAssertEqualObjects(localURL, expectedLocalURL); } - (void)testSetInitialReferrer { NSString *expectedReferrer = @"referrer.example.com"; - [[BNCPreferenceHelper sharedInstance] setInitialReferrer:expectedReferrer]; + [self.prefHelper setInitialReferrer:expectedReferrer]; - NSString *actualReferrer = [[BNCPreferenceHelper sharedInstance] initialReferrer]; + NSString *actualReferrer = [self.prefHelper initialReferrer]; XCTAssertEqualObjects(actualReferrer, expectedReferrer); } - (void)testSetAppleAttributionTokenChecked { BOOL expectedValue = YES; - [[BNCPreferenceHelper sharedInstance] setAppleAttributionTokenChecked:expectedValue]; + [self.prefHelper setAppleAttributionTokenChecked:expectedValue]; - BOOL actualValue = [[BNCPreferenceHelper sharedInstance] appleAttributionTokenChecked]; + BOOL actualValue = [self.prefHelper appleAttributionTokenChecked]; XCTAssertEqual(expectedValue, actualValue); } - (void)testSetHasOptedInBefore { BOOL expectedValue = YES; - [[BNCPreferenceHelper sharedInstance] setHasOptedInBefore:expectedValue]; + [self.prefHelper setHasOptedInBefore:expectedValue]; - BOOL actualValue = [[BNCPreferenceHelper sharedInstance] hasOptedInBefore]; + BOOL actualValue = [self.prefHelper hasOptedInBefore]; XCTAssertEqual(expectedValue, actualValue); } - (void)testSetHasCalledHandleATTAuthorizationStatus { BOOL expectedValue = YES; - [[BNCPreferenceHelper sharedInstance] setHasCalledHandleATTAuthorizationStatus:expectedValue]; + [self.prefHelper setHasCalledHandleATTAuthorizationStatus:expectedValue]; - BOOL actualValue = [[BNCPreferenceHelper sharedInstance] hasCalledHandleATTAuthorizationStatus]; + BOOL actualValue = [self.prefHelper hasCalledHandleATTAuthorizationStatus]; XCTAssertEqual(expectedValue, actualValue); } @@ -328,9 +323,9 @@ - (void)testSetRequestMetadataKeyValidKeyValue { NSString *key = @"testKey"; NSString *value = @"testValue"; - [[BNCPreferenceHelper sharedInstance] setRequestMetadataKey:key value:value]; + [self.prefHelper setRequestMetadataKey:key value:value]; - NSObject *retrievedValue = [[BNCPreferenceHelper sharedInstance].requestMetadataDictionary objectForKey:key]; + NSObject *retrievedValue = [self.prefHelper.requestMetadataDictionary objectForKey:key]; XCTAssertEqualObjects(retrievedValue, value); } @@ -338,90 +333,91 @@ - (void)testSetRequestMetadataKeyValidKeyNilValue { NSString *key = @"testKey"; NSString *value = @"testValue"; - [[BNCPreferenceHelper sharedInstance].requestMetadataDictionary setObject:value forKey:key]; + [self.prefHelper.requestMetadataDictionary setObject:value forKey:key]; - [[BNCPreferenceHelper sharedInstance] setRequestMetadataKey:key value:nil]; + [self.prefHelper setRequestMetadataKey:key value:nil]; - NSObject *retrievedValue = [[BNCPreferenceHelper sharedInstance].requestMetadataDictionary objectForKey:key]; + NSObject *retrievedValue = [self.prefHelper.requestMetadataDictionary objectForKey:key]; XCTAssertNil(retrievedValue); } - (void)testSetRequestMetadataKeyValidKeyNilValueKeyNotExists { NSString *key = @"testKeyNotExists"; - NSUInteger initialDictCount = [[BNCPreferenceHelper sharedInstance].requestMetadataDictionary count]; + NSUInteger initialDictCount = [self.prefHelper.requestMetadataDictionary count]; - [[BNCPreferenceHelper sharedInstance] setRequestMetadataKey:key value:nil]; + [self.prefHelper setRequestMetadataKey:key value:nil]; - NSUInteger postActionDictCount = [[BNCPreferenceHelper sharedInstance].requestMetadataDictionary count]; + NSUInteger postActionDictCount = [self.prefHelper.requestMetadataDictionary count]; XCTAssertEqual(initialDictCount, postActionDictCount); } - (void)testSetRequestMetadataKeyNilKey { NSString *value = @"testValue"; - NSUInteger initialDictCount = [[BNCPreferenceHelper sharedInstance].requestMetadataDictionary count]; + NSUInteger initialDictCount = [self.prefHelper.requestMetadataDictionary count]; - [[BNCPreferenceHelper sharedInstance] setRequestMetadataKey:nil value:value]; + [self.prefHelper setRequestMetadataKey:nil value:value]; - NSUInteger postActionDictCount = [[BNCPreferenceHelper sharedInstance].requestMetadataDictionary count]; + NSUInteger postActionDictCount = [self.prefHelper.requestMetadataDictionary count]; XCTAssertEqual(initialDictCount, postActionDictCount); } - (void)testSetLimitFacebookTracking { BOOL expectedValue = YES; - [[BNCPreferenceHelper sharedInstance] setLimitFacebookTracking:expectedValue]; + [self.prefHelper setLimitFacebookTracking:expectedValue]; - BOOL storedValue = [[BNCPreferenceHelper sharedInstance] limitFacebookTracking]; + BOOL storedValue = [self.prefHelper limitFacebookTracking]; XCTAssertEqual(expectedValue, storedValue); } - (void)testSetTrackingDisabled_YES { - [[BNCPreferenceHelper sharedInstance] setTrackingDisabled:YES]; + [self.prefHelper setTrackingDisabled:YES]; - BOOL storedValue = [[BNCPreferenceHelper sharedInstance] trackingDisabled]; + BOOL storedValue = [self.prefHelper trackingDisabled]; XCTAssertTrue(storedValue); - [[BNCPreferenceHelper sharedInstance] setTrackingDisabled:NO]; + [self.prefHelper setTrackingDisabled:NO]; } - (void)testSetTrackingDisabled_NO { - [[BNCPreferenceHelper sharedInstance] setTrackingDisabled:NO]; + [self.prefHelper setTrackingDisabled:NO]; - BOOL storedValue = [[BNCPreferenceHelper sharedInstance] trackingDisabled]; + BOOL storedValue = [self.prefHelper trackingDisabled]; XCTAssertFalse(storedValue); } +// TODO: rethink this test as these values are not set in a freshly instantiated prefHelper - (void)testClearTrackingInformation { - [[BNCPreferenceHelper sharedInstance] clearTrackingInformation]; - - XCTAssertNil([BNCPreferenceHelper sharedInstance].sessionID); - XCTAssertNil([BNCPreferenceHelper sharedInstance].linkClickIdentifier); - XCTAssertNil([BNCPreferenceHelper sharedInstance].spotlightIdentifier); - XCTAssertNil([BNCPreferenceHelper sharedInstance].referringURL); - XCTAssertNil([BNCPreferenceHelper sharedInstance].universalLinkUrl); - XCTAssertNil([BNCPreferenceHelper sharedInstance].initialReferrer); - XCTAssertNil([BNCPreferenceHelper sharedInstance].installParams); - XCTAssertNil([BNCPreferenceHelper sharedInstance].sessionParams); - XCTAssertNil([BNCPreferenceHelper sharedInstance].externalIntentURI); - XCTAssertNil([BNCPreferenceHelper sharedInstance].savedAnalyticsData); - XCTAssertNil([BNCPreferenceHelper sharedInstance].previousAppBuildDate); - XCTAssertEqual([BNCPreferenceHelper sharedInstance].requestMetadataDictionary.count, 0); - XCTAssertNil([BNCPreferenceHelper sharedInstance].lastStrongMatchDate); - XCTAssertNil([BNCPreferenceHelper sharedInstance].userIdentity); - XCTAssertNil([BNCPreferenceHelper sharedInstance].referringURLQueryParameters); - XCTAssertNil([BNCPreferenceHelper sharedInstance].anonID); + [self.prefHelper clearTrackingInformation]; + + XCTAssertNil(self.prefHelper.sessionID); + XCTAssertNil(self.prefHelper.linkClickIdentifier); + XCTAssertNil(self.prefHelper.spotlightIdentifier); + XCTAssertNil(self.prefHelper.referringURL); + XCTAssertNil(self.prefHelper.universalLinkUrl); + XCTAssertNil(self.prefHelper.initialReferrer); + XCTAssertNil(self.prefHelper.installParams); + XCTAssertNil(self.prefHelper.sessionParams); + XCTAssertNil(self.prefHelper.externalIntentURI); + XCTAssertNil(self.prefHelper.savedAnalyticsData); + XCTAssertNil(self.prefHelper.previousAppBuildDate); + XCTAssertEqual(self.prefHelper.requestMetadataDictionary.count, 0); + XCTAssertNil(self.prefHelper.lastStrongMatchDate); + XCTAssertNil(self.prefHelper.userIdentity); + XCTAssertNil(self.prefHelper.referringURLQueryParameters); + XCTAssertNil(self.prefHelper.anonID); } - (void)testSaveBranchAnalyticsData { NSString *dummySessionID = @"testSession123"; NSDictionary *dummyAnalyticsData = @{ @"key1": @"value1", @"key2": @"value2" }; - [BNCPreferenceHelper sharedInstance].sessionID = dummySessionID; + self.prefHelper.sessionID = dummySessionID; - [[BNCPreferenceHelper sharedInstance] saveBranchAnalyticsData:dummyAnalyticsData]; + [self.prefHelper saveBranchAnalyticsData:dummyAnalyticsData]; - NSMutableDictionary *retrievedData = [[BNCPreferenceHelper sharedInstance] getBranchAnalyticsData]; + NSMutableDictionary *retrievedData = [self.prefHelper getBranchAnalyticsData]; NSArray *viewDataArray = [retrievedData objectForKey:dummySessionID]; XCTAssertNotNil(viewDataArray); @@ -430,22 +426,20 @@ - (void)testSaveBranchAnalyticsData { } - (void)testClearBranchAnalyticsData { - [[BNCPreferenceHelper sharedInstance] clearBranchAnalyticsData]; + [self.prefHelper clearBranchAnalyticsData]; - NSMutableDictionary *retrievedData = [[BNCPreferenceHelper sharedInstance] getBranchAnalyticsData]; + NSMutableDictionary *retrievedData = [self.prefHelper getBranchAnalyticsData]; XCTAssertEqual(retrievedData.count, 0); } - (void)testSaveContentAnalyticsManifest { NSDictionary *dummyManifest = @{ @"manifestKey1": @"manifestValue1", @"manifestKey2": @"manifestValue2" }; - [[BNCPreferenceHelper sharedInstance] saveContentAnalyticsManifest:dummyManifest]; + [self.prefHelper saveContentAnalyticsManifest:dummyManifest]; - NSDictionary *retrievedManifest = [[BNCPreferenceHelper sharedInstance] getContentAnalyticsManifest]; + NSDictionary *retrievedManifest = [self.prefHelper getContentAnalyticsManifest]; XCTAssertEqualObjects(retrievedManifest, dummyManifest); } - - @end diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCServerInterface.Test.m b/Branch-TestBed/Branch-SDK-Tests/BNCServerInterface.Test.m index cdd4401c7..944a792f1 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCServerInterface.Test.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCServerInterface.Test.m @@ -11,93 +11,190 @@ #import "BNCServerInterface.h" #import "BNCPreferenceHelper.h" #import "BranchConstants.h" -#import -#import -#import +//#import +//#import +//#import -typedef void (^UrlConnectionCallback)(NSURLResponse *, NSData *, NSError *); - -@interface BNCServerInterface() - -// private BNCServerInterface method/properties to prepare dictionary for requests -@property (copy, nonatomic) NSString *requestEndpoint; -- (NSMutableDictionary *)prepareParamDict:(NSDictionary *)params - key:(NSString *)key - retryNumber:(NSInteger)retryNumber - requestType:(NSString *)reqType; -@end - - - -@interface BNCServerInterfaceTests : BNCTestCase -@end - -@implementation BNCServerInterfaceTests - -#pragma mark - Tear Down - -- (void)tearDown { - [HTTPStubs removeAllStubs]; - [super tearDown]; -} - - -#pragma mark - Key tests - -//================================================================================== -// TEST 01 -// This test checks to see that the branch key has been added to the GET request - -- (void)testParamAddForBranchKey { - [HTTPStubs removeAllStubs]; - BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; - XCTestExpectation* expectation = - [self expectationWithDescription:@"NSURLSessionDataTask completed"]; - - __block int callCount = 0; - [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { - // We're not sending a request, just verifying a "branch_key=key_xxx" is present. - callCount++; - NSLog(@"\n\nCall count %d.\nRequest: %@\n", callCount, request); - if (callCount == 1) { - BOOL foundIt = ([request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound); - XCTAssertTrue(foundIt, @"Branch Key not added"); - BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [expectation fulfill]; }); - return YES; - } - return NO; - } - withStubResponse:^HTTPStubsResponse *(NSURLRequest *request) { - NSDictionary* dummyJSONResponse = @{@"key": @"value"}; - return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; - } - ]; - - [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; - [self waitForExpectationsWithTimeout:5.0 handler:nil]; - [HTTPStubs removeAllStubs]; -} - -#pragma mark - Retry tests - -//================================================================================== -// TEST 03 -// This test simulates a poor network, with three failed GET attempts and one final success, -// for 4 connections. - -//- (void)testGetRequestAsyncRetriesWhenAppropriate { +//typedef void (^UrlConnectionCallback)(NSURLResponse *, NSData *, NSError *); +// +//@interface BNCServerInterface() +// +//// private BNCServerInterface method/properties to prepare dictionary for requests +//@property (copy, nonatomic) NSString *requestEndpoint; +//- (NSMutableDictionary *)prepareParamDict:(NSDictionary *)params +// key:(NSString *)key +// retryNumber:(NSInteger)retryNumber +// requestType:(NSString *)reqType; +//@end +// +// +// +//@interface BNCServerInterfaceTests : BNCTestCase +//@end +// +//@implementation BNCServerInterfaceTests +// +//#pragma mark - Tear Down +// +//- (void)tearDown { +// [HTTPStubs removeAllStubs]; +// [super tearDown]; +//} +// +// +//#pragma mark - Key tests +// +////================================================================================== +//// TEST 01 +//// This test checks to see that the branch key has been added to the GET request +// +//- (void)testParamAddForBranchKey { +// [HTTPStubs removeAllStubs]; +// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; +// XCTestExpectation* expectation = +// [self expectationWithDescription:@"NSURLSessionDataTask completed"]; +// +// __block int callCount = 0; +// [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { +// // We're not sending a request, just verifying a "branch_key=key_xxx" is present. +// callCount++; +// NSLog(@"\n\nCall count %d.\nRequest: %@\n", callCount, request); +// if (callCount == 1) { +// BOOL foundIt = ([request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound); +// XCTAssertTrue(foundIt, @"Branch Key not added"); +// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [expectation fulfill]; }); +// return YES; +// } +// return NO; +// } +// withStubResponse:^HTTPStubsResponse *(NSURLRequest *request) { +// NSDictionary* dummyJSONResponse = @{@"key": @"value"}; +// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; +// } +// ]; +// +// [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; +// [self waitForExpectationsWithTimeout:5.0 handler:nil]; +// [HTTPStubs removeAllStubs]; +//} +// +//#pragma mark - Retry tests +// +////================================================================================== +//// TEST 03 +//// This test simulates a poor network, with three failed GET attempts and one final success, +//// for 4 connections. +// +////- (void)testGetRequestAsyncRetriesWhenAppropriate { +//// [HTTPStubs removeAllStubs]; +//// +//// //Set up nsurlsession and data task, catching response +//// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; +//// serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; +//// serverInterface.preferenceHelper.retryCount = 3; +//// +//// XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; +//// +//// __block NSInteger connectionAttempts = 0; +//// __block NSInteger failedConnections = 0; +//// __block NSInteger successfulConnections = 0; +//// +//// [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { +//// BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; +//// XCTAssertEqual(foundBranchKey, TRUE); +//// return foundBranchKey; +//// +//// } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { +//// @synchronized (self) { +//// connectionAttempts++; +//// NSLog(@"Attempt # %lu", (unsigned long)connectionAttempts); +//// if (connectionAttempts < 3) { +//// +//// // Return an error the first three times +//// NSDictionary* dummyJSONResponse = @{@"bad": @"data"}; +//// +//// ++failedConnections; +//// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:504 headers:nil]; +//// +//// } else if (connectionAttempts == 3) { +//// +//// // Return actual data afterwards +//// ++successfulConnections; +//// XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections); +//// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ +//// NSLog(@"==> Fullfill."); +//// [successExpectation fulfill]; +//// }); +//// +//// NSDictionary* dummyJSONResponse = @{@"key": @"value"}; +//// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; +//// +//// } else { +//// +//// XCTFail(@"Too many connection attempts: %ld.", (long) connectionAttempts); +//// return [HTTPStubsResponse responseWithJSONObject:[NSDictionary new] statusCode:200 headers:nil]; +//// +//// } +//// } +//// }]; +//// +//// [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; +//// [self waitForExpectationsWithTimeout:10.0 handler:nil]; +////} +// +////================================================================================== +//// TEST 04 +//// This test checks to make sure that GET retries are not attempted when they have a retry +//// count > 0, but retries aren't needed. Based on Test #3 above. +// +//- (void)testGetRequestAsyncRetriesWhenInappropriateResponse { // [HTTPStubs removeAllStubs]; // -// //Set up nsurlsession and data task, catching response // BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; // serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; // serverInterface.preferenceHelper.retryCount = 3; +// +// XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; +// +// __block NSUInteger connectionAttempts = 0; +// +// [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { +// BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; +// XCTAssertEqual(foundBranchKey, TRUE); +// return foundBranchKey; +// +// } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { +// @synchronized (self) { +// // Return actual data on first attempt +// NSDictionary* dummyJSONResponse = @{@"key": @"value"}; +// connectionAttempts++; +// XCTAssertEqual(connectionAttempts, 1); +// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^ { +// [successExpectation fulfill]; +// }); +// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; +// } +// }]; +// +// [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; +// [self waitForExpectationsWithTimeout:2.0 handler:nil]; +//} // +////================================================================================== +//// TEST 05 +//// This test checks to make sure that GET retries are not attempted when they have a retry +//// count == 0, but retries aren't needed. Based on Test #4 above +// +//- (void)testGetRequestAsyncRetriesWhenInappropriateRetryCount { +// [HTTPStubs removeAllStubs]; +// +// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; +// serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; +// serverInterface.preferenceHelper.retryCount = 0; +// // XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; // -// __block NSInteger connectionAttempts = 0; -// __block NSInteger failedConnections = 0; -// __block NSInteger successfulConnections = 0; +// __block NSUInteger connectionAttempts = 0; // // [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { // BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; @@ -106,275 +203,178 @@ - (void)testParamAddForBranchKey { // // } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { // @synchronized (self) { +// // Return actual data on first attempt +// NSDictionary* dummyJSONResponse = @{@"key": @"value"}; // connectionAttempts++; -// NSLog(@"Attempt # %lu", (unsigned long)connectionAttempts); -// if (connectionAttempts < 3) { -// -// // Return an error the first three times -// NSDictionary* dummyJSONResponse = @{@"bad": @"data"}; -// -// ++failedConnections; -// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:504 headers:nil]; -// -// } else if (connectionAttempts == 3) { -// -// // Return actual data afterwards -// ++successfulConnections; -// XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections); -// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ -// NSLog(@"==> Fullfill."); +// XCTAssertEqual(connectionAttempts, 1); +// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ // [successExpectation fulfill]; -// }); +// }); +// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; +// } +// }]; +// +// [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; +// [self waitForExpectationsWithTimeout:2.0 handler:nil]; +//} +// +////================================================================================== +//// TEST 06 +//// This test simulates a poor network, with three failed GET attempts and one final success, +//// for 4 connections. Based on Test #3 above +// +//- (void)testPostRequestAsyncRetriesWhenAppropriate { +// [HTTPStubs removeAllStubs]; +// +// //Set up nsurlsession and data task, catching response +// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; +// serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; +// serverInterface.preferenceHelper.retryCount = 3; +// [serverInterface.preferenceHelper synchronize]; +// +// XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; +// +// __block NSUInteger connectionAttempts = 0; +// __block NSUInteger failedConnections = 0; +// __block NSUInteger successfulConnections = 0; +// +// [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { +// BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; +// XCTAssertEqual(foundBranchKey, TRUE); +// return foundBranchKey; +// +// } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { +// connectionAttempts++; +// NSLog(@"attempt # %lu", (unsigned long)connectionAttempts); +// if (connectionAttempts < 3) { +// // Return an error the first three times +// NSDictionary* dummyJSONResponse = @{@"bad": @"data"}; +// +// ++failedConnections; +// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:504 headers:nil]; +// +// } else if (connectionAttempts == 3) { // -// NSDictionary* dummyJSONResponse = @{@"key": @"value"}; -// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; +// // Return actual data afterwards +// ++successfulConnections; +// NSDictionary* dummyJSONResponse = @{@"key": @"value"}; +// XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections); +// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^ { +// NSLog(@"==>> Fullfill <<=="); +// [successExpectation fulfill]; +// }); +// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; // -// } else { +// } else { // -// XCTFail(@"Too many connection attempts: %ld.", (long) connectionAttempts); -// return [HTTPStubsResponse responseWithJSONObject:[NSDictionary new] statusCode:200 headers:nil]; +// XCTFail(@"Too many connection attempts: %ld.", (long) connectionAttempts); +// return [HTTPStubsResponse responseWithJSONObject:[NSDictionary new] statusCode:200 headers:nil]; // -// } // } // }]; // +// [serverInterface postRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; +// [self waitForExpectationsWithTimeout:5.0 handler:nil]; +//} +// +////================================================================================== +//// TEST 07 +//// This test checks to make sure that POST retries are not attempted when they have a retry +//// count == 0, and retries aren't needed. Based on Test #4 above +// +//- (void)testPostRequestAsyncRetriesWhenInappropriateResponse { +// [HTTPStubs removeAllStubs]; +// +// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; +// serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; +// serverInterface.preferenceHelper.retryCount = 3; +// +// XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; +// +// __block NSUInteger connectionAttempts = 0; +// +// [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { +// BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; +// XCTAssertEqual(foundBranchKey, TRUE); +// return foundBranchKey; +// +// } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { +// // Return actual data on first attempt +// NSDictionary* dummyJSONResponse = @{@"key": @"value"}; +// connectionAttempts++; +// XCTAssertEqual(connectionAttempts, 1); +// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; }); +// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; +// +// }]; +// +// [serverInterface postRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; +// [self waitForExpectationsWithTimeout:1.0 handler:nil]; +// +//} +// +////================================================================================== +//// TEST 08 +//// This test checks to make sure that GET retries are not attempted when they have a retry +//// count == 0, and retries aren't needed. Based on Test #4 above +// +//- (void)testPostRequestAsyncRetriesWhenInappropriateRetryCount { +// [HTTPStubs removeAllStubs]; +// +// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; +// serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; +// serverInterface.preferenceHelper.retryCount = 0; +// +// XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; +// +// __block NSUInteger connectionAttempts = 0; +// +// [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { +// BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; +// XCTAssertEqual(foundBranchKey, TRUE); +// return foundBranchKey; +// +// } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { +// // Return actual data on first attempt +// NSDictionary* dummyJSONResponse = @{@"key": @"value"}; +// connectionAttempts++; +// XCTAssertEqual(connectionAttempts, 1); +// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; }); +// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; +// }]; +// // [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; -// [self waitForExpectationsWithTimeout:10.0 handler:nil]; +// [self waitForExpectationsWithTimeout:1.0 handler:nil]; //} - -//================================================================================== -// TEST 04 -// This test checks to make sure that GET retries are not attempted when they have a retry -// count > 0, but retries aren't needed. Based on Test #3 above. - -- (void)testGetRequestAsyncRetriesWhenInappropriateResponse { - [HTTPStubs removeAllStubs]; - - BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; - serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; - serverInterface.preferenceHelper.retryCount = 3; - - XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; - - __block NSUInteger connectionAttempts = 0; - - [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { - BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; - XCTAssertEqual(foundBranchKey, TRUE); - return foundBranchKey; - - } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { - @synchronized (self) { - // Return actual data on first attempt - NSDictionary* dummyJSONResponse = @{@"key": @"value"}; - connectionAttempts++; - XCTAssertEqual(connectionAttempts, 1); - BNCAfterSecondsPerformBlockOnMainThread(0.01, ^ { - [successExpectation fulfill]; - }); - return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; - } - }]; - - [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; -} - -//================================================================================== -// TEST 05 -// This test checks to make sure that GET retries are not attempted when they have a retry -// count == 0, but retries aren't needed. Based on Test #4 above - -- (void)testGetRequestAsyncRetriesWhenInappropriateRetryCount { - [HTTPStubs removeAllStubs]; - - BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; - serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; - serverInterface.preferenceHelper.retryCount = 0; - - XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; - - __block NSUInteger connectionAttempts = 0; - - [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { - BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; - XCTAssertEqual(foundBranchKey, TRUE); - return foundBranchKey; - - } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { - @synchronized (self) { - // Return actual data on first attempt - NSDictionary* dummyJSONResponse = @{@"key": @"value"}; - connectionAttempts++; - XCTAssertEqual(connectionAttempts, 1); - BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ - [successExpectation fulfill]; - }); - return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; - } - }]; - - [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; -} - -//================================================================================== -// TEST 06 -// This test simulates a poor network, with three failed GET attempts and one final success, -// for 4 connections. Based on Test #3 above - -- (void)testPostRequestAsyncRetriesWhenAppropriate { - [HTTPStubs removeAllStubs]; - - //Set up nsurlsession and data task, catching response - BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; - serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; - serverInterface.preferenceHelper.retryCount = 3; - [serverInterface.preferenceHelper synchronize]; - - XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; - - __block NSUInteger connectionAttempts = 0; - __block NSUInteger failedConnections = 0; - __block NSUInteger successfulConnections = 0; - - [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { - BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; - XCTAssertEqual(foundBranchKey, TRUE); - return foundBranchKey; - - } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { - connectionAttempts++; - NSLog(@"attempt # %lu", (unsigned long)connectionAttempts); - if (connectionAttempts < 3) { - // Return an error the first three times - NSDictionary* dummyJSONResponse = @{@"bad": @"data"}; - - ++failedConnections; - return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:504 headers:nil]; - - } else if (connectionAttempts == 3) { - - // Return actual data afterwards - ++successfulConnections; - NSDictionary* dummyJSONResponse = @{@"key": @"value"}; - XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections); - BNCAfterSecondsPerformBlockOnMainThread(0.01, ^ { - NSLog(@"==>> Fullfill <<=="); - [successExpectation fulfill]; - }); - return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; - - } else { - - XCTFail(@"Too many connection attempts: %ld.", (long) connectionAttempts); - return [HTTPStubsResponse responseWithJSONObject:[NSDictionary new] statusCode:200 headers:nil]; - - } - }]; - - [serverInterface postRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; - [self waitForExpectationsWithTimeout:5.0 handler:nil]; -} - -//================================================================================== -// TEST 07 -// This test checks to make sure that POST retries are not attempted when they have a retry -// count == 0, and retries aren't needed. Based on Test #4 above - -- (void)testPostRequestAsyncRetriesWhenInappropriateResponse { - [HTTPStubs removeAllStubs]; - - BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; - serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; - serverInterface.preferenceHelper.retryCount = 3; - - XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; - - __block NSUInteger connectionAttempts = 0; - - [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { - BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; - XCTAssertEqual(foundBranchKey, TRUE); - return foundBranchKey; - - } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { - // Return actual data on first attempt - NSDictionary* dummyJSONResponse = @{@"key": @"value"}; - connectionAttempts++; - XCTAssertEqual(connectionAttempts, 1); - BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; }); - return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; - - }]; - - [serverInterface postRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; - [self waitForExpectationsWithTimeout:1.0 handler:nil]; - -} - -//================================================================================== -// TEST 08 -// This test checks to make sure that GET retries are not attempted when they have a retry -// count == 0, and retries aren't needed. Based on Test #4 above - -- (void)testPostRequestAsyncRetriesWhenInappropriateRetryCount { - [HTTPStubs removeAllStubs]; - - BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; - serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init]; - serverInterface.preferenceHelper.retryCount = 0; - - XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; - - __block NSUInteger connectionAttempts = 0; - - [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { - BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound; - XCTAssertEqual(foundBranchKey, TRUE); - return foundBranchKey; - - } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) { - // Return actual data on first attempt - NSDictionary* dummyJSONResponse = @{@"key": @"value"}; - connectionAttempts++; - XCTAssertEqual(connectionAttempts, 1); - BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; }); - return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil]; - }]; - - [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL]; - [self waitForExpectationsWithTimeout:1.0 handler:nil]; -} - -//================================================================================== -// TEST 10 -// Test mapping of X-Branch-Request-Id to [BNCServerResponse requestId] - -- (void)testRequestIdFromHeader { - [HTTPStubs removeAllStubs]; - - BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; - NSString *requestId = @"1325e434fa294d3bb7d461349118602d-2020102721"; - - XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; - - [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { - // Return the following response for any request - return YES; - } withStubResponse:^HTTPStubsResponse *(NSURLRequest *request) { - // Stub out a response with a X-Branch-Request-Id header - return [HTTPStubsResponse responseWithJSONObject:@{} statusCode:200 headers:@{@"X-Branch-Request-Id": requestId}]; - }]; - - // POST to trigger the stubbed response. - [serverInterface postRequest:@{} url:@"https://api.branch.io/v1/open" key:@"key_live_xxxx" callback:^(BNCServerResponse *response, NSError *error) { - // Verify the request ID value on the BNCServerResponse - BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; }); - XCTAssertEqualObjects(response.requestId, requestId); - }]; - - [self waitForExpectationsWithTimeout:5.0 handler:nil]; -} - -@end +// +////================================================================================== +//// TEST 10 +//// Test mapping of X-Branch-Request-Id to [BNCServerResponse requestId] +// +//- (void)testRequestIdFromHeader { +// [HTTPStubs removeAllStubs]; +// +// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init]; +// NSString *requestId = @"1325e434fa294d3bb7d461349118602d-2020102721"; +// +// XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"]; +// +// [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { +// // Return the following response for any request +// return YES; +// } withStubResponse:^HTTPStubsResponse *(NSURLRequest *request) { +// // Stub out a response with a X-Branch-Request-Id header +// return [HTTPStubsResponse responseWithJSONObject:@{} statusCode:200 headers:@{@"X-Branch-Request-Id": requestId}]; +// }]; +// +// // POST to trigger the stubbed response. +// [serverInterface postRequest:@{} url:@"https://api.branch.io/v1/open" key:@"key_live_xxxx" callback:^(BNCServerResponse *response, NSError *error) { +// // Verify the request ID value on the BNCServerResponse +// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; }); +// XCTAssertEqualObjects(response.requestId, requestId); +// }]; +// +// [self waitForExpectationsWithTimeout:5.0 handler:nil]; +//} +// +//@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueOldTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueOldTests.m index 9ca55fd3b..43343671d 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueOldTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueOldTests.m @@ -9,115 +9,116 @@ #import "BNCTestCase.h" #import "BNCServerRequestQueue.h" #import "BranchOpenRequest.h" -#import #import "Branch.h" -@interface BNCServerRequestQueue (BNCTests) -- (void)retrieve; -- (void)cancelTimer; -@end - -@interface BNCServerRequestQueueOldTests : BNCTestCase -@end - -@implementation BNCServerRequestQueueOldTests - -#pragma mark - MoveOpenOrInstallToFront tests - -+ (void) setUp { - [self clearAllBranchSettings]; // Clear any saved data before our tests start. -// Branch*branch = [Branch getInstance:@"key_live_foo"]; -// [self clearAllBranchSettings]; -} - -- (void)testMoveOpenOrInstallToFrontWhenEmpty { - BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; - XCTAssertNoThrow([requestQueue moveInstallOrOpenToFront:0]); -} - -- (void)testMoveOpenOrInstallToFrontWhenNotPresent { - BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; - [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; - [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; - XCTAssertNoThrow([requestQueue moveInstallOrOpenToFront:0]); -} - -- (void)testMoveOpenOrInstallToFrontWhenAlreadyInFrontAndNoRequestsInProgress { - BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; - [requestQueue insert:[[BranchOpenRequest alloc] init] at:0]; - - id requestQueueMock = OCMPartialMock(requestQueue); - [[requestQueueMock reject] removeAt:0]; - - [requestQueue moveInstallOrOpenToFront:0]; -} - -- (void)testMoveOpenOrInstallToFrontWhenAlreadyInFrontWithRequestsInProgress { - BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; - [requestQueue insert:[[BranchOpenRequest alloc] init] at:0]; - - id requestQueueMock = OCMPartialMock(requestQueue); - [[requestQueueMock reject] removeAt:0]; - - [requestQueue moveInstallOrOpenToFront:1]; -} - -- (void)testMoveOpenOrInstallToFrontWhenSecondInLineWithRequestsInProgress { - BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; - [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; - [requestQueue insert:[[BranchOpenRequest alloc] init] at:1]; - - id requestQueueMock = OCMPartialMock(requestQueue); - [[requestQueueMock reject] removeAt:1]; - - [requestQueue moveInstallOrOpenToFront:1]; -} - -- (void)testMoveOpenOrInstallToFrontWhenSecondInLineWithNoRequestsInProgress { - BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; - BranchOpenRequest *openRequest = [[BranchOpenRequest alloc] init]; - [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; - [requestQueue insert:openRequest at:1]; - - id requestQueueMock = OCMPartialMock(requestQueue); - [[[requestQueueMock expect] andForwardToRealObject] removeAt:1]; - - [requestQueue moveInstallOrOpenToFront:0]; - XCTAssertEqual([requestQueue peek], openRequest); - - [requestQueueMock verify]; -} - -- (void)testMoveOpenOrInstallToFrontWhenThirdInLineWithRequestsInProgress { - BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; - BranchOpenRequest *openRequest = [[BranchOpenRequest alloc] init]; - [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; - [requestQueue insert:[[BNCServerRequest alloc] init] at:1]; - [requestQueue insert:openRequest at:2]; - - id requestQueueMock = OCMPartialMock(requestQueue); - [[[requestQueueMock expect] andForwardToRealObject] removeAt:2]; - - [requestQueue moveInstallOrOpenToFront:1]; - XCTAssertEqual([requestQueue peekAt:1], openRequest); - - [requestQueueMock verify]; -} - -- (void)testMoveOpenOrInstallToFrontWhenThirdInLineWithNoRequestsInProgress { - BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; - BranchOpenRequest *openRequest = [[BranchOpenRequest alloc] init]; - [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; - [requestQueue insert:[[BNCServerRequest alloc] init] at:1]; - [requestQueue insert:openRequest at:2]; - - id requestQueueMock = OCMPartialMock(requestQueue); - [[[requestQueueMock expect] andForwardToRealObject] removeAt:2]; - - [requestQueue moveInstallOrOpenToFront:0]; - XCTAssertEqual([requestQueue peek], openRequest); - - [requestQueueMock verify]; -} - -@end +//#import +// +//@interface BNCServerRequestQueue (BNCTests) +//- (void)retrieve; +//- (void)cancelTimer; +//@end +// +//@interface BNCServerRequestQueueOldTests : BNCTestCase +//@end +// +//@implementation BNCServerRequestQueueOldTests +// +//#pragma mark - MoveOpenOrInstallToFront tests +// +//+ (void) setUp { +// [self clearAllBranchSettings]; // Clear any saved data before our tests start. +//// Branch*branch = [Branch getInstance:@"key_live_foo"]; +//// [self clearAllBranchSettings]; +//} +// +//- (void)testMoveOpenOrInstallToFrontWhenEmpty { +// BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; +// XCTAssertNoThrow([requestQueue moveInstallOrOpenToFront:0]); +//} +// +//- (void)testMoveOpenOrInstallToFrontWhenNotPresent { +// BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; +// [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; +// [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; +// XCTAssertNoThrow([requestQueue moveInstallOrOpenToFront:0]); +//} +// +//- (void)testMoveOpenOrInstallToFrontWhenAlreadyInFrontAndNoRequestsInProgress { +// BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; +// [requestQueue insert:[[BranchOpenRequest alloc] init] at:0]; +// +// id requestQueueMock = OCMPartialMock(requestQueue); +// [[requestQueueMock reject] removeAt:0]; +// +// [requestQueue moveInstallOrOpenToFront:0]; +//} +// +//- (void)testMoveOpenOrInstallToFrontWhenAlreadyInFrontWithRequestsInProgress { +// BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; +// [requestQueue insert:[[BranchOpenRequest alloc] init] at:0]; +// +// id requestQueueMock = OCMPartialMock(requestQueue); +// [[requestQueueMock reject] removeAt:0]; +// +// [requestQueue moveInstallOrOpenToFront:1]; +//} +// +//- (void)testMoveOpenOrInstallToFrontWhenSecondInLineWithRequestsInProgress { +// BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; +// [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; +// [requestQueue insert:[[BranchOpenRequest alloc] init] at:1]; +// +// id requestQueueMock = OCMPartialMock(requestQueue); +// [[requestQueueMock reject] removeAt:1]; +// +// [requestQueue moveInstallOrOpenToFront:1]; +//} +// +//- (void)testMoveOpenOrInstallToFrontWhenSecondInLineWithNoRequestsInProgress { +// BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; +// BranchOpenRequest *openRequest = [[BranchOpenRequest alloc] init]; +// [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; +// [requestQueue insert:openRequest at:1]; +// +// id requestQueueMock = OCMPartialMock(requestQueue); +// [[[requestQueueMock expect] andForwardToRealObject] removeAt:1]; +// +// [requestQueue moveInstallOrOpenToFront:0]; +// XCTAssertEqual([requestQueue peek], openRequest); +// +// [requestQueueMock verify]; +//} +// +//- (void)testMoveOpenOrInstallToFrontWhenThirdInLineWithRequestsInProgress { +// BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; +// BranchOpenRequest *openRequest = [[BranchOpenRequest alloc] init]; +// [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; +// [requestQueue insert:[[BNCServerRequest alloc] init] at:1]; +// [requestQueue insert:openRequest at:2]; +// +// id requestQueueMock = OCMPartialMock(requestQueue); +// [[[requestQueueMock expect] andForwardToRealObject] removeAt:2]; +// +// [requestQueue moveInstallOrOpenToFront:1]; +// XCTAssertEqual([requestQueue peekAt:1], openRequest); +// +// [requestQueueMock verify]; +//} +// +//- (void)testMoveOpenOrInstallToFrontWhenThirdInLineWithNoRequestsInProgress { +// BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init]; +// BranchOpenRequest *openRequest = [[BranchOpenRequest alloc] init]; +// [requestQueue insert:[[BNCServerRequest alloc] init] at:0]; +// [requestQueue insert:[[BNCServerRequest alloc] init] at:1]; +// [requestQueue insert:openRequest at:2]; +// +// id requestQueueMock = OCMPartialMock(requestQueue); +// [[[requestQueueMock expect] andForwardToRealObject] removeAt:2]; +// +// [requestQueue moveInstallOrOpenToFront:0]; +// XCTAssertEqual([requestQueue peek], openRequest); +// +// [requestQueueMock verify]; +//} +// +//@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.h b/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.h index 7b9d2b7e7..777a5ac43 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.h +++ b/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.h @@ -9,7 +9,6 @@ */ #import -#import #import "NSString+Branch.h" #import "BNCThreads.h" @@ -30,7 +29,6 @@ extern BOOL BNCTestStringMatchesRegex(NSString *string, NSString *regex); - (void)safelyFulfillExpectation:(XCTestExpectation *)expectation; - (void)awaitExpectations; - (void)resetExpectations; -- (id)stringMatchingPattern:(NSString *)pattern; - (double) systemVersion; // Load Resources from the test bundle: diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m b/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m index 5f49a0b03..76ab2e1d2 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m @@ -65,19 +65,6 @@ - (void)awaitExpectations { }]; } -- (id)stringMatchingPattern:(NSString *)pattern { - NSRegularExpression *regex = - [[NSRegularExpression alloc] - initWithPattern:pattern - options:NSRegularExpressionCaseInsensitive - error:nil]; - - return [OCMArg checkWithBlock:^BOOL(NSString *param) { - return [regex numberOfMatchesInString:param - options:kNilOptions range:NSMakeRange(0, param.length)] > 0; - }]; -} - - (NSString*) stringFromBundleWithKey:(NSString*)key { NSString *const kItemNotFound = @""; NSString *resource = diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCURLFilterSkiplistUpgradeTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCURLFilterSkiplistUpgradeTests.m index 60d9fc4c3..ad7d5b029 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCURLFilterSkiplistUpgradeTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCURLFilterSkiplistUpgradeTests.m @@ -9,13 +9,6 @@ #import #import "BNCURLFilter.h" -@interface BNCURLFilter(Test) - -// BNCURLFilter defines this as an ivar with a setter & getter, redefine it as a property -@property (nonatomic, strong, readwrite) NSArray *patternList; -@property (assign, nonatomic) NSInteger listVersion; -@end - @interface BNCURLFilterSkiplistUpgradeTests : XCTestCase @end @@ -77,26 +70,24 @@ - (void)tearDown { - (BNCURLFilter *)filterWithV0List { BNCURLFilter *filter = [BNCURLFilter new]; - [self migrateFilter:filter patternList:[self v1PatternList] version:1]; + [self migrateFilter:filter patternList:[self v1PatternList]]; return filter; } - (BNCURLFilter *)filterWithV1List { BNCURLFilter *filter = [BNCURLFilter new]; - [self migrateFilter:filter patternList:[self v1PatternList] version:1]; + [self migrateFilter:filter patternList:[self v1PatternList]]; return filter; } - (BNCURLFilter *)filterWithV2List { BNCURLFilter *filter = [BNCURLFilter new]; - [self migrateFilter:filter patternList:[self v2PatternList] version:2]; + [self migrateFilter:filter patternList:[self v2PatternList]]; return filter; } -- (void)migrateFilter:(BNCURLFilter *)filter patternList:(NSArray *)patternList version:(NSInteger)version { - // BNCURLFilter updates the global storage when these are set - filter.patternList = patternList; - filter.listVersion = version; +- (void)migrateFilter:(BNCURLFilter *)filter patternList:(NSArray *)patternList { + [filter useCustomPatternList:patternList]; } - (NSArray *)badURLs { diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCURLFilterTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCURLFilterTests.m index bc9c797f6..b6b3c9f0f 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCURLFilterTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCURLFilterTests.m @@ -8,207 +8,177 @@ @copyright Copyright © 2018 Branch. All rights reserved. */ -#import "BNCTestCase.h" +#import #import "BNCURLFilter.h" -#import "Branch.h" -#import "BNCLog.h" -@interface BNCURLFilter () -@property (readwrite) NSURL *jsonURL; -@end - -@interface BNCURLFilterTests : BNCTestCase +@interface BNCURLFilterTests : XCTestCase @end @implementation BNCURLFilterTests -- (void) setUp { - [BNCPreferenceHelper sharedInstance].savedURLPatternList = nil; - [BNCPreferenceHelper sharedInstance].savedURLPatternListVersion = 0; - [BNCPreferenceHelper sharedInstance].dropURLOpen = NO; +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. } -- (void) tearDown { - [BNCPreferenceHelper sharedInstance].dropURLOpen = NO; +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. } -/* - // Test is unreliable when run in parallel with other tests, it's using a persistent datastore... -- (void)testListDownLoad { - XCTestExpectation *expectation = [self expectationWithDescription:@"List Download"]; +- (void)testPatternMatchingURL_nil { BNCURLFilter *filter = [BNCURLFilter new]; - [filter updatePatternListWithCompletion:^ (NSError*error, NSArray*list) { - XCTAssertNil(error); - XCTAssertTrue(list.count > 0); - [expectation fulfill]; - }]; - [self awaitExpectations]; + NSURL *url = nil; + NSString *matchingRegex = [filter patternMatchingURL:url]; + XCTAssertNil(matchingRegex); +} + +- (void)testPatternMatchingURL_emptyString { + BNCURLFilter *filter = [BNCURLFilter new]; + NSURL *url = [NSURL URLWithString:@""]; + NSString *matchingRegex = [filter patternMatchingURL:url]; + XCTAssertNil(matchingRegex); +} + +- (void)testPatternMatchingURL_fbRegexMatches { + NSString *pattern = @"^fb\\d+:((?!campaign_ids).)*$"; + NSString *sampleURL = @"fb12345://"; + + BNCURLFilter *filter = [BNCURLFilter new]; + NSURL *url = [NSURL URLWithString:sampleURL]; + NSString *matchingRegex = [filter patternMatchingURL:url]; + XCTAssertTrue([pattern isEqualToString:matchingRegex]); +} + +- (void)testPatternMatchingURL_fbRegexDoesNotMatch { + NSString *pattern = @"^fb\\d+:((?!campaign_ids).)*$"; + NSString *sampleURL = @"fb12345://campaign_ids"; + + BNCURLFilter *filter = [BNCURLFilter new]; + NSURL *url = [NSURL URLWithString:sampleURL]; + NSString *matchingRegex = [filter patternMatchingURL:url]; + XCTAssertFalse([pattern isEqualToString:matchingRegex]); } - */ -- (NSArray*) badURLs { - NSArray *kBadURLs = @[ + +- (void)testIgnoredSuspectedAuthURLs { + NSArray *urls = @[ @"fb123456:login/464646", - @"twitterkit-.4545:", @"shsh:oauth/login", @"https://myapp.app.link/oauth_token=fred", @"https://myapp.app.link/auth_token=fred", @"https://myapp.app.link/authtoken=fred", @"https://myapp.app.link/auth=fred", - @"fb1234:", - @"fb1234:/", - @"fb1234:/this-is-some-extra-info/?whatever", - @"fb1234:/this-is-some-extra-info/?whatever:andstuff", @"myscheme:path/to/resource?oauth=747474", @"myscheme:oauth=747474", @"myscheme:/oauth=747474", @"myscheme://oauth=747474", @"myscheme://path/oauth=747474", @"myscheme://path/:oauth=747474", - @"https://google.com/userprofile/devonbanks=oauth?", + @"https://google.com/userprofile/devonbanks=oauth?" ]; - return kBadURLs; + + BNCURLFilter *filter = [BNCURLFilter new]; + for (NSString *string in urls) { + NSURL *URL = [NSURL URLWithString:string]; + XCTAssertTrue([filter shouldIgnoreURL:URL], @"Checking '%@'.", URL); + } } -- (NSArray*) goodURLs { - NSArray *kGoodURLs = @[ +- (void)testAllowedURLsSimilarToAuthURLs { + NSArray *urls = @[ @"shshs:/content/path", @"shshs:content/path", @"https://myapp.app.link/12345/link", - @"fb123x:/", @"https://myapp.app.link?authentic=true&tokemonsta=false", - @"myscheme://path/brauth=747474", + @"myscheme://path/brauth=747474" ]; - return kGoodURLs; -} - -- (void)testBadURLs { - // Test default list. + BNCURLFilter *filter = [BNCURLFilter new]; - for (NSString *string in self.badURLs) { + for (NSString *string in urls) { NSURL *URL = [NSURL URLWithString:string]; - XCTAssertTrue([filter shouldIgnoreURL:URL], @"Checking '%@'.", URL); + XCTAssertFalse([filter shouldIgnoreURL:URL], @"Checking '%@'", URL); } } -- (void) testDownloadBadURLs { - // Test download list. - XCTestExpectation *expectation = [self expectationWithDescription:@"List Download"]; +- (void)testIgnoredFacebookURLs { + // Most FB URIs are ignored + NSArray *urls = @[ + @"fb123456://login/464646", + @"fb1234:", + @"fb1234:/", + @"fb1234:/this-is-some-extra-info/?whatever", + @"fb1234:/this-is-some-extra-info/?whatever:andstuff" + ]; + BNCURLFilter *filter = [BNCURLFilter new]; - filter.jsonURL = [NSURL URLWithString:@"https://cdn.branch.io/sdk/uriskiplist_tv1.json"]; - [filter updatePatternListWithCompletion:^ (NSError*error, NSArray*list) { - XCTAssertNil(error); - XCTAssertTrue(list.count == 7); - [expectation fulfill]; - }]; - [self awaitExpectations]; - for (NSString *string in self.badURLs) { + for (NSString *string in urls) { NSURL *URL = [NSURL URLWithString:string]; XCTAssertTrue([filter shouldIgnoreURL:URL], @"Checking '%@'.", URL); } } -- (void)testGoodURLs { - // Test default list. +- (void)testAllowedFacebookURLs { + NSArray *urls = @[ + // Facebook URIs do not contain letters other than an fb prefix + @"fb123x://", + // FB URIs with campaign ids are allowed + @"fb1234://helloworld?al_applink_data=%7B%22target_url%22%3A%22http%3A%5C%2F%5C%2Fitunes.apple.com%5C%2Fapp%5C%2Fid880047117%22%2C%22extras%22%3A%7B%22fb_app_id%22%3A2020399148181142%7D%2C%22referer_app_link%22%3A%7B%22url%22%3A%22fb%3A%5C%2F%5C%2F%5C%2F%3Fapp_id%3D2020399148181142%22%2C%22app_name%22%3A%22Facebook%22%7D%2C%22acs_token%22%3A%22debuggingtoken%22%2C%22campaign_ids%22%3A%22ARFUlbyOurYrHT2DsknR7VksCSgN4tiH8TzG8RIvVoUQoYog5bVCvADGJil5kFQC6tQm-fFJQH0w8wCi3NbOmEHHrtgCNglkXNY-bECEL0aUhj908hIxnBB0tchJCqwxHjorOUqyk2v4bTF75PyWvxOksZ6uTzBmr7wJq8XnOav0bA%22%2C%22test_deeplink%22%3A1%7D" + ]; + BNCURLFilter *filter = [BNCURLFilter new]; - for (NSString *string in self.goodURLs) { + for (NSString *string in urls) { NSURL *URL = [NSURL URLWithString:string]; XCTAssertFalse([filter shouldIgnoreURL:URL], @"Checking '%@'", URL); } } -- (void) testDownloadGoodURLs { - // Test download list. - XCTestExpectation *expectation = [self expectationWithDescription:@"List Download"]; +- (void)testCustomPatternList { BNCURLFilter *filter = [BNCURLFilter new]; - filter.jsonURL = [NSURL URLWithString:@"https://cdn.branch.io/sdk/uriskiplist_tv1.json"]; - [filter updatePatternListWithCompletion:^ (NSError*error, NSArray*list) { - XCTAssertNil(error); - XCTAssertTrue(list.count == 7); - [expectation fulfill]; - }]; - [self awaitExpectations]; - for (NSString *string in self.goodURLs) { - NSURL *URL = [NSURL URLWithString:string]; - XCTAssertFalse([filter shouldIgnoreURL:URL], @"Checking '%@'.", URL); - } + + // sanity check default pattern list + XCTAssertTrue([filter shouldIgnoreURL:[NSURL URLWithString:@"fb123://"]]); + XCTAssertFalse([filter shouldIgnoreURL:[NSURL URLWithString:@"branch123://"]]); + + // confirm new pattern list is enforced + [filter useCustomPatternList:@[@"^branch\\d+:"]]; + XCTAssertFalse([filter shouldIgnoreURL:[NSURL URLWithString:@"fb123://"]]); + XCTAssertTrue([filter shouldIgnoreURL:[NSURL URLWithString:@"branch123://"]]); } -- (void) testStandardList { - BNCLogSetDisplayLevel(BNCLogLevelAll); - Branch *branch = (Branch.branchKey.length) ? Branch.getInstance : [Branch getInstance:@"key_live_foo"]; - id serverInterfaceMock = OCMPartialMock(branch.serverInterface); - XCTestExpectation *expectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - - OCMStub( - [serverInterfaceMock postRequest:[OCMArg any] - url:[OCMArg any] - key:[OCMArg any] - callback:[OCMArg any]] - ).andDo(^(NSInvocation *invocation) { - __unsafe_unretained NSDictionary *dictionary = nil; - __unsafe_unretained NSString *url = nil; - [invocation getArgument:&dictionary atIndex:2]; - [invocation getArgument:&url atIndex:3]; - - NSLog(@"d: %@", dictionary); - NSString* link = dictionary[@"external_intent_uri"]; - NSString *pattern1 = @"^(?i)((http|https):\\/\\/).*[\\/|?|#].*\\b(password|o?auth|o?auth.?token|access|access.?token)\\b"; - NSString *pattern2 = @"^(?i).+:.*[?].*\\b(password|o?auth|o?auth.?token|access|access.?token)\\b"; - NSLog(@"\n Link: '%@'\nPattern1: '%@'\nPattern2: '%@'.", link, pattern1, pattern2); - if ([link isEqualToString:pattern1] || [link isEqualToString:pattern2]) { - [expectation fulfill]; - } - else - if ([url containsString:@"install"]) { - [expectation fulfill]; - } - }); - [branch clearNetworkQueue]; - [branch handleDeepLink:[NSURL URLWithString:@"https://myapp.app.link/bob/link?oauth=true"]]; - [self waitForExpectationsWithTimeout:5.0 handler:nil]; - [serverInterfaceMock stopMocking]; - [BNCPreferenceHelper sharedInstance].referringURL = nil; - [[BNCPreferenceHelper sharedInstance] synchronize]; +// This test relies on the fact the test host saves the pattern list to disk +- (void)testSavedPatternList { + BNCURLFilter *filter = [BNCURLFilter new]; + + // confirm new pattern list is enforced + [filter useCustomPatternList:@[@"^branch\\d+:"]]; + XCTAssertFalse([filter shouldIgnoreURL:[NSURL URLWithString:@"fb123://"]]); + XCTAssertTrue([filter shouldIgnoreURL:[NSURL URLWithString:@"branch123://"]]); + + [filter useSavedPatternList]; + + // the saved list should match default pattern list + XCTAssertTrue([filter shouldIgnoreURL:[NSURL URLWithString:@"fb123://"]]); + XCTAssertFalse([filter shouldIgnoreURL:[NSURL URLWithString:@"branch123://"]]); } -- (void) testUserList { - BNCLogSetDisplayLevel(BNCLogLevelAll); - Branch *branch = (Branch.branchKey.length) ? Branch.getInstance : [Branch getInstance:@"key_live_foo"]; - [branch clearNetworkQueue]; - branch.urlPatternsToIgnore = @[ - @"\\/bob\\/" - ]; - id serverInterfaceMock = OCMPartialMock(branch.serverInterface); - XCTestExpectation *expectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - - OCMStub( - [serverInterfaceMock postRequest:[OCMArg any] - url:[OCMArg any] - key:[OCMArg any] - callback:[OCMArg any]] - ).andDo(^(NSInvocation *invocation) { - __unsafe_unretained NSDictionary *dictionary = nil; - __unsafe_unretained NSString *URL = nil; - [invocation getArgument:&dictionary atIndex:2]; - [invocation getArgument:&URL atIndex:3]; - - NSString* link = dictionary[@"external_intent_uri"]; - NSString *pattern = @"\\/bob\\/"; - NSLog(@"\n URL: '%@'\n Link: '%@'\nPattern: '%@'\n.", URL, link, pattern); - if ([link isEqualToString:pattern]) { - [expectation fulfill]; - } - else - if ([URL containsString:@"install"]) { - [expectation fulfill]; - } - }); - [branch handleDeepLink:[NSURL URLWithString:@"https://myapp.app.link/bob/link"]]; - [self waitForExpectationsWithTimeout:5.0 handler:nil]; - [serverInterfaceMock stopMocking]; - [BNCPreferenceHelper sharedInstance].referringURL = nil; - [[BNCPreferenceHelper sharedInstance] synchronize]; +// This is an end to end test and relies on a server call +- (void)testUpdatePatternListFromServer { + BNCURLFilter *filter = [BNCURLFilter new]; + + // confirm new pattern list is enforced + [filter useCustomPatternList:@[@"^branch\\d+:"]]; + XCTAssertFalse([filter shouldIgnoreURL:[NSURL URLWithString:@"fb123://"]]); + XCTAssertTrue([filter shouldIgnoreURL:[NSURL URLWithString:@"branch123://"]]); + + __block XCTestExpectation *expectation = [self expectationWithDescription:@"List updated"]; + [filter updatePatternListFromServerWithCompletion:^{ + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:5.0 handler:^(NSError * _Nullable error) { }]; + + // the retrieved list should match default pattern list + XCTAssertTrue([filter shouldIgnoreURL:[NSURL URLWithString:@"fb123://"]]); + XCTAssertFalse([filter shouldIgnoreURL:[NSURL URLWithString:@"branch123://"]]); } @end diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchDelegate.Test.m b/Branch-TestBed/Branch-SDK-Tests/BranchDelegate.Test.m deleted file mode 100644 index e7ad27734..000000000 --- a/Branch-TestBed/Branch-SDK-Tests/BranchDelegate.Test.m +++ /dev/null @@ -1,328 +0,0 @@ -// -// BranchDelegateTest.m -// Branch-SDK-Tests -// -// Created by edward on 11/3/17. -// Copyright © 2017 Branch, Inc. All rights reserved. -// - -#import "BNCTestCase.h" -#import "Branch.h" -#import "NSError+Branch.h" -#import "BNCEncodingUtils.h" - -@interface BranchDelegateTest : BNCTestCase -@property (assign, nonatomic) NSInteger notificationOrder; -@property (strong, nonatomic) XCTestExpectation *branchWillOpenURLExpectation; -@property (strong, nonatomic) XCTestExpectation *branchWillOpenURLNotificationExpectation; -@property (strong, nonatomic) XCTestExpectation *branchDidOpenURLExpectation; -@property (strong, nonatomic) XCTestExpectation *branchDidOpenURLNotificationExpectation; -@property (strong, nonatomic) NSDictionary *deepLinkParams; -@property (assign, nonatomic) BOOL expectFailure; -@end - -#pragma mark - BranchDelegateTest - -@implementation BranchDelegateTest - -// Test that Branch notifications work. -// Test that they 1) work and 2) are sent in the right order. -//- (void) testNotificationsSuccess { -// -// self.expectFailure = NO; -// self.notificationOrder = 0; -// -// [[NSNotificationCenter defaultCenter] -// addObserver:self -// selector:@selector(branchWillStartSessionNotification:) -// name:BranchWillStartSessionNotification -// object:nil]; -// -// [[NSNotificationCenter defaultCenter] -// addObserver:self -// selector:@selector(branchDidStartSessionNotification:) -// name:BranchDidStartSessionNotification -// object:nil]; -// -// id serverInterfaceMock = OCMClassMock([BNCServerInterface class]); -// -// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; -// Branch.branchKey = @"key_live_foo"; -// -// Branch *branch = -// [[Branch alloc] -// initWithInterface:serverInterfaceMock -// queue:[[BNCServerRequestQueue alloc] init] -// cache:[[BNCLinkCache alloc] init] -// preferenceHelper:preferenceHelper -// key:@"key_live_foo"]; -// branch.delegate = self; -// -// BNCServerResponse *openInstallResponse = [[BNCServerResponse alloc] init]; -// openInstallResponse.data = @{ -// @"data": @"{\"$og_title\":\"Content Title\",\"$randomized_bundle_token\":\"423237095633725879\",\"~feature\":\"Sharing Feature\",\"$desktop_url\":\"http://branch.io\",\"$canonical_identifier\":\"item/12345\",\"~id\":423243086454504450,\"~campaign\":\"some campaign\",\"+is_first_session\":false,\"~channel\":\"Distribution Channel\",\"$ios_url\":\"https://dev.branch.io/getting-started/sdk-integration-guide/guide/ios/\",\"$exp_date\":0,\"$currency\":\"$\",\"$publicly_indexable\":1,\"$content_type\":\"some type\",\"~creation_source\":3,\"$amount\":1000,\"$og_description\":\"My Content Description\",\"+click_timestamp\":1506983962,\"$og_image_url\":\"https://pbs.twimg.com/profile_images/658759610220703744/IO1HUADP.png\",\"+match_guaranteed\":true,\"+clicked_branch_link\":true,\"deeplink_text\":\"This text was embedded as data in a Branch link with the following characteristics:\\n\\ncanonicalUrl: https://dev.branch.io/getting-started/deep-link-routing/guide/ios/\\n title: Content Title\\n contentDescription: My Content Description\\n imageUrl: https://pbs.twimg.com/profile_images/658759610220703744/IO1HUADP.png\\n\",\"$one_time_use\":false,\"$canonical_url\":\"https://dev.branch.io/getting-started/deep-link-routing/guide/ios/\",\"~referring_link\":\"https://bnctestbed.app.link/izPBY2xCqF\"}", -// @"randomized_device_token": @"439892172783867901", -// @"randomized_bundle_token": @"439892172804841307", -// @"link": @"https://bnctestbed.app.link?%24randomized_bundle_token=439892172804841307", -// @"session_id": @"443529761084512316", -// }; -// -// __block BNCServerCallback openOrInstallCallback; -// id openOrInstallCallbackCheckBlock = [OCMArg checkWithBlock:^BOOL(BNCServerCallback callback) { -// openOrInstallCallback = callback; -// return YES; -// }]; -// -// id openOrInstallInvocation = ^(NSInvocation *invocation) { -// openOrInstallCallback(openInstallResponse, nil); -// }; -// -// id openOrInstallUrlCheckBlock = [OCMArg checkWithBlock:^BOOL(NSString *url) { -// return [url rangeOfString:@"open"].location != NSNotFound || -// [url rangeOfString:@"install"].location != NSNotFound; -// }]; -// [[[serverInterfaceMock expect] -// andDo:openOrInstallInvocation] -// postRequest:[OCMArg any] -// url:openOrInstallUrlCheckBlock -// key:[OCMArg any] -// callback:openOrInstallCallbackCheckBlock]; -// -// preferenceHelper.universalLinkUrl = nil; -// preferenceHelper.externalIntentURI = nil; -// preferenceHelper.referringURL = nil; -// -// [branch clearNetworkQueue]; -// XCTestExpectation *openExpectation = [self expectationWithDescription:@"Test open"]; -// [branch initSessionWithLaunchOptions:@{} -// andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) { -// // Callback block. Order: 2. -// XCTAssertNil(error); -// XCTAssertEqualObjects(preferenceHelper.sessionID, @"443529761084512316"); -// XCTAssertTrue(self.notificationOrder == 2); -// self.notificationOrder++; -// self.deepLinkParams = params; -// [openExpectation fulfill]; -// } -// ]; -// -// [self waitForExpectationsWithTimeout:5.0 handler:NULL]; -// XCTAssertTrue(self.notificationOrder == 5); -// [[NSNotificationCenter defaultCenter] removeObserver:self]; -// branch.delegate = nil; -//} -// -//// Test that Branch notifications work with a failure. -//// Test that they 1) work and 2) are sent in the right order. -//- (void) testNotificationsFailure { -// -// self.expectFailure = YES; -// self.notificationOrder = 0; -// -// [[NSNotificationCenter defaultCenter] -// addObserver:self -// selector:@selector(branchWillStartSessionNotification:) -// name:BranchWillStartSessionNotification -// object:nil]; -// -// [[NSNotificationCenter defaultCenter] -// addObserver:self -// selector:@selector(branchDidStartSessionNotification:) -// name:BranchDidStartSessionNotification -// object:nil]; -// -// id serverInterfaceMock = OCMClassMock([BNCServerInterface class]); -// -// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; -// Branch.branchKey = @"key_live_foo"; -// -// Branch *branch = -// [[Branch alloc] -// initWithInterface:serverInterfaceMock -// queue:[[BNCServerRequestQueue alloc] init] -// cache:[[BNCLinkCache alloc] init] -// preferenceHelper:preferenceHelper -// key:@"key_live_foo"]; -// branch.delegate = self; -// -// BNCServerResponse *openInstallResponse = [[BNCServerResponse alloc] init]; -// openInstallResponse.data = @{ }; -// -// __block BNCServerCallback openOrInstallCallback; -// id openOrInstallCallbackCheckBlock = [OCMArg checkWithBlock:^BOOL(BNCServerCallback callback) { -// openOrInstallCallback = callback; -// return YES; -// }]; -// -// id openOrInstallInvocation = ^(NSInvocation *invocation) { -// NSError *error = [NSError branchErrorWithCode:BNCNetworkServiceInterfaceError]; -// openOrInstallCallback(openInstallResponse, error); -// }; -// -// id openOrInstallUrlCheckBlock = [OCMArg checkWithBlock:^BOOL(NSString *url) { -// return [url rangeOfString:@"open"].location != NSNotFound || -// [url rangeOfString:@"install"].location != NSNotFound; -// }]; -// -// [[[serverInterfaceMock expect] -// andDo:openOrInstallInvocation] -// postRequest:[OCMArg any] -// url:openOrInstallUrlCheckBlock -// key:[OCMArg any] -// callback:openOrInstallCallbackCheckBlock]; -// -// [branch clearNetworkQueue]; -// XCTestExpectation *openExpectation = [self expectationWithDescription:@"Test open"]; -// [branch initSessionWithLaunchOptions:@{} -// andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) { -// // Callback block. Order: 2. -// XCTAssertEqualObjects(params, @{}); -// XCTAssertNotNil(error); -// XCTAssertTrue(self.notificationOrder == 2); -// self.notificationOrder++; -// self.deepLinkParams = params; -// [openExpectation fulfill]; -// } -// ]; -// -// [self waitForExpectationsWithTimeout:5.0 handler:NULL]; -// XCTAssertTrue(self.notificationOrder == 5); -// [[NSNotificationCenter defaultCenter] removeObserver:self]; -// branch.delegate = nil; -//} - -#pragma mark - Delegate & Notification Methods - -// Delegate method. Order: 0. -- (void) branch:(Branch*)branch willStartSessionWithURL:(NSURL*)url { - XCTAssertTrue(self.notificationOrder == 0); - self.notificationOrder++; - [self.branchWillOpenURLExpectation fulfill]; -} - -// Notification method. Order: 1. -- (void) branchWillStartSessionNotification:(NSNotification*)notification { - XCTAssertTrue(self.notificationOrder == 1); - self.notificationOrder++; - - NSError *error = notification.userInfo[BranchErrorKey]; - XCTAssertNil(error); - - NSURL *URL = notification.userInfo[BranchURLKey]; - XCTAssertNil(URL); - - BranchUniversalObject *object = notification.userInfo[BranchUniversalObjectKey]; - XCTAssertNil(object); - - BranchLinkProperties *properties = notification.userInfo[BranchLinkPropertiesKey]; - XCTAssertNil(properties); - - [self.branchWillOpenURLNotificationExpectation fulfill]; -} - -// Delegate method. Order: 3. -- (void) branch:(Branch*)branch -didStartSessionWithURL:(NSURL*)url - branchLink:(BranchLink*)branchLink { - XCTAssertTrue([NSThread isMainThread]); - XCTAssertTrue(self.notificationOrder == 3); - self.notificationOrder++; - XCTAssertNotNil(branchLink.universalObject); - XCTAssertNotNil(branchLink.linkProperties); - if (self.expectFailure) - [NSException raise:NSInternalInconsistencyException format:@"Should return an error here."]; - [self.branchDidOpenURLExpectation fulfill]; -} - -// Delegate method. Order: 3 -- (void) branch:(Branch*)branch -failedToStartSessionWithURL:(NSURL*)url - error:(NSError*)error { - XCTAssertTrue([NSThread isMainThread]); - XCTAssertTrue(self.notificationOrder == 3); - self.notificationOrder++; - XCTAssertNotNil(error); - if (!self.expectFailure) - [NSException raise:NSInternalInconsistencyException format:@"Shouldn't return an error here."]; - [self.branchDidOpenURLExpectation fulfill]; -} - -// Notification method. Order: 4 -- (void) branchDidStartSessionNotification:(NSNotification*)notification { - XCTAssertTrue([NSThread isMainThread]); - XCTAssertTrue(self.notificationOrder == 4); - self.notificationOrder++; - - NSError *error = notification.userInfo[BranchErrorKey]; - NSURL *URL = notification.userInfo[BranchURLKey]; - BranchUniversalObject *object = notification.userInfo[BranchUniversalObjectKey]; - BranchLinkProperties *properties = notification.userInfo[BranchLinkPropertiesKey]; - - if (self.expectFailure) { - - XCTAssertNotNil(error); - XCTAssertNil(URL); - XCTAssertNil(object); - XCTAssertNil(properties); - - } else { - - XCTAssertNil(error); - XCTAssertNotNil(URL); - XCTAssertNotNil(object); - XCTAssertNotNil(properties); - - NSMutableDictionary *d = - [NSMutableDictionary dictionaryWithDictionary: - [object getDictionaryWithCompleteLinkProperties:properties]]; - NSMutableDictionary *truth = [NSMutableDictionary dictionaryWithDictionary:@{ - @"$amount": @1000, - @"$canonical_identifier": @"item/12345", - @"$canonical_url": @"https://dev.branch.io/getting-started/deep-link-routing/guide/ios/", - @"$content_type": @"some type", - @"$currency": @"$", - @"$desktop_url": @"http://branch.io", - @"$exp_date": @0, - @"$randomized_bundle_token": @"423237095633725879", - @"$ios_url": @"https://dev.branch.io/getting-started/sdk-integration-guide/guide/ios/", - @"$og_description": @"My Content Description", - @"$og_image_url": @"https://pbs.twimg.com/profile_images/658759610220703744/IO1HUADP.png", - @"$og_title": @"Content Title", - @"$one_time_use": @0, - @"$publicly_indexable": @1, - - @"+click_timestamp": @1506983962, - @"+clicked_branch_link": @1, - @"+is_first_session": @0, - @"+match_guaranteed": @1, - - @"deeplink_text": @"This text was embedded as data in a Branch link with the following characteristics:\n\ncanonicalUrl: https://dev.branch.io/getting-started/deep-link-routing/guide/ios/\n title: Content Title\n contentDescription: My Content Description\n imageUrl: https://pbs.twimg.com/profile_images/658759610220703744/IO1HUADP.png\n", - - @"~campaign": @"some campaign", - @"~channel": @"Distribution Channel", - @"~creation_source": @3, - @"~duration": @0, - @"~feature": @"Sharing Feature", - @"~id": @423243086454504450, - @"~referring_link": @"https://bnctestbed.app.link/izPBY2xCqF" - }]; - - XCTAssertTrue(d.count == truth.count); - XCTAssertTrue(!d || [d isEqualToDictionary:truth]); - } - - [self.branchDidOpenURLNotificationExpectation fulfill]; -} - -- (void)setUp { - self.branchWillOpenURLExpectation = - [self expectationWithDescription:@"branchWillOpenURLExpectation"]; - self.branchWillOpenURLNotificationExpectation = - [self expectationWithDescription:@"branchWillOpenURLNotificationExpectation"]; - self.branchDidOpenURLExpectation = - [self expectationWithDescription:@"branchDidOpenURLExpectation"]; - self.branchDidOpenURLNotificationExpectation = - [self expectationWithDescription:@"branchDidOpenURLNotificationExpectation"]; -} - -@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchInstallRequestTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchInstallRequestTests.m index 9b4cf8990..b46ffefae 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchInstallRequestTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchInstallRequestTests.m @@ -15,304 +15,304 @@ #import "BNCSystemObserver.h" #import "BranchConstants.h" #import "BNCEncodingUtils.h" -#import - -@interface BranchInstallRequestTests : BNCTestCase -@end - -@implementation BranchInstallRequestTests - -- (void)setUp { - [super setUp]; - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - preferenceHelper.installParams = nil; - preferenceHelper.randomizedBundleToken = nil; - [preferenceHelper saveContentAnalyticsManifest:nil]; - [preferenceHelper synchronize]; -} - -- (void)testSuccessWithAllKeysAndIsReferrable { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const SESSION_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; - NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_SESSION_DATA: SESSION_PARAMS, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN - }; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - }]; - - [Branch setBranchKey:@"key_live_foo"]; - [request processResponse:response error:nil]; - [self awaitExpectations]; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.sessionParams, SESSION_PARAMS); - XCTAssertEqualObjects(preferenceHelper.installParams, SESSION_PARAMS); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); - XCTAssertNil(preferenceHelper.linkClickIdentifier); -} - -- (void)testSuccessWithAllKeysAndIsNotReferrable { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const SESSION_PARAMS = @"{\"foo\":\"bar\"}"; - NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; - NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_SESSION_DATA: SESSION_PARAMS, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - preferenceHelper.installParams = INSTALL_PARAMS; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - }]; - - [Branch setBranchKey:@"key_live_foo"]; - [request processResponse:response error:nil]; - - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.sessionParams, SESSION_PARAMS); - XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); - XCTAssertNil(preferenceHelper.linkClickIdentifier); -} - -- (void)testSuccessWithNoSessionParamsAndIsNotReferrable { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; - NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - preferenceHelper.installParams = INSTALL_PARAMS; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - }]; - - [Branch setBranchKey:@"key_live_foo"]; - [request processResponse:response error:nil]; - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); - XCTAssertNil(preferenceHelper.sessionParams); - XCTAssertNil(preferenceHelper.linkClickIdentifier); -} - -- (void)testSuccessWithNoSessionParamsAndIsReferrableAndAllowToBeClearIsNotSet { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; - NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - preferenceHelper.installParams = INSTALL_PARAMS; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - }]; - - [Branch setBranchKey:@"key_live_foo"]; - [request processResponse:response error:nil]; - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); - XCTAssertNil(preferenceHelper.sessionParams); - XCTAssertNil(preferenceHelper.linkClickIdentifier); -} - -- (void)testSuccessWithNoSessionParamsAndIsReferrableAndAllowToBeClearIsSet { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN - }; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - } isInstall:YES]; - - [Branch setBranchKey:@"key_live_foo"]; - [request processResponse:response error:nil]; - [self awaitExpectations]; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); - XCTAssertNil(preferenceHelper.sessionParams); - XCTAssertNil(preferenceHelper.linkClickIdentifier); - XCTAssertNil(preferenceHelper.installParams); -} - -- (void)testInstallWhenReferrableAndNullData { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"ReferrableInstall"]; - BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssertNil(preferenceHelper.installParams); - [self safelyFulfillExpectation:expectation]; - }]; - - [Branch setBranchKey:@"key_live_foo"]; - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{}; - [request processResponse:response error:nil]; - [self awaitExpectations]; -} - -- (void)testInstallWhenReferrableAndNonNullData { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - NSString * const INSTALL_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; - - XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; - BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); - - [self safelyFulfillExpectation:expectation]; - }]; - - [Branch setBranchKey:@"key_live_foo"]; - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: INSTALL_PARAMS }; - [request processResponse:response error:nil]; - [self awaitExpectations]; -} - -- (void)testInstallWhenReferrableAndNoInstallParamsAndNonLinkClickData { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":0}"; - - XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; - BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssertNil(preferenceHelper.installParams); - - [self safelyFulfillExpectation:expectation]; - }]; - - [Branch setBranchKey:@"key_live_foo"]; - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; - [request processResponse:response error:nil]; - [self awaitExpectations]; -} - -- (void)testInstallWhenNotReferrable { - // 'isReferrable' seems to be an empty concept in iOS. - // It is in the code but not used. -- Edward. - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - NSString * const INSTALL_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; - - XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; - BranchInstallRequest *request = - [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssert([preferenceHelper.installParams isEqualToString:INSTALL_PARAMS]); - [self safelyFulfillExpectation:expectation]; - }]; - - [Branch setBranchKey:@"key_live_foo"]; - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: INSTALL_PARAMS }; - [request processResponse:response error:nil]; - - [self awaitExpectations]; -} - -@end +//#import +// +//@interface BranchInstallRequestTests : BNCTestCase +//@end +// +//@implementation BranchInstallRequestTests +// +//- (void)setUp { +// [super setUp]; +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// preferenceHelper.installParams = nil; +// preferenceHelper.randomizedBundleToken = nil; +// [preferenceHelper saveContentAnalyticsManifest:nil]; +// [preferenceHelper synchronize]; +//} +// +//- (void)testSuccessWithAllKeysAndIsReferrable { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const SESSION_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; +// NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_SESSION_DATA: SESSION_PARAMS, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN +// }; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// }]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// [request processResponse:response error:nil]; +// [self awaitExpectations]; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionParams, SESSION_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.installParams, SESSION_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +//} +// +//- (void)testSuccessWithAllKeysAndIsNotReferrable { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const SESSION_PARAMS = @"{\"foo\":\"bar\"}"; +// NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; +// NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_SESSION_DATA: SESSION_PARAMS, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// preferenceHelper.installParams = INSTALL_PARAMS; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// }]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionParams, SESSION_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +//} +// +//- (void)testSuccessWithNoSessionParamsAndIsNotReferrable { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; +// NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// preferenceHelper.installParams = INSTALL_PARAMS; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// }]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// [request processResponse:response error:nil]; +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); +// XCTAssertNil(preferenceHelper.sessionParams); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +//} +// +//- (void)testSuccessWithNoSessionParamsAndIsReferrableAndAllowToBeClearIsNotSet { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; +// NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// preferenceHelper.installParams = INSTALL_PARAMS; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// }]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// [request processResponse:response error:nil]; +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); +// XCTAssertNil(preferenceHelper.sessionParams); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +//} +// +//- (void)testSuccessWithNoSessionParamsAndIsReferrableAndAllowToBeClearIsSet { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const RANDOMIZED_BUNDLE_TOKEN = @"randomized_bundle_token"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN +// }; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// } isInstall:YES]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// [request processResponse:response error:nil]; +// [self awaitExpectations]; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); +// XCTAssertNil(preferenceHelper.sessionParams); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +// XCTAssertNil(preferenceHelper.installParams); +//} +// +//- (void)testInstallWhenReferrableAndNullData { +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"ReferrableInstall"]; +// BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssertNil(preferenceHelper.installParams); +// [self safelyFulfillExpectation:expectation]; +// }]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{}; +// [request processResponse:response error:nil]; +// [self awaitExpectations]; +//} +// +//- (void)testInstallWhenReferrableAndNonNullData { +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// NSString * const INSTALL_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; +// BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); +// +// [self safelyFulfillExpectation:expectation]; +// }]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: INSTALL_PARAMS }; +// [request processResponse:response error:nil]; +// [self awaitExpectations]; +//} +// +//- (void)testInstallWhenReferrableAndNoInstallParamsAndNonLinkClickData { +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":0}"; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; +// BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssertNil(preferenceHelper.installParams); +// +// [self safelyFulfillExpectation:expectation]; +// }]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; +// [request processResponse:response error:nil]; +// [self awaitExpectations]; +//} +// +//- (void)testInstallWhenNotReferrable { +// // 'isReferrable' seems to be an empty concept in iOS. +// // It is in the code but not used. -- Edward. +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// NSString * const INSTALL_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; +// BranchInstallRequest *request = +// [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssert([preferenceHelper.installParams isEqualToString:INSTALL_PARAMS]); +// [self safelyFulfillExpectation:expectation]; +// }]; +// +// [Branch setBranchKey:@"key_live_foo"]; +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: INSTALL_PARAMS }; +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +//} +// +//@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchNetworkScenario.Test.m b/Branch-TestBed/Branch-SDK-Tests/BranchNetworkScenario.Test.m deleted file mode 100644 index b635f95dd..000000000 --- a/Branch-TestBed/Branch-SDK-Tests/BranchNetworkScenario.Test.m +++ /dev/null @@ -1,176 +0,0 @@ -// -// BranchNetworkScenarioTests.m -// Branch-TestBed -// -// Created by Graham Mueller on 4/20/15. -// Copyright (c) 2015 Branch Metrics. All rights reserved. -// - - -#import -#import "BNCTestCase.h" -#import "Branch.h" -#import "BNCServerRequestQueue.h" -#import "BNCPreferenceHelper.h" -#import "NSError+Branch.h" -#import "BranchOpenRequest.h" - - -@interface Branch (Testing) -@property (strong, nonatomic) BNCServerInterface *serverInterface; -@property (assign, nonatomic) NSInteger networkCount; -@end - - -@interface BranchNetworkScenarioTests : BNCTestCase -@property (assign, nonatomic) BOOL hasExceededExpectations; -@end - - -@implementation BranchNetworkScenarioTests - -#pragma mark - Scenario 8 -// Somehow, betweeen initSession and the next call, all preference items are cleared. -// Shouldn't crash in this case, but can't do much besides "you need to re-init" -- (void)testScenario8 { - sleep(1); - BNCPreferenceHelper *preferenceHelper = [[BNCPreferenceHelper alloc] init]; - id serverInterfaceMock = OCMClassMock([BNCServerInterface class]); - - Branch *branch = - [[Branch alloc] - initWithInterface:serverInterfaceMock - queue:[[BNCServerRequestQueue alloc] init] - cache:[[BNCLinkCache alloc] init] - preferenceHelper:preferenceHelper - key:@"key_live"]; - - XCTestExpectation *expecation = [self expectationWithDescription:@"Scenario8 Expectation"]; - [self initSessionExpectingSuccess:branch serverInterface:serverInterfaceMock callback:^{ - preferenceHelper.sessionID = nil; - preferenceHelper.randomizedDeviceToken = nil; - - [branch getShortURLWithCallback:^(NSString *url, NSError *error) { - XCTAssertNotNil(error); - XCTAssertEqual(error.code, BNCInitError); - [self safelyFulfillExpectation:expecation]; - }]; - }]; - - [self awaitExpectations]; -} - -#pragma mark - Internals - -- (void)initSessionExpectingSuccess:(Branch *)branch - serverInterface:(id)serverInterfaceMock - callback:(void (^)(void))callback { - [self mockSuccesfulInit:serverInterfaceMock]; - [branch initSessionWithLaunchOptions:@{} - andRegisterDeepLinkHandler:[self callbackExpectingSuccess:callback]]; -} - -- (void)initSessionExpectingFailure:(Branch *)branch - serverInterface:(id)serverInterfaceMock - callback:(void (^)(void))callback { - __block BNCServerCallback openOrInstallCallback; - id openOrInstallCallbackCheckBlock = [OCMArg checkWithBlock:^BOOL(BNCServerCallback callback) { - openOrInstallCallback = callback; - return YES; - }]; - - id openOrInstallInvocation = ^(NSInvocation *invocation) { - openOrInstallCallback(nil, [NSError errorWithDomain:NSURLErrorDomain code:-1004 userInfo:nil]); - }; - - id openOrInstallUrlCheckBlock = [OCMArg checkWithBlock:^BOOL(NSString *url) { - return [url rangeOfString:@"open"].location != NSNotFound || [url rangeOfString:@"install"].location != NSNotFound; - }]; - - [[[serverInterfaceMock stub] - andDo:openOrInstallInvocation] - postRequest:[OCMArg any] - url:openOrInstallUrlCheckBlock - key:[OCMArg any] - callback:openOrInstallCallbackCheckBlock]; - - [branch initSessionWithLaunchOptions:@{} andRegisterDeepLinkHandler:[self callbackExpectingFailure:callback]]; -} - - -#pragma mark - Callbacks - -- (callbackWithParams)callbackExpectingSuccess:(void (^)(void))callback { - __block BOOL initCalled = NO; - return ^(NSDictionary *params, NSError *error) { - XCTAssertNil(error); - if (!initCalled && callback) { - initCalled = YES; - callback(); - } - }; -} - -- (callbackWithParams)callbackExpectingFailure:(void (^)(void))callback { - __block BOOL initCalled = NO; - return ^(NSDictionary *params, NSError *error) { - XCTAssertNotNil(error); - - if (!initCalled && callback) { - initCalled = YES; - callback(); - } - }; -} - -#pragma mark - Init mocking - -- (void)mockSuccesfulInit:(id)serverInterfaceMock { - BNCServerResponse *openInstallResponse = [[BNCServerResponse alloc] init]; - openInstallResponse.data = @{ - @"session_id": @"11111", - @"randomized_bundle_token": @"22222", - @"randomized_device_token": @"ae5adt6lkj08", - @"link": @"https://bnc.lt/i/11111" - }; - - __block BNCServerCallback openOrInstallCallback; - id openOrInstallCallbackCheckBlock = [OCMArg checkWithBlock:^BOOL(BNCServerCallback callback) { - openOrInstallCallback = callback; - return YES; - }]; - - id openOrInstallInvocation = ^(NSInvocation *invocation) { - openOrInstallCallback(openInstallResponse, nil); - }; - - id openOrInstallUrlCheckBlock = [OCMArg checkWithBlock:^BOOL(NSString *url) { - return [url rangeOfString:@"open"].location != NSNotFound || - [url rangeOfString:@"install"].location != NSNotFound; - }]; - - [[[serverInterfaceMock stub] - andDo:openOrInstallInvocation] - postRequest:[OCMArg any] - url:openOrInstallUrlCheckBlock - key:[OCMArg any] - callback:openOrInstallCallbackCheckBlock]; -} - -- (void)safelyFulfillExpectation:(XCTestExpectation *)expectation { - if (!self.hasExceededExpectations) { - [expectation fulfill]; - } -} - -- (void)awaitExpectations { - NSTimeInterval timeoutInterval = 5.0; - if ([UIDevice currentDevice].systemVersion.floatValue < 9.0) { - timeoutInterval = 10.0; - } - [self waitForExpectationsWithTimeout:timeoutInterval handler:^(NSError *error) { - self.hasExceededExpectations = YES; - }]; -} - -@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchOpenRequestTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchOpenRequestTests.m index b5059db9d..772f8b624 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchOpenRequestTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchOpenRequestTests.m @@ -13,379 +13,379 @@ #import "BranchOpenRequest.h" #import "BranchConstants.h" #import "BNCPreferenceHelper.h" -#import #import "BNCPreferenceHelper.h" #import "BNCEncodingUtils.h" #import "BNCSystemObserver.h" - -@interface BranchOpenRequestTests : BNCTestCase -@end - -@implementation BranchOpenRequestTests - -- (void)setUp { - [super setUp]; - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - preferenceHelper.installParams = nil; - preferenceHelper.randomizedBundleToken = nil; - [preferenceHelper saveContentAnalyticsManifest:nil]; - [preferenceHelper synchronize]; -} - -- (void)testSuccessWithAllKeysAndIsReferrable { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const SESSION_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; - NSString * const RANDOMIZED_BUNDLE_TOKEN = @"branch-id"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_SESSION_DATA: SESSION_PARAMS, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - } isInstall:TRUE]; - - [request processResponse:response error:nil]; - - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.sessionParams, SESSION_PARAMS); - XCTAssertEqualObjects(preferenceHelper.installParams, SESSION_PARAMS); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); - XCTAssertNil(preferenceHelper.linkClickIdentifier); -} - -- (void)testSuccessWithAllKeysAndIsNotReferrable { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const SESSION_PARAMS = @"{\"foo\":\"bar\"}"; - NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; - NSString * const IDENTITY = @"branch-id"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_SESSION_DATA: SESSION_PARAMS, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - preferenceHelper.installParams = INSTALL_PARAMS; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - }]; - - [request processResponse:response error:nil]; - - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.sessionParams, SESSION_PARAMS); - XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); - XCTAssertNil(preferenceHelper.linkClickIdentifier); -} - -- (void)testSuccessWithNoSessionParamsAndIsNotReferrable { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; - NSString * const IDENTITY = @"branch-id"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - preferenceHelper.installParams = INSTALL_PARAMS; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - }]; - - [request processResponse:response error:nil]; - - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); - XCTAssertNil(preferenceHelper.sessionParams); - XCTAssertNil(preferenceHelper.linkClickIdentifier); -} - -- (void)testSuccessWithNoSessionParamsAndIsReferrableAndAllowToBeClearIsNotSet { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; - NSString * const IDENTITY = @"branch-id"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - preferenceHelper.installParams = INSTALL_PARAMS; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - }]; - - [request processResponse:response error:nil]; - - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); - XCTAssertNil(preferenceHelper.sessionParams); - XCTAssertNil(preferenceHelper.linkClickIdentifier); -} - -- (void)testSuccessWithNoSessionParamsAndIsReferrableAndAllowToBeClearIsSet { - NSString * const DEVICE_TOKEN = @"foo-token"; - NSString * const USER_URL = @"http://foo"; - NSString * const DEVELOPER_ID = @"foo"; - NSString * const SESSION_ID = @"foo-session"; - NSString * const IDENTITY = @"branch-id"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - } isInstall:NO]; - - [request processResponse:response error:nil]; - - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); - XCTAssertNil(preferenceHelper.sessionParams); - XCTAssertNil(preferenceHelper.linkClickIdentifier); - XCTAssertNil(preferenceHelper.installParams); -} - -- (void)testOpenWhenReferrableAndNoInstallParamsAndNonNullData { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; - - XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssertEqualObjects(preferenceHelper.installParams, OPEN_PARAMS); - - [self safelyFulfillExpectation:expectation]; - } isInstall:TRUE]; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; - [request processResponse:response error:nil]; - - [self awaitExpectations]; -} - -- (void)testOpenWhenReferrableAndNoInstallParamsAndNullData { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssertNil(preferenceHelper.installParams); - - [self safelyFulfillExpectation:expectation]; - }]; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ }; - [request processResponse:response error:nil]; - - [self awaitExpectations]; -} - -- (void)testOpenWhenReferrableAndNoInstallParamsAndNonLinkClickData { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":0}"; - - XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssertNil(preferenceHelper.installParams); - - [self safelyFulfillExpectation:expectation]; - }]; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; - [request processResponse:response error:nil]; - - [self awaitExpectations]; -} - -- (void)testOpenWhenReferrableAndInstallParams { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - NSString * const INSTALL_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; - NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":1,\"bar\":\"foo\"}"; - - preferenceHelper.installParams = INSTALL_PARAMS; - - XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); - - [self safelyFulfillExpectation:expectation]; - }]; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; - [request processResponse:response error:nil]; - - [self awaitExpectations]; -} - -- (void)testOpenWhenNotReferrable { - // 'isReferrable' seems to be an empty concept in iOS. - // It is in the code but not used. -- Edward. - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; - - XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { - XCTAssertNil(error); - XCTAssert([preferenceHelper.installParams isEqualToString:OPEN_PARAMS]); - [self safelyFulfillExpectation:expectation]; - } isInstall:TRUE]; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; - [request processResponse:response error:nil]; - - [self awaitExpectations]; -} - -- (void)testEmptyResponseFields { - NSString * DEVICE_TOKEN = @"foo-token"; - NSString * USER_URL = @"http://foo"; - NSString * DEVELOPER_ID = @"foo"; - NSString * SESSION_ID = @"foo-session"; - NSString * IDENTITY = @"branch-id"; - - BNCServerResponse *response = [[BNCServerResponse alloc] init]; - response.data = @{ - BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, - BRANCH_RESPONSE_KEY_USER_URL: USER_URL, - BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, - BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, - BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY - }; - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; - BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { - XCTAssertNil(error); - XCTAssertTrue(success); - [self safelyFulfillExpectation:openExpectation]; - } isInstall:NO]; - - [request processResponse:response error:nil]; - - [self awaitExpectations]; - - XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); - XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); - XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); - XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); - XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); - XCTAssertNil(preferenceHelper.sessionParams); - XCTAssertNil(preferenceHelper.linkClickIdentifier); - XCTAssertNil(preferenceHelper.installParams); - - // Now call processResponse with empty fields again. - response.data = @{}; - [request processResponse:response error:nil]; - - XCTAssertNotNil(preferenceHelper.randomizedDeviceToken); - XCTAssertNotNil(preferenceHelper.userUrl); - XCTAssertNotNil(preferenceHelper.sessionID); - XCTAssertNotNil(preferenceHelper.randomizedBundleToken); -} - -@end +//#import +// +//@interface BranchOpenRequestTests : BNCTestCase +//@end +// +//@implementation BranchOpenRequestTests +// +//- (void)setUp { +// [super setUp]; +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// preferenceHelper.installParams = nil; +// preferenceHelper.randomizedBundleToken = nil; +// [preferenceHelper saveContentAnalyticsManifest:nil]; +// [preferenceHelper synchronize]; +//} +// +//- (void)testSuccessWithAllKeysAndIsReferrable { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const SESSION_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; +// NSString * const RANDOMIZED_BUNDLE_TOKEN = @"branch-id"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_SESSION_DATA: SESSION_PARAMS, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: RANDOMIZED_BUNDLE_TOKEN +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// } isInstall:TRUE]; +// +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionParams, SESSION_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.installParams, SESSION_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, RANDOMIZED_BUNDLE_TOKEN); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +//} +// +//- (void)testSuccessWithAllKeysAndIsNotReferrable { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const SESSION_PARAMS = @"{\"foo\":\"bar\"}"; +// NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; +// NSString * const IDENTITY = @"branch-id"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_SESSION_DATA: SESSION_PARAMS, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// preferenceHelper.installParams = INSTALL_PARAMS; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// }]; +// +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionParams, SESSION_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +//} +// +//- (void)testSuccessWithNoSessionParamsAndIsNotReferrable { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; +// NSString * const IDENTITY = @"branch-id"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// preferenceHelper.installParams = INSTALL_PARAMS; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// }]; +// +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); +// XCTAssertNil(preferenceHelper.sessionParams); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +//} +// +//- (void)testSuccessWithNoSessionParamsAndIsReferrableAndAllowToBeClearIsNotSet { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const INSTALL_PARAMS = @"{\"bar\":\"foo\"}"; +// NSString * const IDENTITY = @"branch-id"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// preferenceHelper.installParams = INSTALL_PARAMS; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// }]; +// +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); +// XCTAssertNil(preferenceHelper.sessionParams); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +//} +// +//- (void)testSuccessWithNoSessionParamsAndIsReferrableAndAllowToBeClearIsSet { +// NSString * const DEVICE_TOKEN = @"foo-token"; +// NSString * const USER_URL = @"http://foo"; +// NSString * const DEVELOPER_ID = @"foo"; +// NSString * const SESSION_ID = @"foo-session"; +// NSString * const IDENTITY = @"branch-id"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// } isInstall:NO]; +// +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); +// XCTAssertNil(preferenceHelper.sessionParams); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +// XCTAssertNil(preferenceHelper.installParams); +//} +// +//- (void)testOpenWhenReferrableAndNoInstallParamsAndNonNullData { +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssertEqualObjects(preferenceHelper.installParams, OPEN_PARAMS); +// +// [self safelyFulfillExpectation:expectation]; +// } isInstall:TRUE]; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +//} +// +//- (void)testOpenWhenReferrableAndNoInstallParamsAndNullData { +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssertNil(preferenceHelper.installParams); +// +// [self safelyFulfillExpectation:expectation]; +// }]; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ }; +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +//} +// +//- (void)testOpenWhenReferrableAndNoInstallParamsAndNonLinkClickData { +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":0}"; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssertNil(preferenceHelper.installParams); +// +// [self safelyFulfillExpectation:expectation]; +// }]; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +//} +// +//- (void)testOpenWhenReferrableAndInstallParams { +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// NSString * const INSTALL_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; +// NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":1,\"bar\":\"foo\"}"; +// +// preferenceHelper.installParams = INSTALL_PARAMS; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssertEqualObjects(preferenceHelper.installParams, INSTALL_PARAMS); +// +// [self safelyFulfillExpectation:expectation]; +// }]; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +//} +// +//- (void)testOpenWhenNotReferrable { +// // 'isReferrable' seems to be an empty concept in iOS. +// // It is in the code but not used. -- Edward. +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// NSString * const OPEN_PARAMS = @"{\"+clicked_branch_link\":1,\"foo\":\"bar\"}"; +// +// XCTestExpectation *expectation = [self expectationWithDescription:@"Request Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError *error) { +// XCTAssertNil(error); +// XCTAssert([preferenceHelper.installParams isEqualToString:OPEN_PARAMS]); +// [self safelyFulfillExpectation:expectation]; +// } isInstall:TRUE]; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ BRANCH_RESPONSE_KEY_SESSION_DATA: OPEN_PARAMS }; +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +//} +// +//- (void)testEmptyResponseFields { +// NSString * DEVICE_TOKEN = @"foo-token"; +// NSString * USER_URL = @"http://foo"; +// NSString * DEVELOPER_ID = @"foo"; +// NSString * SESSION_ID = @"foo-session"; +// NSString * IDENTITY = @"branch-id"; +// +// BNCServerResponse *response = [[BNCServerResponse alloc] init]; +// response.data = @{ +// BRANCH_RESPONSE_KEY_RANDOMIZED_DEVICE_TOKEN: DEVICE_TOKEN, +// BRANCH_RESPONSE_KEY_USER_URL: USER_URL, +// BRANCH_RESPONSE_KEY_DEVELOPER_IDENTITY: DEVELOPER_ID, +// BRANCH_RESPONSE_KEY_SESSION_ID: SESSION_ID, +// BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN: IDENTITY +// }; +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"OpenRequest Expectation"]; +// BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:^(BOOL success, NSError *error) { +// XCTAssertNil(error); +// XCTAssertTrue(success); +// [self safelyFulfillExpectation:openExpectation]; +// } isInstall:NO]; +// +// [request processResponse:response error:nil]; +// +// [self awaitExpectations]; +// +// XCTAssertEqualObjects(preferenceHelper.randomizedDeviceToken, DEVICE_TOKEN); +// XCTAssertEqualObjects(preferenceHelper.userUrl, USER_URL); +// XCTAssertEqualObjects(preferenceHelper.userIdentity, DEVELOPER_ID); +// XCTAssertEqualObjects(preferenceHelper.sessionID, SESSION_ID); +// XCTAssertEqualObjects(preferenceHelper.randomizedBundleToken, IDENTITY); +// XCTAssertNil(preferenceHelper.sessionParams); +// XCTAssertNil(preferenceHelper.linkClickIdentifier); +// XCTAssertNil(preferenceHelper.installParams); +// +// // Now call processResponse with empty fields again. +// response.data = @{}; +// [request processResponse:response error:nil]; +// +// XCTAssertNotNil(preferenceHelper.randomizedDeviceToken); +// XCTAssertNotNil(preferenceHelper.userUrl); +// XCTAssertNotNil(preferenceHelper.sessionID); +// XCTAssertNotNil(preferenceHelper.randomizedBundleToken); +//} +// +//@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchSDKFunctionalityTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchSDKFunctionalityTests.m index e48b545f3..889ee54a3 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchSDKFunctionalityTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchSDKFunctionalityTests.m @@ -21,101 +21,101 @@ @interface BranchSDKFunctionalityTests : BNCTestCase @implementation BranchSDKFunctionalityTests -- (void)test00OpenOrInstall { - id serverInterfaceMock = OCMClassMock([BNCServerInterface class]); - - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - Branch.branchKey = @"key_live_foo"; - - Branch *branch = - [[Branch alloc] - initWithInterface:serverInterfaceMock - queue:[[BNCServerRequestQueue alloc] init] - cache:[[BNCLinkCache alloc] init] - preferenceHelper:preferenceHelper - key:@"key_live_foo"]; - - BNCServerResponse *openInstallResponse = [[BNCServerResponse alloc] init]; - openInstallResponse.data = @{ - @"randomized_device_token": TEST_RANDOMIZED_DEVICE_TOKEN, - @"randomized_bundle_token": TEST_RANDOMIZED_BUNDLE_TOKEN, - @"link": TEST_IDENTITY_LINK, - @"session_id": TEST_SESSION_ID - }; - - __block BNCServerCallback openOrInstallCallback; - id openOrInstallCallbackCheckBlock = [OCMArg checkWithBlock:^BOOL(BNCServerCallback callback) { - openOrInstallCallback = callback; - return YES; - }]; - - id openOrInstallInvocation = ^(NSInvocation *invocation) { - openOrInstallCallback(openInstallResponse, nil); - }; - - id openOrInstallUrlCheckBlock = [OCMArg checkWithBlock:^BOOL(NSString *url) { - return [url rangeOfString:@"open"].location != NSNotFound || [url rangeOfString:@"install"].location != NSNotFound; - }]; - [[[serverInterfaceMock expect] - andDo:openOrInstallInvocation] - postRequest:[OCMArg any] - url:openOrInstallUrlCheckBlock - key:[OCMArg any] - callback:openOrInstallCallbackCheckBlock]; - - XCTestExpectation *openExpectation = [self expectationWithDescription:@"Test open"]; - [branch initSessionWithLaunchOptions:@{} andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) { - XCTAssertNil(error); - XCTAssertEqualObjects(preferenceHelper.sessionID, TEST_SESSION_ID); - [openExpectation fulfill]; - }]; - - [self waitForExpectationsWithTimeout:2 handler:NULL]; -} - -#pragma mark - Test Utility - -- (void)safelyFulfillExpectation:(XCTestExpectation *)expectation { - if (!self.hasExceededExpectations) { - [expectation fulfill]; - } -} - -- (void)awaitExpectations { - [self waitForExpectationsWithTimeout:6.0 handler:^(NSError *error) { - self.hasExceededExpectations = YES; - }]; -} - -- (void)setupDefaultStubsForServerInterfaceMock:(id)serverInterfaceMock { - BNCServerResponse *openInstallResponse = [[BNCServerResponse alloc] init]; - openInstallResponse.data = @{ - @"session_id": TEST_SESSION_ID, - @"randomized_bundle_token": TEST_RANDOMIZED_BUNDLE_TOKEN, - @"randomized_device_token": TEST_RANDOMIZED_DEVICE_TOKEN, - }; - - // Stub open / install - __block BNCServerCallback openOrInstallCallback; - id openOrInstallCallbackCheckBlock = [OCMArg checkWithBlock:^BOOL(BNCServerCallback callback) { - openOrInstallCallback = callback; - return YES; - }]; - - id openOrInstallInvocation = ^(NSInvocation *invocation) { - openOrInstallCallback(openInstallResponse, nil); - }; - - id openOrInstallUrlCheckBlock = [OCMArg checkWithBlock:^BOOL(NSString *url) { - return [url rangeOfString:@"open"].location != NSNotFound || - [url rangeOfString:@"install"].location != NSNotFound; - }]; - [[[serverInterfaceMock expect] - andDo:openOrInstallInvocation] - postRequest:[OCMArg any] - url:openOrInstallUrlCheckBlock - key:[OCMArg any] - callback:openOrInstallCallbackCheckBlock]; -} +//- (void)test00OpenOrInstall { +// id serverInterfaceMock = OCMClassMock([BNCServerInterface class]); +// +// BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; +// Branch.branchKey = @"key_live_foo"; +// +// Branch *branch = +// [[Branch alloc] +// initWithInterface:serverInterfaceMock +// queue:[[BNCServerRequestQueue alloc] init] +// cache:[[BNCLinkCache alloc] init] +// preferenceHelper:preferenceHelper +// key:@"key_live_foo"]; +// +// BNCServerResponse *openInstallResponse = [[BNCServerResponse alloc] init]; +// openInstallResponse.data = @{ +// @"randomized_device_token": TEST_RANDOMIZED_DEVICE_TOKEN, +// @"randomized_bundle_token": TEST_RANDOMIZED_BUNDLE_TOKEN, +// @"link": TEST_IDENTITY_LINK, +// @"session_id": TEST_SESSION_ID +// }; +// +// __block BNCServerCallback openOrInstallCallback; +// id openOrInstallCallbackCheckBlock = [OCMArg checkWithBlock:^BOOL(BNCServerCallback callback) { +// openOrInstallCallback = callback; +// return YES; +// }]; +// +// id openOrInstallInvocation = ^(NSInvocation *invocation) { +// openOrInstallCallback(openInstallResponse, nil); +// }; +// +// id openOrInstallUrlCheckBlock = [OCMArg checkWithBlock:^BOOL(NSString *url) { +// return [url rangeOfString:@"open"].location != NSNotFound || [url rangeOfString:@"install"].location != NSNotFound; +// }]; +// [[[serverInterfaceMock expect] +// andDo:openOrInstallInvocation] +// postRequest:[OCMArg any] +// url:openOrInstallUrlCheckBlock +// key:[OCMArg any] +// callback:openOrInstallCallbackCheckBlock]; +// +// XCTestExpectation *openExpectation = [self expectationWithDescription:@"Test open"]; +// [branch initSessionWithLaunchOptions:@{} andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) { +// XCTAssertNil(error); +// XCTAssertEqualObjects(preferenceHelper.sessionID, TEST_SESSION_ID); +// [openExpectation fulfill]; +// }]; +// +// [self waitForExpectationsWithTimeout:2 handler:NULL]; +//} +// +//#pragma mark - Test Utility +// +//- (void)safelyFulfillExpectation:(XCTestExpectation *)expectation { +// if (!self.hasExceededExpectations) { +// [expectation fulfill]; +// } +//} +// +//- (void)awaitExpectations { +// [self waitForExpectationsWithTimeout:6.0 handler:^(NSError *error) { +// self.hasExceededExpectations = YES; +// }]; +//} +// +//- (void)setupDefaultStubsForServerInterfaceMock:(id)serverInterfaceMock { +// BNCServerResponse *openInstallResponse = [[BNCServerResponse alloc] init]; +// openInstallResponse.data = @{ +// @"session_id": TEST_SESSION_ID, +// @"randomized_bundle_token": TEST_RANDOMIZED_BUNDLE_TOKEN, +// @"randomized_device_token": TEST_RANDOMIZED_DEVICE_TOKEN, +// }; +// +// // Stub open / install +// __block BNCServerCallback openOrInstallCallback; +// id openOrInstallCallbackCheckBlock = [OCMArg checkWithBlock:^BOOL(BNCServerCallback callback) { +// openOrInstallCallback = callback; +// return YES; +// }]; +// +// id openOrInstallInvocation = ^(NSInvocation *invocation) { +// openOrInstallCallback(openInstallResponse, nil); +// }; +// +// id openOrInstallUrlCheckBlock = [OCMArg checkWithBlock:^BOOL(NSString *url) { +// return [url rangeOfString:@"open"].location != NSNotFound || +// [url rangeOfString:@"install"].location != NSNotFound; +// }]; +// [[[serverInterfaceMock expect] +// andDo:openOrInstallInvocation] +// postRequest:[OCMArg any] +// url:openOrInstallUrlCheckBlock +// key:[OCMArg any] +// callback:openOrInstallCallbackCheckBlock]; +//} @end diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchSetIdentityTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchSetIdentityTests.m deleted file mode 100644 index 5a5c79ef3..000000000 --- a/Branch-TestBed/Branch-SDK-Tests/BranchSetIdentityTests.m +++ /dev/null @@ -1,69 +0,0 @@ -// -// BranchSetIdentityRequestTests.m -// Branch-TestBed -// -// Created by Graham Mueller on 6/10/15. -// Copyright (c) 2015 Branch Metrics. All rights reserved. -// - -#import "BNCTestCase.h" -#import "BranchConstants.h" -#import "BNCPreferenceHelper.h" -#import "Branch.h" -#import - -static NSString * const IDENTITY_TEST_USER_ID = @"foo_id"; - -@interface BranchSetIdentityTests : BNCTestCase -@end - -@implementation BranchSetIdentityTests - -#pragma mark - setIdentity Tests -- (void)testSetIdentityWithCallback { - Branch *branch = [Branch getInstance]; - [branch logoutWithCallback:^(BOOL changed, NSError * _Nullable error) { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"setIdentity callback is called"]; - - [branch setIdentity:@"testUserIdWithCallback" withCallback:^(NSDictionary *params, NSError *error) { - XCTAssertEqualObjects(@"testUserIdWithCallback", preferenceHelper.userIdentity); - [expectation fulfill]; - }]; - - [self waitForExpectationsWithTimeout:5 handler:nil]; - }]; -} - -- (void)testSetIdentityWithNilUserId { - Branch *branch = [Branch getInstance]; - [branch logoutWithCallback:^(BOOL changed, NSError * _Nullable error) { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"setIdentityWithNil callback is called"]; - - [branch setIdentity:nil withCallback:^(NSDictionary *params, NSError *error) { - XCTAssertNil(preferenceHelper.userIdentity); - [expectation fulfill]; - }]; - - [self waitForExpectationsWithTimeout:5 handler:nil]; - }]; -} - -- (void)testSetIdentityWithUserId { - Branch *branch = [Branch getInstance]; - [branch logoutWithCallback:^(BOOL changed, NSError * _Nullable error) { - BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - - NSString *testUserId = @"testUserId"; - [branch setIdentity:testUserId withCallback:nil]; - - XCTAssertEqualObjects(@"testUserId", preferenceHelper.userIdentity); - }]; -} - - - -@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchUniversalObject.Test.m b/Branch-TestBed/Branch-SDK-Tests/BranchUniversalObject.Test.m deleted file mode 100644 index 7c3c2a23a..000000000 --- a/Branch-TestBed/Branch-SDK-Tests/BranchUniversalObject.Test.m +++ /dev/null @@ -1,286 +0,0 @@ -// -// BranchUniversalObject.Test.m -// Branch-TestBed -// -// Created by Edward Smith on 8/15/17. -// Copyright © 2017 Branch Metrics. All rights reserved. -// - -#import -#import "BNCTestCase.h" -#import "BranchUniversalObject.h" -#import "NSString+Branch.h" -#import "Branch.h" - -@interface BranchUniversalObjectTest : BNCTestCase -@end - -@implementation BranchUniversalObjectTest - -- (void) testDeserialize { - - NSString *jsonString = [self stringFromBundleWithKey:@"BranchUniversalObjectJSON"]; - XCTAssertTrue(jsonString, @"Can't load BranchUniversalObjectJSON resource from plist!"); - - NSError *error = nil; - NSDictionary *dictionary = - [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] - options:0 error:&error]; - XCTAssertNil(error); - XCTAssert(dictionary); - - BranchUniversalObject *buo = [BranchUniversalObject objectWithDictionary:dictionary]; - XCTAssert(buo); - - XCTAssertEqualObjects(buo.contentMetadata.contentSchema, BranchContentSchemaCommerceProduct); - XCTAssertEqual(buo.contentMetadata.quantity, 2); - XCTAssertEqualObjects(buo.contentMetadata.price, [NSDecimalNumber decimalNumberWithString:@"23.20"]); - XCTAssertEqualObjects(buo.contentMetadata.currency, BNCCurrencyUSD); - XCTAssertEqualObjects(buo.contentMetadata.sku, @"1994320302"); - XCTAssertEqualObjects(buo.contentMetadata.productName, @"my_product_name1"); - XCTAssertEqualObjects(buo.contentMetadata.productBrand, @"my_prod_Brand1"); - XCTAssertEqualObjects(buo.contentMetadata.productCategory, BNCProductCategoryBabyToddler); - XCTAssertEqualObjects(buo.contentMetadata.productVariant, @"3T"); - XCTAssertEqualObjects(buo.contentMetadata.condition, @"FAIR"); - XCTAssertEqual(buo.contentMetadata.ratingAverage, 5); - XCTAssertEqual(buo.contentMetadata.ratingCount, 5); - XCTAssertEqual(buo.contentMetadata.ratingMax, 7); - XCTAssertEqual(buo.contentMetadata.rating, 6); - XCTAssertEqualObjects(buo.contentMetadata.addressStreet, @"Street_name1"); - XCTAssertEqualObjects(buo.contentMetadata.addressCity, @"city1"); - XCTAssertEqualObjects(buo.contentMetadata.addressRegion, @"Region1"); - XCTAssertEqualObjects(buo.contentMetadata.addressCountry, @"Country1"); - XCTAssertEqualObjects(buo.contentMetadata.addressPostalCode, @"postal_code"); - XCTAssertEqual(buo.contentMetadata.latitude, 12.07); - XCTAssertEqual(buo.contentMetadata.longitude, -97.5); - NSArray *array = @[@"my_img_caption1", @"my_img_caption_2"]; - XCTAssertEqualObjects(buo.contentMetadata.imageCaptions, array); - NSDictionary *d = @{ - @"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1", - @"Custom_Content_metadata_key2": @"Custom_Content_metadata_val2" - }; - XCTAssertEqualObjects(buo.contentMetadata.customMetadata, d); - XCTAssertEqualObjects(buo.title, @"My Content Title"); - XCTAssertEqualObjects(buo.canonicalIdentifier, @"item/12345"); - XCTAssertEqualObjects(buo.canonicalUrl, @"https://branch.io/deepviews"); - array = @[@"My_Keyword1", @"My_Keyword2"]; - XCTAssertEqualObjects(buo.keywords, array); - XCTAssertEqualObjects(buo.contentDescription, @"my_product_description1"); - XCTAssertEqualObjects(buo.imageUrl, @"https://test_img_url"); - XCTAssertEqualObjects(buo.expirationDate, [NSDate dateWithTimeIntervalSince1970:(double)212123232544.0/1000.0]); - XCTAssertEqual(buo.publiclyIndex, NO); - XCTAssertEqual(buo.locallyIndex, YES); - XCTAssertEqualObjects(buo.creationDate, [NSDate dateWithTimeIntervalSince1970:(double)1501869445321.0/1000.0]); - - XCTAssertEqualObjects(buo.expirationDate.description, @"1976-09-21 03:07:12 +0000"); - XCTAssertEqualObjects(buo.creationDate.description, @"2017-08-04 17:57:25 +0000"); - - // Check serialization of the dictionary. - - NSDictionary *newDictionary = [buo dictionary]; - XCTAssert(newDictionary); - - NSMutableDictionary *oldDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionary]; - oldDictionary[@"$publicly_indexable"] = nil; // Remove this value since we don't add false values. - XCTAssertEqualObjects(oldDictionary, newDictionary); - - NSData* data = [NSJSONSerialization dataWithJSONObject:newDictionary options:0 error:&error]; - XCTAssertNil(error); - XCTAssert(data); - - // NSString *newString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - // Can't compare strings since the field item order may be different. - // XCTAssertEqualObjects(jsonString, newString); -} - -- (void) testSerialize { - BranchUniversalObject *buo = [BranchUniversalObject new]; - buo.contentMetadata.contentSchema = BranchContentSchemaCommerceProduct; - buo.contentMetadata.quantity = 2; - buo.contentMetadata.price = [NSDecimalNumber decimalNumberWithString:@"23.20"]; - buo.contentMetadata.currency = BNCCurrencyUSD; - buo.contentMetadata.sku = @"1994320302"; - buo.contentMetadata.productName = @"my_product_name1"; - buo.contentMetadata.productBrand = @"my_prod_Brand1"; - buo.contentMetadata.productCategory = BNCProductCategoryBabyToddler; - buo.contentMetadata.productVariant = @"3T"; - buo.contentMetadata.condition = @"FAIR"; - buo.contentMetadata.ratingAverage = 5; - buo.contentMetadata.ratingCount = 5; - buo.contentMetadata.ratingMax = 7; - buo.contentMetadata.rating = 6; - buo.contentMetadata.addressStreet = @"Street_name1"; - buo.contentMetadata.addressCity = @"city1"; - buo.contentMetadata.addressRegion = @"Region1"; - buo.contentMetadata.addressCountry = @"Country1"; - buo.contentMetadata.addressPostalCode = @"postal_code"; - buo.contentMetadata.latitude = 12.07; - buo.contentMetadata.longitude = -97.5; - buo.contentMetadata.imageCaptions = (id) @[@"my_img_caption1", @"my_img_caption_2"]; - buo.contentMetadata.customMetadata = (id) @{ - @"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1", - @"Custom_Content_metadata_key2": @"Custom_Content_metadata_val2" - }; - buo.title = @"My Content Title"; - buo.canonicalIdentifier = @"item/12345"; - buo.canonicalUrl = @"https://branch.io/deepviews"; - buo.keywords = @[@"My_Keyword1", @"My_Keyword2"]; - buo.contentDescription = @"my_product_description1"; - buo.imageUrl = @"https://test_img_url"; - buo.expirationDate = - [NSDate dateWithTimeIntervalSince1970:(double)212123232544.0/1000.0]; - buo.publiclyIndex = NO; - buo.locallyIndex = YES; - buo.creationDate = - [NSDate dateWithTimeIntervalSince1970:(double)1501869445321.0/1000.0]; - NSDictionary *buoDictionary = buo.dictionary; - - // Load the JSON: - - NSString *jsonString = [self stringFromBundleWithKey:@"BranchUniversalObjectJSON"]; - XCTAssertTrue(jsonString, @"Can't load BranchUniversalObjectJSON resource from plist!"); - - NSError *error = nil; - NSMutableDictionary *jsonDictionary = - [[NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] - options:0 error:&error] - mutableCopy]; - XCTAssertNil(error); - jsonDictionary[@"$publicly_indexable"] = nil; - - // Compare: - - XCTAssert(buoDictionary); - XCTAssert(jsonDictionary); - XCTAssertEqualObjects(buoDictionary, jsonDictionary); -} - -- (void) testSchemaDescription { - NSDictionary *d = [self mutableDictionaryFromBundleJSONWithKey:@"BranchUniversalObjectJSON"]; - BranchUniversalObject *b = [BranchUniversalObject objectWithDictionary:d]; - NSString *s = b.contentMetadata.description; - BNCTAssertEqualMaskedString(s, - @""); -} - -- (void) testBUODescription { - NSString *mask = [self stringFromBundleWithKey:@"BUODescription"]; - NSDictionary *d = [self mutableDictionaryFromBundleJSONWithKey:@"BranchUniversalObjectJSON"]; - BranchUniversalObject *b = [BranchUniversalObject objectWithDictionary:d]; - NSString *s = b.description; - NSLog(@"%@\n%@", s, mask); - XCTAssertTrue([s bnc_isEqualToMaskedString:mask]); -} - -- (void) testDeprecations { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - - BranchUniversalObject *buo = [BranchUniversalObject new]; - buo.price = 10.00; - buo.currency = BNCCurrencyUSD; - buo.type = @"Purchase"; - buo.contentIndexMode = BranchContentIndexModePublic; - buo.metadata = @{ @"Key1": @"Value1" }; - buo.automaticallyListOnSpotlight = YES; - - XCTAssertEqualObjects(buo.contentMetadata.price, [NSDecimalNumber decimalNumberWithString:@"10.00"]); - XCTAssertEqualObjects(buo.contentMetadata.currency, BNCCurrencyUSD); - XCTAssertEqualObjects(buo.contentMetadata.contentSchema, @"Purchase"); - XCTAssertEqual(buo.locallyIndex, YES); - XCTAssertEqual(buo.publiclyIndex, YES); - XCTAssertEqualObjects(buo.contentMetadata.customMetadata, @{ @"Key1": @"Value1" } ); - - XCTAssertEqual(buo.price, 10.00); - XCTAssertEqualObjects(buo.currency, BNCCurrencyUSD); - XCTAssertEqualObjects(buo.type, @"Purchase");; - XCTAssertEqual(buo.contentIndexMode, BranchContentIndexModePublic); - XCTAssertEqualObjects(buo.metadata, @{ @"Key1": @"Value1" }); - XCTAssertEqual(buo.automaticallyListOnSpotlight, YES); - - buo.contentMetadata.customMetadata = (NSMutableDictionary*) @{ @"Key2": @"Value2" }; - buo.contentMetadata.customMetadata[@"Key3"] = @"Value3"; - [buo addMetadataKey:@"Key4" value:@"Value4"]; - NSDictionary *d = @{ - @"Key2": @"Value2", - @"Key3": @"Value3", - @"Key4": @"Value4", - }; - XCTAssertEqualObjects(buo.metadata, d); - - #pragma clang diagnostic pop -} - -- (void) testDictionary { - NSDictionary *d = nil; - BranchUniversalObject *buo = [BranchUniversalObject new]; - - buo.contentMetadata.customMetadata = (id) @{}; - d = [NSDictionary new]; - XCTAssertEqualObjects(buo.contentMetadata.customMetadata, d); - - buo.contentMetadata.customMetadata = (id) @{}; - buo.contentMetadata.customMetadata[@"a"] = @"b"; - d = @{ @"a": @"b" }; - XCTAssertEqualObjects(buo.contentMetadata.customMetadata, d); - - buo.contentMetadata.customMetadata = [NSMutableDictionary dictionaryWithDictionary:@{@"1": @"2"}]; - buo.contentMetadata.customMetadata[@"3"] = @"4"; - d = @{ - @"1": @"2", - @"3": @"4", - }; - XCTAssertEqualObjects(buo.contentMetadata.customMetadata, d); -} - -- (void) testRegisterView { - Branch *branch = [Branch getInstance:@"key_live_foo"]; - [BNCPreferenceHelper sharedInstance].randomizedBundleToken = @"1234567"; - [BNCPreferenceHelper sharedInstance].sessionID = @"654321"; - [BNCPreferenceHelper sharedInstance].randomizedDeviceToken = @"987654321"; - XCTestExpectation *expectation = [self expectationWithDescription:@"testRegisterView"]; - id serverInterfaceMock = OCMPartialMock(branch.serverInterface); - - OCMStub( - [serverInterfaceMock genericHTTPRequest:[OCMArg any] - retryNumber:0 - callback:[OCMArg any] - retryHandler:[OCMArg any]] - ).andDo(^(NSInvocation *invocation) { - - __unsafe_unretained NSURLRequest *request = nil; - [invocation getArgument:&request atIndex:2]; - - NSError *error = nil; - NSString *url = request.URL.absoluteString; - NSData *bodyData = request.HTTPBody; - NSDictionary *parameters = [NSJSONSerialization JSONObjectWithData:bodyData options:0 error:&error]; - XCTAssertNil(error); - - NSLog(@"1"); - NSLog(@"URL: %@.", url); - NSLog(@"Body: %@.", parameters); - - NSString *eventName = parameters[@"name"]; - if ([url containsString:@"branch.io/v2/event/standard"] && - [eventName isEqualToString:@"VIEW_ITEM"]) { - [expectation fulfill]; - } - }); - - [branch clearNetworkQueue]; - BranchUniversalObject *buo = [BranchUniversalObject new]; - buo.canonicalIdentifier = @"Uniq!"; - buo.title = @"Object Title"; - [buo registerViewWithCallback:^(NSDictionary * _Nullable params, NSError * _Nullable error) { - XCTAssertNil(error); - }]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; -} - -- (void) testInitWithTitle { - BranchUniversalObject *buo = [[BranchUniversalObject new] initWithTitle:@"buoTitle"]; - XCTAssertEqual(buo.title, @"buoTitle"); -} - -@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchUniversalObjectTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchUniversalObjectTests.m new file mode 100644 index 000000000..9a7112e31 --- /dev/null +++ b/Branch-TestBed/Branch-SDK-Tests/BranchUniversalObjectTests.m @@ -0,0 +1,446 @@ +// +// BranchUniversalObjectTests.m +// Branch-TestBed +// +// Created by Edward Smith on 8/15/17. +// Copyright © 2017 Branch Metrics. All rights reserved. +// + +#import +#import "BranchUniversalObject.h" + +@interface BranchUniversalObjectTests : XCTestCase +@end + +@implementation BranchUniversalObjectTests + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +#pragma mark BranchContentMetadata tests + +- (BranchContentMetadata *)branchContentMetadataWithAllPropertiesSet { + BranchContentMetadata *metadata = [BranchContentMetadata new]; + metadata.contentSchema = BranchContentSchemaOther; + metadata.quantity = 10; + metadata.price = [[NSDecimalNumber alloc] initWithDouble:5.5]; + metadata.currency = BNCCurrencyUSD; + metadata.sku = @"testSKU"; + metadata.productName = @"testProductName"; + metadata.productBrand = @"testProductBrand"; + metadata.productCategory = BNCProductCategoryApparel; + metadata.productVariant = @"testProductVariant"; + metadata.condition = BranchConditionNew; + metadata.ratingAverage = 3.5; + metadata.ratingCount = 2; + metadata.ratingMax = 4; + metadata.rating = 3; + metadata.addressStreet = @"195 Page Mill Road"; + metadata.addressCity = @"Palo Alto"; + metadata.addressRegion = @"CA"; + metadata.addressCountry = @"USA"; + metadata.addressPostalCode = @"94306"; + metadata.latitude = 37.426; + metadata.longitude = -122.138; + + metadata.imageCaptions = @[ + @"Hello World", + @"Goodbye World" + ].mutableCopy; + + metadata.customMetadata = @{ + @"custom0": @"custom data 0" + }.mutableCopy; + + return metadata; +} + +- (void)verifyBranchContentMetadataWithAllProperties:(BranchContentMetadata *)metadata { + XCTAssertNotNil(metadata); + + XCTAssertEqual(BranchContentSchemaOther, metadata.contentSchema); + XCTAssertTrue([@(10) isEqualToNumber:@(metadata.quantity)]); + XCTAssertTrue([[[NSDecimalNumber alloc] initWithDouble:5.5] isEqualToNumber:metadata.price]); + + XCTAssertEqual(BNCCurrencyUSD, metadata.currency); + XCTAssertTrue([@"testSKU" isEqualToString:metadata.sku]); + XCTAssertTrue([@"testProductName" isEqualToString:metadata.productName]); + XCTAssertTrue([@"testProductBrand" isEqualToString:metadata.productBrand]); + XCTAssertEqual(BNCProductCategoryApparel, metadata.productCategory); + XCTAssertTrue([@"testProductVariant" isEqualToString:metadata.productVariant]); + XCTAssertEqual(BranchConditionNew, metadata.condition); + XCTAssertTrue([@(3.5) isEqualToNumber:@(metadata.ratingAverage)]); + XCTAssertTrue([@(2) isEqualToNumber:@(metadata.ratingCount)]); + XCTAssertTrue([@(4) isEqualToNumber:@(metadata.ratingMax)]); + XCTAssertTrue([@(3) isEqualToNumber:@(metadata.rating)]); + + XCTAssertTrue([@"195 Page Mill Road" isEqualToString:metadata.addressStreet]); + XCTAssertTrue([@"Palo Alto" isEqualToString:metadata.addressCity]); + XCTAssertTrue([@"CA" isEqualToString:metadata.addressRegion]); + XCTAssertTrue([@"USA" isEqualToString:metadata.addressCountry]); + XCTAssertTrue([@"94306" isEqualToString:metadata.addressPostalCode]); + + XCTAssertTrue([@(37.426) isEqualToNumber:@(metadata.latitude)]); + XCTAssertTrue([@(-122.138) isEqualToNumber:@(metadata.longitude)]); + + XCTAssertNotNil(metadata.imageCaptions); + XCTAssertTrue(metadata.imageCaptions.count == 2); + XCTAssertTrue([metadata.imageCaptions[0] isEqualToString:@"Hello World"]); + XCTAssertTrue([metadata.imageCaptions[1] isEqualToString:@"Goodbye World"]); + + XCTAssertNotNil(metadata.customMetadata); + XCTAssertTrue(metadata.customMetadata.allKeys.count == 1); +} + +- (void)verifyBranchContentMetadataDictionaryWithAllPropertiesSet:(NSDictionary *)dict { + XCTAssertTrue([@"OTHER" isEqualToString:dict[@"$content_schema"]]); + XCTAssertTrue([@(10) isEqualToNumber:dict[@"$quantity"]]); + XCTAssertTrue([[[NSDecimalNumber alloc] initWithDouble:5.5] isEqualToNumber:dict[@"$price"]]); + XCTAssertTrue([@"USD" isEqualToString:dict[@"$currency"]]); + XCTAssertTrue([@"testSKU" isEqualToString:dict[@"$sku"]]); + XCTAssertTrue([@"testProductName" isEqualToString:dict[@"$product_name"]]); + XCTAssertTrue([@"testProductBrand" isEqualToString:dict[@"$product_brand"]]); + XCTAssertTrue([@"Apparel & Accessories" isEqualToString:dict[@"$product_category"]]); + XCTAssertTrue([@"testProductVariant" isEqualToString:dict[@"$product_variant"]]); + XCTAssertTrue([@"NEW" isEqualToString:dict[@"$condition"]]); + + XCTAssertTrue([@(3.5) isEqualToNumber:dict[@"$rating_average"]]); + XCTAssertTrue([@(2) isEqualToNumber:dict[@"$rating_count"]]); + XCTAssertTrue([@(4) isEqualToNumber:dict[@"$rating_max"]]); + XCTAssertTrue([@(3) isEqualToNumber:dict[@"$rating"]]); + + XCTAssertTrue([@"195 Page Mill Road" isEqualToString:dict[@"$address_street"]]); + XCTAssertTrue([@"Palo Alto" isEqualToString:dict[@"$address_city"]]); + XCTAssertTrue([@"CA" isEqualToString:dict[@"$address_region"]]); + XCTAssertTrue([@"USA" isEqualToString:dict[@"$address_country"]]); + XCTAssertTrue([@"94306" isEqualToString:dict[@"$address_postal_code"]]); + + XCTAssertTrue([@(37.426) isEqualToNumber:dict[@"$latitude"]]); + XCTAssertTrue([@(-122.138) isEqualToNumber:dict[@"$longitude"]]); + + XCTAssertTrue([dict[@"$image_captions"] isKindOfClass:NSArray.class]); + NSArray *tmp = dict[@"$image_captions"]; + XCTAssertTrue(tmp.count == 2); + XCTAssertTrue([tmp[0] isEqualToString:@"Hello World"]); + XCTAssertTrue([tmp[1] isEqualToString:@"Goodbye World"]); + + XCTAssertTrue([@"custom data 0" isEqualToString:dict[@"custom0"]]); +} + +- (void)testBranchContentMetadataCreation_NoPropertiesSet { + BranchContentMetadata *metadata = [BranchContentMetadata new]; + + // most properties default to nil. primitives default to 0 + XCTAssertNil(metadata.contentSchema); + XCTAssertEqual(0, metadata.quantity); + XCTAssertNil(metadata.price); + XCTAssertNil(metadata.currency); + XCTAssertNil(metadata.sku); + XCTAssertNil(metadata.productName); + XCTAssertNil(metadata.productBrand); + XCTAssertNil(metadata.productCategory); + XCTAssertNil(metadata.productVariant); + XCTAssertNil(metadata.condition); + XCTAssertEqual(0, metadata.ratingAverage); + XCTAssertEqual(0, metadata.ratingCount); + XCTAssertEqual(0, metadata.ratingMax); + XCTAssertEqual(0, metadata.rating); + XCTAssertNil(metadata.addressStreet); + XCTAssertNil(metadata.addressCity); + XCTAssertNil(metadata.addressRegion); + XCTAssertNil(metadata.addressCountry); + XCTAssertNil(metadata.addressPostalCode); + XCTAssertEqual(0, metadata.latitude); + XCTAssertEqual(0, metadata.longitude); + + // defaults to an empty array + XCTAssertNotNil(metadata.imageCaptions); + XCTAssertTrue(metadata.imageCaptions.count == 0); + + // defaults to an empty dictionary + XCTAssertNotNil(metadata.customMetadata); + XCTAssertTrue(metadata.customMetadata.allKeys.count == 0); +} + +- (void)testBranchContentMetadataCreation_AllPropertiesSet { + BranchContentMetadata *metadata = [self branchContentMetadataWithAllPropertiesSet]; + [self verifyBranchContentMetadataWithAllProperties:metadata]; +} + +- (void)testBranchContentMetadataDictionary_NoPropertiesSet { + BranchContentMetadata *metadata = [BranchContentMetadata new]; + NSDictionary *dict = metadata.dictionary; + + XCTAssertNotNil(dict); + XCTAssertTrue(dict.allKeys.count == 0); +} + +- (void)testBranchContentMetadataDictionary_AllPropertiesSet { + BranchContentMetadata *metadata = [self branchContentMetadataWithAllPropertiesSet]; + NSDictionary *dict = metadata.dictionary; + + XCTAssertNotNil(dict); + XCTAssertTrue(dict.allKeys.count == 23); + [self verifyBranchContentMetadataDictionaryWithAllPropertiesSet:dict]; +} + +- (void)testBranchContentMetadata_contentMetadataWithDictionary { + BranchContentMetadata *original = [self branchContentMetadataWithAllPropertiesSet]; + NSDictionary *dict = [original dictionary]; + + BranchContentMetadata *metadata = [BranchContentMetadata contentMetadataWithDictionary:dict]; + [self verifyBranchContentMetadataWithAllProperties:metadata]; +} + +- (void)testBranchContentMetadataDescription_NoPropertiesSet { + BranchContentMetadata *metadata = [BranchContentMetadata new]; + NSString *desc = [metadata description]; + XCTAssertTrue([desc containsString:@"BranchContentMetadata"]); + XCTAssertTrue([desc containsString:@"schema: (null) userData: 0 items"]); +} + +- (void)testBranchContentMetadataDescription_AllPropertiesSet { + BranchContentMetadata *metadata = [self branchContentMetadataWithAllPropertiesSet]; + NSString *desc = [metadata description]; + XCTAssertTrue([desc containsString:@"BranchContentMetadata"]); + XCTAssertTrue([desc containsString:@"schema: OTHER userData: 1 items"]); +} + +#pragma mark BranchUniversalObject tests + +- (BranchUniversalObject *)branchUniversalObjectWithAllPropertiesSet { + BranchUniversalObject *buo = [[BranchUniversalObject alloc] initWithCanonicalIdentifier:@"io.branch.testObject"]; + buo.canonicalUrl = @"https://branch.io"; + buo.title = @"Test Title"; + buo.contentDescription = @"the quick brown fox jumps over the lazy dog"; + buo.imageUrl = @"https://branch.io"; + buo.keywords = @[@"keyword1", @"keyword2"]; + buo.expirationDate = [NSDate dateWithTimeIntervalSinceNow:1]; + buo.locallyIndex = YES; + buo.publiclyIndex = YES; + + buo.contentMetadata = [self branchContentMetadataWithAllPropertiesSet]; + return buo; +} + +- (void)verifyBranchUniversalObjectWithAllPropertiesSet:(BranchUniversalObject *)buo { + XCTAssertNotNil(buo); + XCTAssertTrue([@"https://branch.io" isEqualToString:buo.canonicalUrl]); + XCTAssertTrue([@"Test Title" isEqualToString:buo.title]); + XCTAssertTrue([@"the quick brown fox jumps over the lazy dog" isEqualToString:buo.contentDescription]); + XCTAssertTrue([@"https://branch.io" isEqualToString:buo.imageUrl]); + + XCTAssertTrue(buo.keywords.count == 2); + XCTAssertTrue([buo.keywords[0] isEqualToString:@"keyword1"]); + XCTAssertTrue([buo.keywords[1] isEqualToString:@"keyword2"]); + + XCTAssertTrue([buo.creationDate compare:buo.expirationDate] == NSOrderedAscending); + + XCTAssertTrue(buo.locallyIndex); + XCTAssertTrue(buo.publiclyIndex); + + [self verifyBranchContentMetadataWithAllProperties:buo.contentMetadata]; +} + +- (void)verifyBranchUniversalObjectDictionaryWithAllPropertiesSet:(NSDictionary *)dict { + XCTAssertTrue([@"io.branch.testObject" isEqualToString:dict[@"$canonical_identifier"]]); + XCTAssertTrue([@"https://branch.io" isEqualToString:dict[@"$canonical_url"]]); + XCTAssertTrue([@"Test Title" isEqualToString:dict[@"$og_title"]]); + XCTAssertTrue([@"the quick brown fox jumps over the lazy dog" isEqualToString:dict[@"$og_description"]]); + XCTAssertTrue([@"https://branch.io" isEqualToString:dict[@"$og_image_url"]]); + + XCTAssertTrue(dict[@"$locally_indexable"]); + XCTAssertTrue(dict[@"$publicly_indexable"]); + + XCTAssertTrue([dict[@"$creation_timestamp"] isKindOfClass:NSNumber.class]); + XCTAssertTrue([dict[@"$exp_date"] isKindOfClass:NSNumber.class]); + NSNumber *creationDate = dict[@"$creation_timestamp"]; + NSNumber *expirationDate = dict[@"$exp_date"]; + XCTAssertTrue([creationDate compare:expirationDate] == NSOrderedAscending); + + XCTAssertTrue([dict[@"$keywords"] isKindOfClass:NSArray.class]); + NSArray *tmp = dict[@"$keywords"]; + XCTAssertTrue(tmp.count == 2); + XCTAssertTrue([tmp[0] isEqualToString:@"keyword1"]); + XCTAssertTrue([tmp[1] isEqualToString:@"keyword2"]); + + // the BranchContentMetadata dictionary is NOT in a sub dictionary, it is merged in at the top level + [self verifyBranchContentMetadataDictionaryWithAllPropertiesSet:dict]; +} + +- (void)testBranchUniversalObjectCreation { + BranchUniversalObject *buo = [BranchUniversalObject new]; + XCTAssertNotNil(buo); + + XCTAssertNil(buo.canonicalIdentifier); + XCTAssertNil(buo.canonicalUrl); + XCTAssertNil(buo.title); + XCTAssertNil(buo.contentDescription); + XCTAssertNil(buo.imageUrl); + XCTAssertNil(buo.keywords); + XCTAssertNil(buo.creationDate); + XCTAssertNil(buo.expirationDate); + XCTAssertFalse(buo.locallyIndex); + XCTAssertFalse(buo.publiclyIndex); + + XCTAssertNotNil(buo.contentMetadata); +} + +- (void)testBranchUniversalObjectCreation_initWithCanonicalIdentifier { + BranchUniversalObject *buo = [[BranchUniversalObject alloc] initWithCanonicalIdentifier:@"io.branch.testObject"]; + XCTAssertNotNil(buo); + + XCTAssertTrue([@"io.branch.testObject" isEqualToString:buo.canonicalIdentifier]); + XCTAssertNil(buo.canonicalUrl); + XCTAssertNil(buo.title); + XCTAssertNil(buo.contentDescription); + XCTAssertNil(buo.imageUrl); + XCTAssertNil(buo.keywords); + XCTAssertNotNil(buo.creationDate); + XCTAssertNil(buo.expirationDate); + XCTAssertFalse(buo.locallyIndex); + XCTAssertFalse(buo.publiclyIndex); + + XCTAssertNotNil(buo.contentMetadata); +} + +- (void)testBranchUniversalObjectCreation_initWithTitle { + BranchUniversalObject *buo = [[BranchUniversalObject alloc] initWithTitle:@"Test Title"]; + XCTAssertNotNil(buo); + + XCTAssertNil(buo.canonicalIdentifier); + XCTAssertNil(buo.canonicalUrl); + XCTAssertTrue([@"Test Title" isEqualToString:buo.title]); + XCTAssertNil(buo.contentDescription); + XCTAssertNil(buo.imageUrl); + XCTAssertNil(buo.keywords); + XCTAssertNotNil(buo.creationDate); + XCTAssertNil(buo.expirationDate); + XCTAssertFalse(buo.locallyIndex); + XCTAssertFalse(buo.publiclyIndex); + + XCTAssertNotNil(buo.contentMetadata); +} + +- (void)testBranchUniversalObject_AllPropertiesSet { + BranchUniversalObject *buo = [self branchUniversalObjectWithAllPropertiesSet]; + [self verifyBranchUniversalObjectWithAllPropertiesSet:buo]; +} + +- (void)testBranchUniversalObjectDescription_AllPropertiesSet { + BranchUniversalObject *buo = [self branchUniversalObjectWithAllPropertiesSet]; + NSString *desc = buo.description; + + // Verifies a few properties used to generate the description string + XCTAssertTrue([desc containsString:@"BranchUniversalObject"]); + XCTAssertTrue([desc containsString:@"canonicalIdentifier: io.branch.testObject"]); + XCTAssertTrue([desc containsString:@"title: Test Title"]); + XCTAssertTrue([desc containsString:@"contentDescription: the quick brown fox jumps over the lazy dog"]); +} + +- (void)testBranchUniversalObjectDictionary_AllPropertiesSet { + BranchUniversalObject *buo = [self branchUniversalObjectWithAllPropertiesSet]; + NSDictionary *dict = buo.dictionary; + + XCTAssertNotNil(dict); + XCTAssertTrue(dict.allKeys.count == 33); + [self verifyBranchUniversalObjectDictionaryWithAllPropertiesSet:dict]; +} + +- (void)testBranchUniversalObject_objectWithDictionary { + BranchUniversalObject *original = [self branchUniversalObjectWithAllPropertiesSet]; + NSDictionary *dict = [original dictionary]; + + BranchUniversalObject *buo = [BranchUniversalObject objectWithDictionary:dict]; + [self verifyBranchUniversalObjectWithAllPropertiesSet:buo]; +} + +- (void)testBranchUniversalObject_getDictionaryWithCompleteLinkProperties_NoLinkPropertiesSet { + BranchUniversalObject *original = [self branchUniversalObjectWithAllPropertiesSet]; + BranchLinkProperties *linkProperties = [BranchLinkProperties new]; + NSDictionary *dict = [original getDictionaryWithCompleteLinkProperties:linkProperties]; + + XCTAssertNotNil(dict); + XCTAssertTrue([@(0) isEqualToNumber:dict[@"~duration"]]); +} + +- (void)testBranchUniversalObject_getDictionaryWithCompleteLinkProperties_AllLinkPropertiesSet { + BranchUniversalObject *original = [self branchUniversalObjectWithAllPropertiesSet]; + BranchLinkProperties *linkProperties = [BranchLinkProperties new]; + + linkProperties.tags = @[@"tag1", @"tag2"]; + linkProperties.feature = @"test feature"; + linkProperties.alias = @"test alias"; + linkProperties.channel = @"test channel"; + linkProperties.matchDuration = 10; + + // BranchUniversalObject.controlParams overwrites BranchContentMetadata.customMetadata + linkProperties.controlParams = @{ + @"testControlParam": @"test control param", + //@"custom0": @"test control param" + }; + + NSDictionary *dict = [original getDictionaryWithCompleteLinkProperties:linkProperties]; + XCTAssertNotNil(dict); + XCTAssertTrue(dict.allKeys.count == 39); + + XCTAssertTrue([@(10) isEqualToNumber:dict[@"~duration"]]); + XCTAssertTrue([@"test alias" isEqualToString:dict[@"~alias"]]); + XCTAssertTrue([@"test channel" isEqualToString:dict[@"~channel"]]); + XCTAssertTrue([@"test feature" isEqualToString:dict[@"~feature"]]); + + XCTAssertTrue([@"test control param" isEqualToString:dict[@"testControlParam"]]); + + // BranchUniversalObject fields are at the top level of the dictionary + [self verifyBranchUniversalObjectDictionaryWithAllPropertiesSet:dict]; +} + +- (void)testBranchUniversalObject_getParamsForServerRequestWithAddedLinkProperties_NoLinkPropertiesSet { + BranchUniversalObject *original = [self branchUniversalObjectWithAllPropertiesSet]; + BranchLinkProperties *linkProperties = [BranchLinkProperties new]; + + // Nothing is added with this call + NSDictionary *dict = [original getParamsForServerRequestWithAddedLinkProperties:linkProperties]; + + XCTAssertNotNil(dict); + + // BranchUniversalObject fields are at the top level of the dictionary + [self verifyBranchUniversalObjectDictionaryWithAllPropertiesSet:dict]; +} + +- (void)testBranchUniversalObject_getParamsForServerRequestWithAddedLinkProperties_AllLinkPropertiesSet { + BranchUniversalObject *original = [self branchUniversalObjectWithAllPropertiesSet]; + BranchLinkProperties *linkProperties = [BranchLinkProperties new]; + linkProperties.tags = @[@"tag1", @"tag2"]; + linkProperties.feature = @"test feature"; + linkProperties.alias = @"test alias"; + linkProperties.channel = @"test channel"; + linkProperties.matchDuration = 10; + + // BranchUniversalObject.controlParams overwrites BranchContentMetadata.customMetadata + linkProperties.controlParams = @{ + @"testControlParam": @"test control param", + //@"custom0": @"test control param" + }; + + NSDictionary *dict = [original getParamsForServerRequestWithAddedLinkProperties:linkProperties]; + XCTAssertNotNil(dict); + XCTAssertTrue(dict.allKeys.count == 34); + + // only the control parameters are in the dictionary + XCTAssertTrue([@"test control param" isEqualToString:dict[@"testControlParam"]]); + XCTAssertNil(dict[@"~duration"]); + XCTAssertNil(dict[@"~alias"]); + XCTAssertNil(dict[@"~channel"]); + XCTAssertNil(dict[@"~feature"]); + + // BranchUniversalObject fields are at the top level of the dictionary + [self verifyBranchUniversalObjectDictionaryWithAllPropertiesSet:dict]; +} + +@end diff --git a/Branch-TestBed/Branch-SDK-Tests/NSErrorBranchCategoryTests.m b/Branch-TestBed/Branch-SDK-Tests/NSErrorBranchCategoryTests.m deleted file mode 100644 index 794027e57..000000000 --- a/Branch-TestBed/Branch-SDK-Tests/NSErrorBranchCategoryTests.m +++ /dev/null @@ -1,58 +0,0 @@ -/** - @file NSErrorBranchCategoryTests.m - @package Branch-SDK - @brief Branch error tests. - - @author Edward Smith - @date August 2017 - @copyright Copyright © 2017 Branch. All rights reserved. -*/ - -#import "BNCTestCase.h" -#import "NSError+Branch.h" - -@interface NSErrorBranchCategoryTests : BNCTestCase -@end - -@implementation NSErrorBranchCategoryTests - -- (void) testErrorBasic { - - NSError *error = nil; - error = [NSError branchErrorWithCode:BNCInitError]; - XCTAssert(error.domain == [NSError bncErrorDomain]); - XCTAssert(error.code == BNCInitError); - XCTAssert([error.localizedDescription isEqualToString: - @"The Branch user session has not been initialized."] - ); - - NSError *underlyingError = - [NSError errorWithDomain:NSCocoaErrorDomain - code:NSFileNoSuchFileError userInfo:nil]; - error = [NSError branchErrorWithCode:BNCServerProblemError error:underlyingError]; - XCTAssert(error.domain == [NSError bncErrorDomain]); - XCTAssert(error.code == BNCServerProblemError); - XCTAssert( - [error.localizedDescription isEqualToString: - @"Trouble reaching the Branch servers, please try again shortly."] - ); - XCTAssert(error.userInfo[NSUnderlyingErrorKey] == underlyingError); - if ([UIDevice currentDevice].systemVersion.floatValue < 9.0) { - XCTAssert([error.localizedFailureReason isEqualToString: - @"The operation couldn’t be completed. (Cocoa error 4.)"]); - } else { - XCTAssert([error.localizedFailureReason isEqualToString:@"The file doesn’t exist."]); - } - - NSString *message = [NSString stringWithFormat:@"Network operation of class '%@' does not conform to the BNCNetworkOperationProtocol.", - NSStringFromClass([self class])]; - error = [NSError branchErrorWithCode:BNCNetworkServiceInterfaceError localizedMessage:message]; - XCTAssert(error.domain == [NSError bncErrorDomain]); - XCTAssert(error.code == BNCNetworkServiceInterfaceError); - XCTAssert([error.localizedDescription isEqualToString: - @"The underlying network service does not conform to the BNCNetworkOperationProtocol."]); - XCTAssert([error.localizedFailureReason isEqualToString: - @"Network operation of class 'NSErrorBranchCategoryTests' does not conform to the BNCNetworkOperationProtocol."]); -} - -@end diff --git a/Branch-TestBed/Branch-SDK-Tests/NSErrorBranchTests.m b/Branch-TestBed/Branch-SDK-Tests/NSErrorBranchTests.m new file mode 100644 index 000000000..4399b7484 --- /dev/null +++ b/Branch-TestBed/Branch-SDK-Tests/NSErrorBranchTests.m @@ -0,0 +1,54 @@ +/** + @file NSErrorBranchCategoryTests.m + @package Branch-SDK + @brief Branch error tests. + + @author Edward Smith + @date August 2017 + @copyright Copyright © 2017 Branch. All rights reserved. +*/ + +#import +#import "NSError+Branch.h" + +@interface NSErrorBranchTests : XCTestCase +@end + +@implementation NSErrorBranchTests + +- (void)testErrorDomain { + XCTAssertTrue([@"io.branch.sdk.error" isEqualToString:[NSError bncErrorDomain]]); +} + +- (void)testError { + NSError *error = [NSError branchErrorWithCode:BNCInitError]; + XCTAssert(error.domain == [NSError bncErrorDomain]); + XCTAssert(error.code == BNCInitError); + XCTAssert([error.localizedDescription isEqualToString: + @"The Branch user session has not been initialized."] + ); +} + +- (void)testErrorWithUnderlyingError { + NSError *underlyingError = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileNoSuchFileError userInfo:nil]; + NSError *error = [NSError branchErrorWithCode:BNCServerProblemError error:underlyingError]; + + XCTAssert(error.domain == [NSError bncErrorDomain]); + XCTAssert(error.code == BNCServerProblemError); + XCTAssert([error.localizedDescription isEqualToString: @"Trouble reaching the Branch servers, please try again shortly."]); + + XCTAssert(error.userInfo[NSUnderlyingErrorKey] == underlyingError); + XCTAssert([error.localizedFailureReason isEqualToString:@"The file doesn’t exist."]); +} + +- (void)testErrorWithMessage { + NSString *message = [NSString stringWithFormat:@"Network operation of class '%@' does not conform to the BNCNetworkOperationProtocol.", NSStringFromClass([self class])]; + NSError *error = [NSError branchErrorWithCode:BNCNetworkServiceInterfaceError localizedMessage:message]; + + XCTAssert(error.domain == [NSError bncErrorDomain]); + XCTAssert(error.code == BNCNetworkServiceInterfaceError); + XCTAssert([error.localizedDescription isEqualToString: @"The underlying network service does not conform to the BNCNetworkOperationProtocol."]); + XCTAssert([error.localizedFailureReason isEqualToString: @"Network operation of class 'NSErrorBranchTests' does not conform to the BNCNetworkOperationProtocol."]); +} + +@end diff --git a/Branch-TestBed/Branch-SDK-Tests/NSString+Branch.Test.m b/Branch-TestBed/Branch-SDK-Tests/NSStringBranchTests.m similarity index 90% rename from Branch-TestBed/Branch-SDK-Tests/NSString+Branch.Test.m rename to Branch-TestBed/Branch-SDK-Tests/NSStringBranchTests.m index 1819f2765..67a966d11 100644 --- a/Branch-TestBed/Branch-SDK-Tests/NSString+Branch.Test.m +++ b/Branch-TestBed/Branch-SDK-Tests/NSStringBranchTests.m @@ -8,17 +8,17 @@ @copyright Copyright © 2017 Branch. All rights reserved. */ +#import #import "NSString+Branch.h" -#import "BNCTestCase.h" #define _countof(array) (sizeof(array)/sizeof(array[0])) -@interface NSStringBranchTest : BNCTestCase +@interface NSStringBranchTests : XCTestCase @end -@implementation NSStringBranchTest +@implementation NSStringBranchTests -- (void) testMaskEqual { +- (void)testMaskEqual { XCTAssertTrue([@"0123" bnc_isEqualToMaskedString:@"0123"]); XCTAssertFalse([@"0123" bnc_isEqualToMaskedString:@"012"]); XCTAssertFalse([@"0123" bnc_isEqualToMaskedString:@"01234"]); diff --git a/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj b/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj index c235b3026..f5431f7e1 100644 --- a/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj +++ b/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj @@ -33,7 +33,6 @@ 4683F0761B20A73F00A432E7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 670016731940F51400A9E103 /* AppDelegate.m */; }; 46DC406E1B2A328900D2D203 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67BBCF271A69E49A009C7DAE /* AdSupport.framework */; }; 4AB16368239E3A2700D42931 /* DispatchToIsolationQueueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AB16367239E3A2700D42931 /* DispatchToIsolationQueueTests.m */; }; - 4D1683A62098C902008819E3 /* BranchSetIdentityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16837B2098C901008819E3 /* BranchSetIdentityTests.m */; }; 4D1683A82098C902008819E3 /* BNCServerRequestQueueOldTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16837D2098C901008819E3 /* BNCServerRequestQueueOldTests.m */; }; 4D1683AA2098C902008819E3 /* BranchOpenRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16837F2098C901008819E3 /* BranchOpenRequestTests.m */; }; 4D1683AC2098C902008819E3 /* BranchInstallRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683822098C901008819E3 /* BranchInstallRequestTests.m */; }; @@ -41,16 +40,14 @@ 4D1683B02098C902008819E3 /* BranchSDKFunctionalityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683862098C901008819E3 /* BranchSDKFunctionalityTests.m */; }; 4D1683B62098C902008819E3 /* BNCURLFilterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16838C2098C901008819E3 /* BNCURLFilterTests.m */; }; 4D1683B72098C902008819E3 /* BNCTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16838D2098C901008819E3 /* BNCTestCase.m */; }; - 4D1683B82098C902008819E3 /* BNCEncodingUtils.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16838E2098C901008819E3 /* BNCEncodingUtils.Test.m */; }; + 4D1683B82098C902008819E3 /* BNCEncodingUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16838E2098C901008819E3 /* BNCEncodingUtilsTests.m */; }; 4D1683B92098C902008819E3 /* BNCSystemObserverTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16838F2098C901008819E3 /* BNCSystemObserverTests.m */; }; - 4D1683BA2098C902008819E3 /* BNCLog.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683902098C901008819E3 /* BNCLog.Test.m */; }; - 4D1683BC2098C902008819E3 /* BranchDelegate.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683922098C901008819E3 /* BranchDelegate.Test.m */; }; - 4D1683BD2098C902008819E3 /* BranchNetworkScenario.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683932098C901008819E3 /* BranchNetworkScenario.Test.m */; }; - 4D1683C02098C902008819E3 /* BranchUniversalObject.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683962098C901008819E3 /* BranchUniversalObject.Test.m */; }; - 4D1683C12098C902008819E3 /* BNCApplication.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683972098C901008819E3 /* BNCApplication.Test.m */; }; + 4D1683BA2098C902008819E3 /* BNCLogTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683902098C901008819E3 /* BNCLogTests.m */; }; + 4D1683C02098C902008819E3 /* BranchUniversalObjectTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683962098C901008819E3 /* BranchUniversalObjectTests.m */; }; + 4D1683C12098C902008819E3 /* BNCApplicationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683972098C901008819E3 /* BNCApplicationTests.m */; }; 4D1683C62098C902008819E3 /* BranchEvent.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16839C2098C901008819E3 /* BranchEvent.Test.m */; }; - 4D1683C72098C902008819E3 /* BNCCrashlyticsWrapper.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16839D2098C901008819E3 /* BNCCrashlyticsWrapper.Test.m */; }; - 4D1683C82098C902008819E3 /* NSString+Branch.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16839E2098C901008819E3 /* NSString+Branch.Test.m */; }; + 4D1683C72098C902008819E3 /* BNCCrashlyticsWrapperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16839D2098C901008819E3 /* BNCCrashlyticsWrapperTests.m */; }; + 4D1683C82098C902008819E3 /* NSStringBranchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16839E2098C901008819E3 /* NSStringBranchTests.m */; }; 4D1683CA2098C902008819E3 /* BNCPreferenceHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683A02098C901008819E3 /* BNCPreferenceHelperTests.m */; }; 4D1851C120180F3300E48994 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D1851BF20180F0600E48994 /* Security.framework */; }; 4D35141C1E3201D80085EBA1 /* NSMutableDictionary+Branch.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D35141A1E3201D80085EBA1 /* NSMutableDictionary+Branch.m */; }; @@ -96,8 +93,6 @@ 4DCAC8311F426F7C00405D1D /* NSString+Branch.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DA577201E67B28700A43BDD /* NSString+Branch.h */; }; 4DCF4AFB1F4388F600AF9AAB /* BranchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DCF4AF91F4388F600AF9AAB /* BranchEvent.m */; }; 4DCF4B031F438A8700AF9AAB /* BranchEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DCF4AF81F4388F600AF9AAB /* BranchEvent.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4DD056122177A65C009BD3DD /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DD056112177A65C009BD3DD /* libOCMock.a */; }; - 4DD056142177A65C009BD3DD /* libOHHTTPStubs.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DD056132177A65C009BD3DD /* libOHHTTPStubs.a */; }; 4DE235641FB12C2700D4E5A9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4DBEFFFB1FB12A1000F7C41B /* Main.storyboard */; }; 4DE6491A1FE1D7F500226507 /* BNCFieldDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DE649191FE1D7F500226507 /* BNCFieldDefines.h */; }; 54391A161BA249FA0061CB0F /* BranchCSSearchableItemAttributeSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 54391A141BA249FA0061CB0F /* BranchCSSearchableItemAttributeSet.m */; }; @@ -157,7 +152,7 @@ 5F83B9ED2433BAAA0054A022 /* BNCServerInterface.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16837E2098C901008819E3 /* BNCServerInterface.Test.m */; }; 5F892EBE2361157E0023AEC1 /* NSError+Branch.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F892EBC2361157D0023AEC1 /* NSError+Branch.m */; }; 5F892EBF2361157E0023AEC1 /* NSError+Branch.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F892EBD2361157D0023AEC1 /* NSError+Branch.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5F892EC5236116CD0023AEC1 /* NSErrorBranchCategoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F892EC4236116CC0023AEC1 /* NSErrorBranchCategoryTests.m */; }; + 5F892EC5236116CD0023AEC1 /* NSErrorBranchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F892EC4236116CC0023AEC1 /* NSErrorBranchTests.m */; }; 5F8B7B4021B5F5CD009CE0A6 /* libBranch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 466B58381B17773000A69EDE /* libBranch.a */; }; 5F8B7B4721B5F5F0009CE0A6 /* Branch_setBranchKeyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F8B7B4621B5F5F0009CE0A6 /* Branch_setBranchKeyTests.m */; }; 5F8BB66E278771890055D2DC /* BNCKeyChainTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F8BB66D278771890055D2DC /* BNCKeyChainTests.m */; }; @@ -228,8 +223,8 @@ C12320B52808DB90007771C0 /* BranchQRCodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C12320B42808DB90007771C0 /* BranchQRCodeTests.m */; }; C12320B7280E2060007771C0 /* BranchQRCode.h in Headers */ = {isa = PBXBuildFile; fileRef = C12320B6280E2060007771C0 /* BranchQRCode.h */; settings = {ATTRIBUTES = (Public, ); }; }; C12320B9280E2091007771C0 /* BranchQRCode.m in Sources */ = {isa = PBXBuildFile; fileRef = C12320B8280E2091007771C0 /* BranchQRCode.m */; }; - C15CC9E02ABCF8C8003CC339 /* BranchActivityItemTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C15CC9DF2ABCF8C8003CC339 /* BranchActivityItemTests.m */; }; C15CC9DE2ABCB549003CC339 /* BNCCurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C15CC9DD2ABCB549003CC339 /* BNCCurrencyTests.m */; }; + C15CC9E02ABCF8C8003CC339 /* BranchActivityItemTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C15CC9DF2ABCF8C8003CC339 /* BranchActivityItemTests.m */; }; C1614D56285BC8A00098946B /* LinkPresentation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1614D55285BC8A00098946B /* LinkPresentation.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; C1614D5C285BD4AF0098946B /* BranchPluginSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = C1614D5A285BD4AF0098946B /* BranchPluginSupport.h */; }; C1614D5D285BD4AF0098946B /* BranchPluginSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = C1614D5B285BD4AF0098946B /* BranchPluginSupport.m */; }; @@ -243,7 +238,6 @@ C1CC888229BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C1CC888129BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m */; }; C1CC888829C27E8000BDD2B5 /* BNCUrlQueryParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = C1CC888629C27E8000BDD2B5 /* BNCUrlQueryParameter.h */; }; C1CC888929C27E8000BDD2B5 /* BNCUrlQueryParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = C1CC888729C27E8000BDD2B5 /* BNCUrlQueryParameter.m */; }; - CE09D25C88071212954A776D /* libPods-Branch-SDK-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F2C896423B99BFA2E8B0E4D6 /* libPods-Branch-SDK-Tests.a */; }; E2B9474A1D15D75000F2270D /* BNCCallbacks.h in Headers */ = {isa = PBXBuildFile; fileRef = E2B947491D15D73900F2270D /* BNCCallbacks.h */; settings = {ATTRIBUTES = (Public, ); }; }; E72489D228E40D0200DCD8FD /* PasteControlViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E72489D128E40D0200DCD8FD /* PasteControlViewController.m */; }; E729974D28E2BBFA007D91B2 /* BranchPasteControl.h in Headers */ = {isa = PBXBuildFile; fileRef = E729974B28E2BBFA007D91B2 /* BranchPasteControl.h */; }; @@ -318,7 +312,6 @@ 0372078725E9F81000F29C30 /* UITestCaseMisc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UITestCaseMisc.m; sourceTree = ""; }; 0399DD112599BF8A00CDB36E /* UITestSendV2Event.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UITestSendV2Event.m; sourceTree = ""; }; 03B49EEA25F9F315000BF105 /* UITestCase0OpenNInstall.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UITestCase0OpenNInstall.m; sourceTree = ""; }; - 130D24DFC422D39DC8CB96CC /* Pods-Branch-SDK-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Branch-SDK-Tests.debug.xcconfig"; path = "Target Support Files/Pods-Branch-SDK-Tests/Pods-Branch-SDK-Tests.debug.xcconfig"; sourceTree = ""; }; 3A78D573251EB59B002A25CF /* BranchJsonConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BranchJsonConfig.h; sourceTree = ""; }; 3A78D575251EB5BF002A25CF /* BranchJsonConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BranchJsonConfig.m; sourceTree = ""; }; 464EA3991ACB38EC000E4094 /* BNCEncodingUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCEncodingUtils.h; sourceTree = ""; }; @@ -330,7 +323,6 @@ 466D5A101B5991E3009DB845 /* BNCContentDiscoveryManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCContentDiscoveryManager.m; sourceTree = ""; }; 46DBB42F1B335A9B00642FC8 /* BranchDeepLinkingController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BranchDeepLinkingController.h; sourceTree = ""; }; 4AB16367239E3A2700D42931 /* DispatchToIsolationQueueTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DispatchToIsolationQueueTests.m; sourceTree = ""; }; - 4D16837B2098C901008819E3 /* BranchSetIdentityTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchSetIdentityTests.m; sourceTree = ""; }; 4D16837D2098C901008819E3 /* BNCServerRequestQueueOldTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCServerRequestQueueOldTests.m; sourceTree = ""; }; 4D16837E2098C901008819E3 /* BNCServerInterface.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCServerInterface.Test.m; sourceTree = ""; }; 4D16837F2098C901008819E3 /* BranchOpenRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchOpenRequestTests.m; sourceTree = ""; }; @@ -340,17 +332,15 @@ 4D1683862098C901008819E3 /* BranchSDKFunctionalityTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchSDKFunctionalityTests.m; sourceTree = ""; }; 4D16838C2098C901008819E3 /* BNCURLFilterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCURLFilterTests.m; sourceTree = ""; }; 4D16838D2098C901008819E3 /* BNCTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCTestCase.m; sourceTree = ""; }; - 4D16838E2098C901008819E3 /* BNCEncodingUtils.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCEncodingUtils.Test.m; sourceTree = ""; }; + 4D16838E2098C901008819E3 /* BNCEncodingUtilsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCEncodingUtilsTests.m; sourceTree = ""; }; 4D16838F2098C901008819E3 /* BNCSystemObserverTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCSystemObserverTests.m; sourceTree = ""; }; - 4D1683902098C901008819E3 /* BNCLog.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCLog.Test.m; sourceTree = ""; }; - 4D1683922098C901008819E3 /* BranchDelegate.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchDelegate.Test.m; sourceTree = ""; }; - 4D1683932098C901008819E3 /* BranchNetworkScenario.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchNetworkScenario.Test.m; sourceTree = ""; }; + 4D1683902098C901008819E3 /* BNCLogTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCLogTests.m; sourceTree = ""; }; 4D1683952098C901008819E3 /* BranchEvent.Test.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BranchEvent.Test.swift; sourceTree = ""; }; - 4D1683962098C901008819E3 /* BranchUniversalObject.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchUniversalObject.Test.m; sourceTree = ""; }; - 4D1683972098C901008819E3 /* BNCApplication.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCApplication.Test.m; sourceTree = ""; }; + 4D1683962098C901008819E3 /* BranchUniversalObjectTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchUniversalObjectTests.m; sourceTree = ""; }; + 4D1683972098C901008819E3 /* BNCApplicationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCApplicationTests.m; sourceTree = ""; }; 4D16839C2098C901008819E3 /* BranchEvent.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchEvent.Test.m; sourceTree = ""; }; - 4D16839D2098C901008819E3 /* BNCCrashlyticsWrapper.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCCrashlyticsWrapper.Test.m; sourceTree = ""; }; - 4D16839E2098C901008819E3 /* NSString+Branch.Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Branch.Test.m"; sourceTree = ""; }; + 4D16839D2098C901008819E3 /* BNCCrashlyticsWrapperTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCCrashlyticsWrapperTests.m; sourceTree = ""; }; + 4D16839E2098C901008819E3 /* NSStringBranchTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSStringBranchTests.m; sourceTree = ""; }; 4D16839F2098C901008819E3 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 4D1683A02098C901008819E3 /* BNCPreferenceHelperTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCPreferenceHelperTests.m; sourceTree = ""; }; 4D1683A12098C901008819E3 /* BNCTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCTestCase.h; sourceTree = ""; }; @@ -451,7 +441,7 @@ 5F73FC8023314697000EBD32 /* BNCJSONUtilityTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCJSONUtilityTests.m; sourceTree = ""; }; 5F892EBC2361157D0023AEC1 /* NSError+Branch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Branch.m"; sourceTree = ""; }; 5F892EBD2361157D0023AEC1 /* NSError+Branch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Branch.h"; sourceTree = ""; }; - 5F892EC4236116CC0023AEC1 /* NSErrorBranchCategoryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSErrorBranchCategoryTests.m; sourceTree = ""; }; + 5F892EC4236116CC0023AEC1 /* NSErrorBranchTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSErrorBranchTests.m; sourceTree = ""; }; 5F8B7B3B21B5F5CD009CE0A6 /* Branch-SDK-Unhosted-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Branch-SDK-Unhosted-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 5F8B7B3F21B5F5CD009CE0A6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5F8B7B4621B5F5F0009CE0A6 /* Branch_setBranchKeyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Branch_setBranchKeyTests.m; sourceTree = ""; }; @@ -523,7 +513,6 @@ 677F4CB41C1FB0FA0029F2B3 /* Branch-TestBed.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Branch-TestBed.entitlements"; sourceTree = ""; }; 67BBCF271A69E49A009C7DAE /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 67F270881BA9FCFF002546A7 /* CoreSpotlight.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreSpotlight.framework; path = System/Library/Frameworks/CoreSpotlight.framework; sourceTree = SDKROOT; }; - 713E79E4D7BF588897570949 /* Pods-Branch-SDK-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Branch-SDK-Tests.release.xcconfig"; path = "Target Support Files/Pods-Branch-SDK-Tests/Pods-Branch-SDK-Tests.release.xcconfig"; sourceTree = ""; }; 7B18DF471F1F00E200C25C84 /* BNCCrashlyticsWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCCrashlyticsWrapper.h; sourceTree = ""; }; 7B18DF481F1F00E200C25C84 /* BNCCrashlyticsWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCCrashlyticsWrapper.m; sourceTree = ""; }; 7D5882301CA1BEEA00FF6358 /* BNCDeviceInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCDeviceInfo.h; sourceTree = ""; }; @@ -547,8 +536,8 @@ C12320B42808DB90007771C0 /* BranchQRCodeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BranchQRCodeTests.m; sourceTree = ""; }; C12320B6280E2060007771C0 /* BranchQRCode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BranchQRCode.h; sourceTree = ""; }; C12320B8280E2091007771C0 /* BranchQRCode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BranchQRCode.m; sourceTree = ""; }; - C15CC9DF2ABCF8C8003CC339 /* BranchActivityItemTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BranchActivityItemTests.m; sourceTree = ""; }; C15CC9DD2ABCB549003CC339 /* BNCCurrencyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCCurrencyTests.m; sourceTree = ""; }; + C15CC9DF2ABCF8C8003CC339 /* BranchActivityItemTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BranchActivityItemTests.m; sourceTree = ""; }; C1614D55285BC8A00098946B /* LinkPresentation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LinkPresentation.framework; path = System/Library/Frameworks/LinkPresentation.framework; sourceTree = SDKROOT; }; C1614D5A285BD4AF0098946B /* BranchPluginSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchPluginSupport.h; sourceTree = ""; }; C1614D5B285BD4AF0098946B /* BranchPluginSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchPluginSupport.m; sourceTree = ""; }; @@ -577,7 +566,6 @@ F1D3591E1ED4DCC500A93FD5 /* BNCDeepLinkViewControllerInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCDeepLinkViewControllerInstance.h; sourceTree = ""; }; F1D3591F1ED4DCC500A93FD5 /* BNCDeepLinkViewControllerInstance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCDeepLinkViewControllerInstance.m; sourceTree = ""; }; F1D4F9AC1F323F01002D13FF /* Branch-TestBed-UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Branch-TestBed-UITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - F2C896423B99BFA2E8B0E4D6 /* libPods-Branch-SDK-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Branch-SDK-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -626,9 +614,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 4DD056122177A65C009BD3DD /* libOCMock.a in Frameworks */, - 4DD056142177A65C009BD3DD /* libOHHTTPStubs.a in Frameworks */, - CE09D25C88071212954A776D /* libPods-Branch-SDK-Tests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -646,23 +631,22 @@ 4D16837A2098C901008819E3 /* Branch-SDK-Tests */ = { isa = PBXGroup; children = ( - E7A728BC2AA9A112009343B7 /* BNCAPIServerTest.m */, 5FC7326F22DD1F93006E6FBC /* BNCAppleReceiptTests.m */, - 4D1683972098C901008819E3 /* BNCApplication.Test.m */, + 4D1683972098C901008819E3 /* BNCApplicationTests.m */, 4D7881FB209CF2D4002B750F /* BNCApplication+BNCTest.h */, 4D7881FC209CF2D4002B750F /* BNCApplication+BNCTest.m */, 5FE694372405FA2700E3AEE2 /* BNCCallbackMapTests.m */, - 4D16839D2098C901008819E3 /* BNCCrashlyticsWrapper.Test.m */, + 4D16839D2098C901008819E3 /* BNCCrashlyticsWrapperTests.m */, 5F92B241238752A500CA909B /* BNCDeviceInfoTests.m */, 5F437E3F237E1A560052064B /* BNCDeviceSystemTests.m */, 5F2035CB240DDE90004FDC3E /* BNCDisableAdNetworkCalloutsTests.m */, - 4D16838E2098C901008819E3 /* BNCEncodingUtils.Test.m */, + 4D16838E2098C901008819E3 /* BNCEncodingUtilsTests.m */, 5F3D6719233062FD00454FF1 /* BNCJsonLoader.h */, 5F3D671A233062FD00454FF1 /* BNCJsonLoader.m */, 5F73FC8023314697000EBD32 /* BNCJSONUtilityTests.m */, 5F8BB66D278771890055D2DC /* BNCKeyChainTests.m */, 4D1683842098C901008819E3 /* BNCLinkDataTests.m */, - 4D1683902098C901008819E3 /* BNCLog.Test.m */, + 4D1683902098C901008819E3 /* BNCLogTests.m */, 5FA9112E29BC662000F3D35C /* BNCNetworkInterfaceTests.m */, 5FDF91582581CDF4009BE5A3 /* BNCPartnerParametersTests.m */, 5FD1786D26DEE49C009696E3 /* BNCPasteboardTests.m */, @@ -683,23 +667,20 @@ 4D16838C2098C901008819E3 /* BNCURLFilterTests.m */, 5F205D022318641700C776D1 /* BNCUserAgentCollectorTests.m */, 4D1683812098C901008819E3 /* Branch-SDK-Tests-Bridging-Header.h */, - 4D1683922098C901008819E3 /* BranchDelegate.Test.m */, 4D16839C2098C901008819E3 /* BranchEvent.Test.m */, 4D1683952098C901008819E3 /* BranchEvent.Test.swift */, 4D1683822098C901008819E3 /* BranchInstallRequestTests.m */, 5F909B712332BEF600A774D2 /* BranchLastAttributedTouchDataTests.m */, - 4D1683932098C901008819E3 /* BranchNetworkScenario.Test.m */, 4D16837F2098C901008819E3 /* BranchOpenRequestTests.m */, C10F393927A0872800BF5D36 /* BranchPluginSupportTests.m */, C12320B42808DB90007771C0 /* BranchQRCodeTests.m */, 4D1683862098C901008819E3 /* BranchSDKFunctionalityTests.m */, - 4D16837B2098C901008819E3 /* BranchSetIdentityTests.m */, C10C61A9282481FB00761D7E /* BranchShareLinkTests.m */, - 4D1683962098C901008819E3 /* BranchUniversalObject.Test.m */, + 4D1683962098C901008819E3 /* BranchUniversalObjectTests.m */, 4AB16367239E3A2700D42931 /* DispatchToIsolationQueueTests.m */, 4D16839F2098C901008819E3 /* Info.plist */, - 5F892EC4236116CC0023AEC1 /* NSErrorBranchCategoryTests.m */, - 4D16839E2098C901008819E3 /* NSString+Branch.Test.m */, + 5F892EC4236116CC0023AEC1 /* NSErrorBranchTests.m */, + 4D16839E2098C901008819E3 /* NSStringBranchTests.m */, E7A728BC2AA9A112009343B7 /* BNCAPIServerTest.m */, C15CC9DF2ABCF8C8003CC339 /* BranchActivityItemTests.m */, C17DAF7A2AC20C2000B16B1A /* BranchClassTests.m */, @@ -761,7 +742,6 @@ 5FC4CF7D24860C320001E701 /* cannedData */, 670016621940F51400A9E103 /* Frameworks */, 670016611940F51400A9E103 /* Products */, - D7B9BBDAF01EEBE97D55F0AF /* Pods */, ); sourceTree = ""; }; @@ -797,7 +777,6 @@ 670016631940F51400A9E103 /* Foundation.framework */, 670016651940F51400A9E103 /* CoreGraphics.framework */, 670016671940F51400A9E103 /* UIKit.framework */, - F2C896423B99BFA2E8B0E4D6 /* libPods-Branch-SDK-Tests.a */, ); name = Frameworks; sourceTree = ""; @@ -991,15 +970,6 @@ path = ../BranchSDK; sourceTree = ""; }; - D7B9BBDAF01EEBE97D55F0AF /* Pods */ = { - isa = PBXGroup; - children = ( - 130D24DFC422D39DC8CB96CC /* Pods-Branch-SDK-Tests.debug.xcconfig */, - 713E79E4D7BF588897570949 /* Pods-Branch-SDK-Tests.release.xcconfig */, - ); - path = Pods; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -1146,7 +1116,6 @@ isa = PBXNativeTarget; buildConfigurationList = 7E6B3B571AA42D0E005F45BF /* Build configuration list for PBXNativeTarget "Branch-SDK-Tests" */; buildPhases = ( - BF36CDEC6A8D1A1CF5E669A4 /* [CP] Check Pods Manifest.lock */, 7E6B3B4D1AA42D0E005F45BF /* Sources */, 7E6B3B4E1AA42D0E005F45BF /* Frameworks */, 7E6B3B4F1AA42D0E005F45BF /* Resources */, @@ -1308,28 +1277,6 @@ shellPath = /bin/sh; shellScript = "xcrun simctl terminate booted io.branch.sdk.Branch-TestBed\nxcrun simctl uninstall booted io.branch.sdk.Branch-TestBed\n"; }; - BF36CDEC6A8D1A1CF5E669A4 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Branch-SDK-Tests-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -1441,7 +1388,7 @@ files = ( 5F22AFC0240600A200837CF5 /* BNCCallbackMap.m in Sources */, 4D1683B72098C902008819E3 /* BNCTestCase.m in Sources */, - 4D1683B82098C902008819E3 /* BNCEncodingUtils.Test.m in Sources */, + 4D1683B82098C902008819E3 /* BNCEncodingUtilsTests.m in Sources */, 5F909B5E23314CE900A774D2 /* BNCJSONUtilityTests.m in Sources */, 5F909B722332BEF600A774D2 /* BranchLastAttributedTouchDataTests.m in Sources */, 4D7881FE209CF2D4002B750F /* BNCTestCase.Test.m in Sources */, @@ -1457,7 +1404,7 @@ 5F205D0823186AF700C776D1 /* BNCUserAgentCollectorTests.m in Sources */, 5FCF7EAD29DC96A7008D629E /* BNCURLFilterSkiplistUpgradeTests.m in Sources */, E7A728BD2AA9A112009343B7 /* BNCAPIServerTest.m in Sources */, - 4D1683C12098C902008819E3 /* BNCApplication.Test.m in Sources */, + 4D1683C12098C902008819E3 /* BNCApplicationTests.m in Sources */, 4D1683B92098C902008819E3 /* BNCSystemObserverTests.m in Sources */, 4D1683CA2098C902008819E3 /* BNCPreferenceHelperTests.m in Sources */, 4AB16368239E3A2700D42931 /* DispatchToIsolationQueueTests.m in Sources */, @@ -1466,28 +1413,25 @@ 5FE694382405FA2700E3AEE2 /* BNCCallbackMapTests.m in Sources */, 5FDB04F424E6156800F2F267 /* BNCSKAdNetworkTests.m in Sources */, 5FB6CC13264F0C7C0020E478 /* BNCServerRequestQueueTests.m in Sources */, - 4D1683BA2098C902008819E3 /* BNCLog.Test.m in Sources */, + 4D1683BA2098C902008819E3 /* BNCLogTests.m in Sources */, 4D1683AE2098C902008819E3 /* BNCLinkDataTests.m in Sources */, - 4D1683BD2098C902008819E3 /* BranchNetworkScenario.Test.m in Sources */, 4D7881FF209CF2D4002B750F /* BNCApplication+BNCTest.m in Sources */, C15CC9E02ABCF8C8003CC339 /* BranchActivityItemTests.m in Sources */, 5F92B23423835FEB00CA909B /* BNCReachabilityTests.m in Sources */, C17DAF7B2AC20C2000B16B1A /* BranchClassTests.m in Sources */, C12320B52808DB90007771C0 /* BranchQRCodeTests.m in Sources */, 5F3D671B233062FD00454FF1 /* BNCJsonLoader.m in Sources */, - 4D1683C02098C902008819E3 /* BranchUniversalObject.Test.m in Sources */, + 4D1683C02098C902008819E3 /* BranchUniversalObjectTests.m in Sources */, 5FC7327022DD1F93006E6FBC /* BNCAppleReceiptTests.m in Sources */, - 4D1683C82098C902008819E3 /* NSString+Branch.Test.m in Sources */, - 5F892EC5236116CD0023AEC1 /* NSErrorBranchCategoryTests.m in Sources */, + 4D1683C82098C902008819E3 /* NSStringBranchTests.m in Sources */, + 5F892EC5236116CD0023AEC1 /* NSErrorBranchTests.m in Sources */, 4D1683AA2098C902008819E3 /* BranchOpenRequestTests.m in Sources */, 4D1683A82098C902008819E3 /* BNCServerRequestQueueOldTests.m in Sources */, - 4D1683A62098C902008819E3 /* BranchSetIdentityTests.m in Sources */, - 4D1683BC2098C902008819E3 /* BranchDelegate.Test.m in Sources */, 4D1683B62098C902008819E3 /* BNCURLFilterTests.m in Sources */, C10C61AA282481FB00761D7E /* BranchShareLinkTests.m in Sources */, 5F437E40237E1A560052064B /* BNCDeviceSystemTests.m in Sources */, 4D1683AC2098C902008819E3 /* BranchInstallRequestTests.m in Sources */, - 4D1683C72098C902008819E3 /* BNCCrashlyticsWrapper.Test.m in Sources */, + 4D1683C72098C902008819E3 /* BNCCrashlyticsWrapperTests.m in Sources */, 5FDF91592581CDF4009BE5A3 /* BNCPartnerParametersTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1801,7 +1745,6 @@ }; 7E6B3B581AA42D0E005F45BF /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 130D24DFC422D39DC8CB96CC /* Pods-Branch-SDK-Tests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_WARN_UNREACHABLE_CODE = YES; @@ -1827,7 +1770,6 @@ }; 7E6B3B591AA42D0E005F45BF /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 713E79E4D7BF588897570949 /* Pods-Branch-SDK-Tests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_WARN_UNREACHABLE_CODE = YES; diff --git a/Branch-TestBed/Branch-TestBed.xcodeproj/xcshareddata/xcschemes/Branch-TestBed-CI.xcscheme b/Branch-TestBed/Branch-TestBed.xcodeproj/xcshareddata/xcschemes/Branch-TestBed-CI.xcscheme index b159d1b87..7fab3a2a5 100644 --- a/Branch-TestBed/Branch-TestBed.xcodeproj/xcshareddata/xcschemes/Branch-TestBed-CI.xcscheme +++ b/Branch-TestBed/Branch-TestBed.xcodeproj/xcshareddata/xcschemes/Branch-TestBed-CI.xcscheme @@ -114,8 +114,6 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" enableThreadSanitizer = "YES" - language = "ru" - region = "RU" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Branch-TestBed/Branch-TestBed.xcodeproj/xcshareddata/xcschemes/Branch-TestBed.xcscheme b/Branch-TestBed/Branch-TestBed.xcodeproj/xcshareddata/xcschemes/Branch-TestBed.xcscheme index 329bd6f00..1fd3b59c9 100644 --- a/Branch-TestBed/Branch-TestBed.xcodeproj/xcshareddata/xcschemes/Branch-TestBed.xcscheme +++ b/Branch-TestBed/Branch-TestBed.xcodeproj/xcshareddata/xcschemes/Branch-TestBed.xcscheme @@ -114,8 +114,6 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" enableThreadSanitizer = "YES" - language = "ru" - region = "RU" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Branch-TestBed/Branch-TestBed.xcworkspace/contents.xcworkspacedata b/Branch-TestBed/Branch-TestBed.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 1209a7cd1..000000000 --- a/Branch-TestBed/Branch-TestBed.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/Branch-TestBed/Branch-TestBed.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Branch-TestBed/Branch-TestBed.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d981003..000000000 --- a/Branch-TestBed/Branch-TestBed.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/Branch-TestBed/Podfile b/Branch-TestBed/Podfile deleted file mode 100644 index b618d26bc..000000000 --- a/Branch-TestBed/Podfile +++ /dev/null @@ -1,8 +0,0 @@ -source 'https://github.com/CocoaPods/Specs.git' -platform :ios, '8.0' - -target 'Branch-SDK-Tests' do - project 'Branch-TestBed' - pod 'OCMock', :inhibit_warnings => true - pod 'OHHTTPStubs' -end diff --git a/Branch-TestBed/Podfile.lock b/Branch-TestBed/Podfile.lock deleted file mode 100644 index 19f88d201..000000000 --- a/Branch-TestBed/Podfile.lock +++ /dev/null @@ -1,32 +0,0 @@ -PODS: - - OCMock (3.7.1) - - OHHTTPStubs (9.1.0): - - OHHTTPStubs/Default (= 9.1.0) - - OHHTTPStubs/Core (9.1.0) - - OHHTTPStubs/Default (9.1.0): - - OHHTTPStubs/Core - - OHHTTPStubs/JSON - - OHHTTPStubs/NSURLSession - - OHHTTPStubs/OHPathHelpers - - OHHTTPStubs/JSON (9.1.0): - - OHHTTPStubs/Core - - OHHTTPStubs/NSURLSession (9.1.0): - - OHHTTPStubs/Core - - OHHTTPStubs/OHPathHelpers (9.1.0) - -DEPENDENCIES: - - OCMock - - OHHTTPStubs - -SPEC REPOS: - https://github.com/CocoaPods/Specs.git: - - OCMock - - OHHTTPStubs - -SPEC CHECKSUMS: - OCMock: 75fbeaa46a9b11f8c182bbb1d1f7e9a35ccc9955 - OHHTTPStubs: 90eac6d8f2c18317baeca36698523dc67c513831 - -PODFILE CHECKSUM: 829cf437db3e2065c6c17ddea2f24b51cb0aecc0 - -COCOAPODS: 1.12.1 diff --git a/BranchSDK.podspec b/BranchSDK.podspec index 555f13065..94b161d61 100644 --- a/BranchSDK.podspec +++ b/BranchSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "BranchSDK" - s.version = "3.0.0" + s.version = "3.0.1" s.summary = "Create an HTTP URL for any piece of content in your app" s.description = <<-DESC - Want the highest possible conversions on your sharing feature? diff --git a/BranchSDK.xcodeproj/project.pbxproj b/BranchSDK.xcodeproj/project.pbxproj index 6c2392513..796471c83 100644 --- a/BranchSDK.xcodeproj/project.pbxproj +++ b/BranchSDK.xcodeproj/project.pbxproj @@ -1953,7 +1953,11 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.0.0; + MARKETING_VERSION = 3.0.1; + OTHER_LDFLAGS = ( + "-weak_framework", + LinkPresentation, + ); PRODUCT_BUNDLE_IDENTIFIER = io.branch.BranchSDK; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1984,7 +1988,11 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.0.0; + MARKETING_VERSION = 3.0.1; + OTHER_LDFLAGS = ( + "-weak_framework", + LinkPresentation, + ); PRODUCT_BUNDLE_IDENTIFIER = io.branch.BranchSDK; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -2186,7 +2194,11 @@ "@loader_path/Frameworks", ); MACH_O_TYPE = staticlib; - MARKETING_VERSION = 3.0.0; + MARKETING_VERSION = 3.0.1; + OTHER_LDFLAGS = ( + "-weak_framework", + LinkPresentation, + ); PRODUCT_BUNDLE_IDENTIFIER = io.branch.BranchSDK; PRODUCT_MODULE_NAME = BranchSDK; PRODUCT_NAME = BranchSDK; @@ -2221,7 +2233,11 @@ "@loader_path/Frameworks", ); MACH_O_TYPE = staticlib; - MARKETING_VERSION = 3.0.0; + MARKETING_VERSION = 3.0.1; + OTHER_LDFLAGS = ( + "-weak_framework", + LinkPresentation, + ); PRODUCT_BUNDLE_IDENTIFIER = io.branch.BranchSDK; PRODUCT_MODULE_NAME = BranchSDK; PRODUCT_NAME = BranchSDK; @@ -2254,7 +2270,11 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.0.0; + MARKETING_VERSION = 3.0.1; + OTHER_LDFLAGS = ( + "-weak_framework", + LinkPresentation, + ); PRODUCT_BUNDLE_IDENTIFIER = io.branch.BranchSDK; PRODUCT_NAME = BranchSDK; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -2285,7 +2305,11 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.0.0; + MARKETING_VERSION = 3.0.1; + OTHER_LDFLAGS = ( + "-weak_framework", + LinkPresentation, + ); PRODUCT_BUNDLE_IDENTIFIER = io.branch.BranchSDK; PRODUCT_NAME = BranchSDK; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/BranchSDK/BNCConfig.m b/BranchSDK/BNCConfig.m index ba11b7d30..b17c985b9 100644 --- a/BranchSDK/BNCConfig.m +++ b/BranchSDK/BNCConfig.m @@ -8,7 +8,7 @@ #include "BNCConfig.h" -NSString * const BNC_SDK_VERSION = @"3.0.0"; +NSString * const BNC_SDK_VERSION = @"3.0.1"; NSString * const BNC_LINK_URL = @"https://bnc.lt"; NSString * const BNC_CDN_URL = @"https://cdn.branch.io"; diff --git a/BranchSDK/BNCPreferenceHelper.h b/BranchSDK/BNCPreferenceHelper.h index 8f771db42..d7f56047b 100644 --- a/BranchSDK/BNCPreferenceHelper.h +++ b/BranchSDK/BNCPreferenceHelper.h @@ -77,8 +77,8 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); + (BNCPreferenceHelper *)sharedInstance; -- (void)setBranchAPIURL:(NSString*)branchAPIURL; -- (void)setPatternListURL:(NSString*)cdnURL; +- (void)setBranchAPIURL:(NSString *)url; +- (void)setPatternListURL:(NSString *)url; - (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value; - (NSMutableDictionary *)requestMetadataDictionary; diff --git a/BranchSDK/BNCPreferenceHelper.m b/BranchSDK/BNCPreferenceHelper.m index f67a01b02..fb7a3ca58 100644 --- a/BranchSDK/BNCPreferenceHelper.m +++ b/BranchSDK/BNCPreferenceHelper.m @@ -76,6 +76,9 @@ @interface BNCPreferenceHelper () { @property (strong, nonatomic) NSMutableDictionary *requestMetadataDictionary; @property (strong, nonatomic) NSMutableDictionary *instrumentationDictionary; +// unit tests run in parallel, causing issues with data stored to disk +@property (nonatomic, assign, readwrite) BOOL useStorage; + @end @implementation BNCPreferenceHelper @@ -119,6 +122,9 @@ + (BNCPreferenceHelper *)sharedInstance { dispatch_once(&onceToken, ^{ preferenceHelper = [[BNCPreferenceHelper alloc] init]; + + // the shared version read/writes data to storage + preferenceHelper.useStorage = YES; }); return preferenceHelper; @@ -135,6 +141,7 @@ - (instancetype)init { _persistPrefsQueue.maxConcurrentOperationCount = 1; self.disableAdNetworkCallouts = NO; + self.useStorage = NO; } return self; } @@ -149,10 +156,14 @@ - (void) dealloc { #pragma mark - API methods -- (void)setBranchAPIURL:(NSString*)branchAPIURL_ { - @synchronized (self) { - _branchAPIURL = [branchAPIURL_ copy]; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_API_URL value:_branchAPIURL]; +- (void)setBranchAPIURL:(NSString *)url { + if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ + @synchronized (self) { + _branchAPIURL = [url copy]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_API_URL value:_branchAPIURL]; + } + } else { + BNCLogWarning(@"Ignoring invalid custom API URL"); } } @@ -173,10 +184,14 @@ - (NSString *)branchAPIURL { } } -- (void)setPatternListURL:(NSString*)url { - @synchronized (self) { - _patternListURL = url; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_PATTERN_LIST_URL value:url]; +- (void)setPatternListURL:(NSString *)url { + if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ + @synchronized (self) { + _patternListURL = url; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_PATTERN_LIST_URL value:url]; + } + } else { + BNCLogWarning(@"Ignoring invalid custom CDN URL"); } } @@ -857,8 +872,7 @@ - (void)writeObjectToDefaults:(NSString *)key value:(NSObject *)value { @synchronized (self) { if (value) { self.persistenceDict[key] = value; - } - else { + } else { [self.persistenceDict removeObjectForKey:key]; } [self persistPrefsToDisk]; @@ -866,21 +880,23 @@ - (void)writeObjectToDefaults:(NSString *)key value:(NSObject *)value { } - (void)persistPrefsToDisk { - @synchronized (self) { - if (!self.persistenceDict) return; - - NSData *data = [self serializePrefDict:self.persistenceDict]; - if (!data) return; - - NSURL *prefsURL = [self.class.URLForPrefsFile copy]; - NSBlockOperation *newPersistOp = [NSBlockOperation blockOperationWithBlock:^ { - NSError *error = nil; - [data writeToURL:prefsURL options:NSDataWritingAtomic error:&error]; - if (error) { - BNCLogWarning([NSString stringWithFormat:@"Failed to persist preferences: %@.", error]); - } - }]; - [_persistPrefsQueue addOperation:newPersistOp]; + if (self.useStorage) { + @synchronized (self) { + if (!self.persistenceDict) return; + + NSData *data = [self serializePrefDict:self.persistenceDict]; + if (!data) return; + + NSURL *prefsURL = [self.class.URLForPrefsFile copy]; + NSBlockOperation *newPersistOp = [NSBlockOperation blockOperationWithBlock:^ { + NSError *error = nil; + [data writeToURL:prefsURL options:NSDataWritingAtomic error:&error]; + if (error) { + BNCLogWarning([NSString stringWithFormat:@"Failed to persist preferences: %@.", error]); + } + }]; + [_persistPrefsQueue addOperation:newPersistOp]; + } } } @@ -906,7 +922,11 @@ + (void) clearAll { - (NSMutableDictionary *)persistenceDict { @synchronized(self) { if (!_persistenceDict) { - _persistenceDict = [self deserializePrefDictFromData:[self loadPrefData]]; + if (self.useStorage) { + _persistenceDict = [self deserializePrefDictFromData:[self loadPrefData]]; + } else { + _persistenceDict = [[NSMutableDictionary alloc] init]; + } } return _persistenceDict; } @@ -942,6 +962,8 @@ - (NSMutableDictionary *)deserializePrefDictFromData:(NSData *)data { if (dict && [dict isKindOfClass:[NSDictionary class]]) { return [dict mutableCopy]; } else { + + // if nothing was loaded, default to an empty dictionary return [[NSMutableDictionary alloc] init]; } } diff --git a/BranchSDK/BNCURLFilter.h b/BranchSDK/BNCURLFilter.h index 17850ea7d..97bd2c1ad 100644 --- a/BranchSDK/BNCURLFilter.h +++ b/BranchSDK/BNCURLFilter.h @@ -7,35 +7,38 @@ @date February 14, 2018 @copyright Copyright © 2018 Branch. All rights reserved. */ - -#if __has_feature(modules) -@import Foundation; -#else #import -#endif + +NS_ASSUME_NONNULL_BEGIN @interface BNCURLFilter : NSObject /** @brief Checks if a given URL should be ignored. - + @param url The URL to be checked. @return Returns true if the provided URL should be ignored. -*/ -- (BOOL) shouldIgnoreURL:(NSURL*_Nullable)url; + */ +- (BOOL)shouldIgnoreURL:(NSURL *)url; /** @brief Returns the pattern that matches a URL, if any. - + @param url The URL to be checked. @return Returns the pattern matching the URL or `nil` if no patterns match. -*/ -- (NSString*_Nullable) patternMatchingURL:(NSURL*_Nullable)url; + */ +- (nullable NSString *)patternMatchingURL:(NSURL *)url; + +// Sets a list of ignored URL regex patterns +// Used for custom URL filtering and testing +- (void)useCustomPatternList:(NSArray *)patternList; -/// Refreshes the list of ignored URLs from the server. -- (void) updatePatternListWithCompletion:(void (^_Nullable) (NSError*_Nullable error, NSArray*_Nullable list))completion; +// Loads the saved list of ignored URL regex patterns +- (void)useSavedPatternList; + +// Refreshes the list of ignored URL regex patterns from the server +- (void)updatePatternListFromServerWithCompletion:(void (^_Nullable) (void))completion; -/// Is YES if the listed has already been updated from the server. -@property (assign, readonly, nonatomic) BOOL hasUpdatedPatternList; -@property (strong, nonatomic) NSArray*_Nullable patternList; @end + +NS_ASSUME_NONNULL_END diff --git a/BranchSDK/BNCURLFilter.m b/BranchSDK/BNCURLFilter.m index 0fa5c31ec..b5a80d4c3 100644 --- a/BranchSDK/BNCURLFilter.m +++ b/BranchSDK/BNCURLFilter.m @@ -12,171 +12,171 @@ #import "Branch.h" #import "BNCLog.h" -@interface BNCURLFilter () { - NSArray*_patternList; -} +@interface BNCURLFilter () + +@property (strong, nonatomic, readwrite) NSArray *patternList; + +// Is YES if the list has already been updated from the server, or is overridden with a custom list. +@property (nonatomic, assign, readwrite) BOOL hasUpdatedPatternList; + @property (strong, nonatomic) NSArray *ignoredURLRegex; @property (assign, nonatomic) NSInteger listVersion; -@property (strong, nonatomic) id networkService; -@property (assign, nonatomic) BOOL hasUpdatedPatternList; -@property (strong, nonatomic) NSError *error; -@property (strong, nonatomic) NSURL *jsonURL; + @end @implementation BNCURLFilter -- (instancetype) init { +- (instancetype)init { self = [super init]; if (!self) return self; + [self useDefaultPatternList]; + + return self; +} + +- (void)useDefaultPatternList { self.patternList = @[ - @"^fb\\d+:((?!campaign_ids).)*$", - @"^li\\d+:", - @"^pdk\\d+:", - @"^twitterkit-.*:", - @"^com\\.googleusercontent\\.apps\\.\\d+-.*:\\/oauth", + @"^fb\\d+:((?!campaign_ids).)*$", // Facebook + @"^li\\d+:", // LinkedIn - deprecated + @"^pdk\\d+:", // Pinterest - deprecated + @"^twitterkit-.*:", // TwitterKit - deprecated + @"^com\\.googleusercontent\\.apps\\.\\d+-.*:\\/oauth", // Google @"^(?i)(?!(http|https):).*(:|:.*\\b)(password|o?auth|o?auth.?token|access|access.?token)\\b", @"^(?i)((http|https):\\/\\/).*[\\/|?|#].*\\b(password|o?auth|o?auth.?token|access|access.?token)\\b", ]; self.listVersion = -1; // First time always refresh the list version, version 0. - - NSArray *storedList = [BNCPreferenceHelper sharedInstance].savedURLPatternList; - if (storedList.count > 0) { - self.patternList = storedList; - self.listVersion = [BNCPreferenceHelper sharedInstance].savedURLPatternListVersion; - } - - NSError *error = nil; - _ignoredURLRegex = [self.class compileRegexArray:self.patternList error:&error]; - self.error = error; - - return self; -} - -- (void) dealloc { - [self.networkService cancelAllOperations]; - self.networkService = nil; -} - -- (void) setPatternList:(NSArray *)patternList { - @synchronized (self) { - _patternList = patternList; - _ignoredURLRegex = [self.class compileRegexArray:_patternList error:nil]; - } -} - -- (NSArray*) patternList { - @synchronized (self) { - return _patternList; - } + self.ignoredURLRegex = [self compileRegexArray:self.patternList]; } -+ (NSArray*) compileRegexArray:(NSArray*)patternList - error:(NSError*_Nullable __autoreleasing *_Nullable)error_ { - if (error_) *error_ = nil; - NSMutableArray *array = [NSMutableArray new]; +- (NSArray *)compileRegexArray:(NSArray *)patternList { + NSMutableArray *array = [NSMutableArray new]; for (NSString *pattern in patternList) { - NSError *error = nil; - NSRegularExpression *regex = - [NSRegularExpression regularExpressionWithPattern:pattern - options: NSRegularExpressionAnchorsMatchLines | NSRegularExpressionUseUnicodeWordBoundaries - error:&error]; - if (error || !regex) { - BNCLogError([NSString stringWithFormat:@"Invalid regular expression '%@': %@.", pattern, error]); - if (error_ && !*error_) *error_ = error; - } else { + NSError *regexError = nil; + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options: NSRegularExpressionAnchorsMatchLines | NSRegularExpressionUseUnicodeWordBoundaries error:®exError]; + + if (regex && !regexError) { [array addObject:regex]; + } else { + BNCLogError([NSString stringWithFormat:@"Invalid regular expression '%@': %@.", pattern, regexError]); } } return array; } -- (NSString*_Nullable) patternMatchingURL:(NSURL*_Nullable)url { +- (nullable NSString *)patternMatchingURL:(NSURL *)url { NSString *urlString = url.absoluteString; if (urlString == nil || urlString.length <= 0) return nil; + NSRange range = NSMakeRange(0, urlString.length); - for (NSRegularExpression* regex in self.ignoredURLRegex) { NSUInteger matches = [regex numberOfMatchesInString:urlString options:0 range:range]; if (matches > 0) return regex.pattern; } - + return nil; } -- (BOOL) shouldIgnoreURL:(NSURL *)url { +- (BOOL)shouldIgnoreURL:(NSURL *)url { return ([self patternMatchingURL:url]) ? YES : NO; } -- (void) updatePatternList { - [self updatePatternListWithCompletion:nil]; +- (void)useSavedPatternList { + NSArray *storedList = [BNCPreferenceHelper sharedInstance].savedURLPatternList; + if (storedList.count > 0) { + self.patternList = storedList; + self.listVersion = [BNCPreferenceHelper sharedInstance].savedURLPatternListVersion; + } + self.ignoredURLRegex = [self compileRegexArray:self.patternList]; } -- (void) updatePatternListWithCompletion:(void (^) (NSError*error, NSArray*list))completion { - @synchronized(self) { - if (self.hasUpdatedPatternList) { - if (completion) completion(self.error, self.patternList); - return; - } - self.hasUpdatedPatternList = YES; +- (void)useCustomPatternList:(NSArray *)patternList { + if (patternList.count > 0) { + self.patternList = patternList; + self.listVersion = 0; } + self.ignoredURLRegex = [self compileRegexArray:self.patternList]; +} + +#pragma mark Server update - self.error = nil; - NSString *urlString = [self.jsonURL absoluteString]; - if (!urlString) { - urlString = [NSString stringWithFormat:@"%@/sdk/uriskiplist_v%ld.json", [BNCPreferenceHelper sharedInstance].patternListURL, (long) self.listVersion+1]; +- (void)updatePatternListFromServerWithCompletion:(void (^_Nullable) (void))completion { + if (self.hasUpdatedPatternList) { + return; } - NSMutableURLRequest *request = - [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] - cachePolicy:NSURLRequestReloadIgnoringLocalCacheData - timeoutInterval:30.0]; - - self.networkService = [[Branch networkServiceClass] new]; - id operation = - [self.networkService networkOperationWithURLRequest:request completion: - ^(id operation) { - [self processServerOperation:operation]; - if (completion) completion(self.error, self.patternList); - [self.networkService cancelAllOperations]; - self.networkService = nil; - } - ]; + + NSString *urlString = [NSString stringWithFormat:@"%@/sdk/uriskiplist_v%ld.json", [BNCPreferenceHelper sharedInstance].patternListURL, (long) self.listVersion+1]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0]; + + __block id networkService = [[Branch networkServiceClass] new]; + id operation = [networkService networkOperationWithURLRequest:request completion: ^(id operation) { + [self processServerOperation:operation]; + if (completion) { + completion(); + } + }]; [operation start]; } -- (void) processServerOperation:(id)operation { - NSError *error = nil; - NSString *responseString = nil; - if (operation.responseData) - responseString = [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding]; - if (operation.response.statusCode == 404) { - BNCLogDebugSDK(@"No new URL ignore list found."); - } else { - BNCLogDebugSDK([NSString stringWithFormat:@"URL ignore list update result. Error: %@ status: %ld body:\n%@.", - operation.error, (long)operation.response.statusCode, responseString]); +- (BOOL)foundUpdatedURLList:(id)operation { + NSInteger statusCode = operation.response.statusCode; + NSError *error = operation.error; + NSString *jsonString = nil; + if (operation.responseData) { + jsonString = [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding]; } - if (operation.error || operation.responseData == nil || operation.response.statusCode != 200) { - self.error = operation.error; - return; + + if (statusCode == 404) { + BNCLogDebug([NSString stringWithFormat:@"No update for URL ignore list found."]); + return NO; + + } else if (statusCode != 200 || error != nil || jsonString == nil) { + BNCLogError([NSString stringWithFormat:@"Failed to update URL ignore list. error: %@ status: %ld", operation.error, (long)operation.response.statusCode]); + BNCLogDebug([NSString stringWithFormat:@"URL ignore JSON: %@", jsonString]); + return NO; + + } else { + return YES; } +} + +- (nullable NSDictionary *)parseJSONFromData:(NSData *)data { + NSError *error = nil; + NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; - NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:operation.responseData options:0 error:&error]; if (error) { - self.error = error; - BNCLogError([NSString stringWithFormat:@"Can't parse JSON: %@.", error]); - return; + BNCLogError([NSString stringWithFormat:@"Can't parse URL ignore JSON: %@.", error]); + return nil; } - + NSArray *urls = dictionary[@"uri_skip_list"]; - if (![urls isKindOfClass:NSArray.class]) return; - + if (![urls isKindOfClass:NSArray.class]) { + BNCLogError([NSString stringWithFormat:@"Can't parse URL ignore JSON, uri_skip_list is not a NSArray."]); + return nil; + } + NSNumber *version = dictionary[@"version"]; - if (![version isKindOfClass:NSNumber.class]) return; + if (![version isKindOfClass:NSNumber.class]) { + BNCLogError([NSString stringWithFormat:@"Can't parse URL ignore JSON, version is not a NSNumber."]); + return nil; + } + + return dictionary; +} - self.patternList = urls; - self.listVersion = [version longValue]; - [BNCPreferenceHelper sharedInstance].savedURLPatternList = self.patternList; - [BNCPreferenceHelper sharedInstance].savedURLPatternListVersion = self.listVersion; +- (void)processServerOperation:(id)operation { + if ([self foundUpdatedURLList:operation]) { + NSDictionary *json = [self parseJSONFromData:operation.responseData]; + if (json) { + self.hasUpdatedPatternList = YES; + self.patternList = json[@"uri_skip_list"]; + self.listVersion = (long)json[@"version"]; + self.ignoredURLRegex = [self compileRegexArray:self.patternList]; + + [BNCPreferenceHelper sharedInstance].savedURLPatternList = self.patternList; + [BNCPreferenceHelper sharedInstance].savedURLPatternListVersion = self.listVersion; + } + } } @end diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index 820376a8d..d4ab71e10 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -644,7 +644,7 @@ extern NSString * __nonnull const BNCSpotlightFeature; These are ICU standard regular expressions. */ -@property (copy, nullable) NSArray/*_Nullable*/* urlPatternsToIgnore; +- (void)setUrlPatternsToIgnore:(NSArray *)urlsToIgnore; /** Checks the pasteboard (clipboard) for a Branch Link on App Install. diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index 24bcf7ef0..da80d47ee 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -122,7 +122,6 @@ typedef NS_ENUM(NSInteger, BNCInitStatus) { @interface Branch() { NSInteger _networkCount; - BNCURLFilter *_userURLFilter; } // This isolation queue protects branch initialization and ensures things are processed in order. @@ -141,6 +140,8 @@ @interface Branch() { @property (strong, nonatomic) NSDictionary *deepLinkDebugParams; @property (strong, nonatomic) NSMutableArray *allowedSchemeList; @property (strong, nonatomic) BNCURLFilter *urlFilter; +@property (strong, nonatomic, readwrite) BNCURLFilter *userURLFilter; + @property (strong, nonatomic) BNCServerAPI *serverAPI; #if !TARGET_OS_TV @@ -207,6 +208,8 @@ - (id)initWithInterface:(BNCServerInterface *)interface self.class.branchKey = key; self.urlFilter = [BNCURLFilter new]; + [self.urlFilter useSavedPatternList]; + self.userURLFilter = nil; [BranchOpenRequest setWaitNeededForOpenResponseLock]; @@ -670,16 +673,8 @@ - (void)addAllowedScheme:(NSString *)scheme { } - (void)setUrlPatternsToIgnore:(NSArray*)urlsToIgnore { - @synchronized (self) { - _userURLFilter = [[BNCURLFilter alloc] init]; - _userURLFilter.patternList = urlsToIgnore; - } -} - -- (NSArray *)urlPatternsToIgnore { - @synchronized (self) { - return _userURLFilter.patternList; - } + self.userURLFilter = [[BNCURLFilter alloc] init]; + [self.userURLFilter useCustomPatternList:urlsToIgnore]; } // This is currently the same as handleDeeplink @@ -704,7 +699,7 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier NSString *pattern = nil; pattern = [self.urlFilter patternMatchingURL:url]; if (!pattern) { - pattern = [_userURLFilter patternMatchingURL:url]; + pattern = [self.userURLFilter patternMatchingURL:url]; } if (pattern) { self.preferenceHelper.dropURLOpen = YES; @@ -1738,6 +1733,7 @@ - (void)applicationDidBecomeActive { - (void)applicationWillResignActive { if (!Branch.trackingDisabled) { + self.initializationStatus = BNCInitStatusUninitialized; [self.requestQueue persistImmediately]; [BranchOpenRequest setWaitNeededForOpenResponseLock]; BNCLogDebugSDK(@"Application resigned active."); @@ -2095,10 +2091,7 @@ - (void)handleInitSuccessAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS } [self sendOpenNotificationWithLinkParameters:latestReferringParams error:nil]; - - if (!self.urlFilter.hasUpdatedPatternList) { - [self.urlFilter updatePatternListWithCompletion:nil]; - } + [self.urlFilter updatePatternListFromServerWithCompletion:nil]; if (self.shouldAutomaticallyDeepLink) { dispatch_async(dispatch_get_main_queue(), ^ { diff --git a/BranchSDK/BranchPluginSupport.m b/BranchSDK/BranchPluginSupport.m index 36b710c8b..ca07797ed 100644 --- a/BranchSDK/BranchPluginSupport.m +++ b/BranchSDK/BranchPluginSupport.m @@ -57,20 +57,12 @@ + (BranchPluginSupport *)instance { // With the change to support Apple's tracking domain feature, this API no longer works. See SDK-2118 // Overrides base API URL + (void)setAPIUrl:(NSString *)url { - if([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ - [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url]; - } else { - BNCLogWarning(@"Ignoring invalid custom API URL"); - } + [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url]; } // Overrides base CDN URL + (void)setCDNBaseUrl:(NSString *)url { - if([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ - [[BNCPreferenceHelper sharedInstance] setPatternListURL:url]; - } else { - BNCLogWarning(@"Ignoring invalid custom CDN URL"); - } + [[BNCPreferenceHelper sharedInstance] setPatternListURL:url]; } @end diff --git a/BranchSDK/BranchUniversalObject.m b/BranchSDK/BranchUniversalObject.m index 04327b186..8ac43afc6 100644 --- a/BranchSDK/BranchUniversalObject.m +++ b/BranchSDK/BranchUniversalObject.m @@ -106,7 +106,7 @@ - (NSDictionary*_Nonnull) dictionary { } + (BranchContentMetadata*_Nonnull) contentMetadataWithDictionary:(NSDictionary*_Nullable)dictionary { - BranchContentMetadata*object = [BranchContentMetadata new]; + BranchContentMetadata *object = [BranchContentMetadata new]; if (!dictionary) return object; #define BNCFieldDefinesObjectFromDictionary @@ -136,6 +136,49 @@ + (BranchContentMetadata*_Nonnull) contentMetadataWithDictionary:(NSDictionary*_ addStringArray(imageCaptions,$image_captions); #include "BNCFieldDefines.h" + + NSSet *fieldsAdded = [NSSet setWithArray:@[ + @"$canonical_identifier", + @"$canonical_url", + @"$creation_timestamp", + @"$exp_date", + @"$keywords", + @"$locally_indexable", + @"$og_description", + @"$og_image_url", + @"$og_title", + @"$publicly_indexable", + @"$content_schema", + @"$quantity", + @"$price", + @"$currency", + @"$sku", + @"$product_name", + @"$product_brand", + @"$product_category", + @"$product_variant", + @"$condition", + @"$rating_average", + @"$rating_count", + @"$rating_max", + @"$rating", + @"$address_street", + @"$address_city", + @"$address_region", + @"$address_country", + @"$address_postal_code", + @"$latitude", + @"$longitude", + @"$image_captions", + @"$custom_fields", + ]]; + + // Add any extra fields to the content object.contentMetadata.customMetadata + for (NSString *key in dictionary.keyEnumerator) { + if (![fieldsAdded containsObject:key]) { + object.customMetadata[key] = dictionary[key]; + } + } return object; } @@ -505,6 +548,7 @@ - (NSDictionary *)getDictionaryWithCompleteLinkProperties:(BranchLinkProperties return [temp copy]; } + - (void)safeSetValue:(NSObject *)value forKey:(NSString *)key onDict:(NSMutableDictionary *)dict { if (value) { dict[key] = value; @@ -533,50 +577,6 @@ + (BranchUniversalObject*_Nonnull) objectWithDictionary:(NSDictionary*_Null_unsp BranchContentMetadata *data = [BranchContentMetadata contentMetadataWithDictionary:dictionary]; object.contentMetadata = data; - NSSet *fieldsAdded = [NSSet setWithArray:@[ - @"$canonical_identifier", - @"$canonical_url", - @"$creation_timestamp", - @"$exp_date", - @"$keywords", - @"$locally_indexable", - @"$og_description", - @"$og_image_url", - @"$og_title", - @"$publicly_indexable", - @"$content_schema", - @"$quantity", - @"$price", - @"$currency", - @"$sku", - @"$product_name", - @"$product_brand", - @"$product_category", - @"$product_variant", - @"$condition", - @"$rating_average", - @"$rating_count", - @"$rating_max", - @"$rating", - @"$address_street", - @"$address_city", - @"$address_region", - @"$address_country", - @"$address_postal_code", - @"$latitude", - @"$longitude", - @"$image_captions", - @"$custom_fields", - ]]; - - // Add any extra fields to the content object.contentMetadata.customMetadata - - for (NSString* key in dictionary.keyEnumerator) { - if (![fieldsAdded containsObject:key]) { - object.contentMetadata.customMetadata[key] = dictionary[key]; - } - } - return object; } diff --git a/BranchSDK/NSError+Branch.h b/BranchSDK/NSError+Branch.h index 32f756955..610eff65e 100644 --- a/BranchSDK/NSError+Branch.h +++ b/BranchSDK/NSError+Branch.h @@ -35,7 +35,6 @@ typedef NS_ENUM(NSInteger, BNCErrorCode) { BNCHighestError }; -// This should be renamed. It's actually a category and not a class. @interface NSError (Branch) + (NSString *)bncErrorDomain; diff --git a/BranchSDK/NSError+Branch.m b/BranchSDK/NSError+Branch.m index 408a5a64b..524273842 100644 --- a/BranchSDK/NSError+Branch.m +++ b/BranchSDK/NSError+Branch.m @@ -21,7 +21,7 @@ + (NSString *)bncErrorDomain { } // Legacy error messages -+ (NSString *) messageForCode:(BNCErrorCode)code { ++ (NSString *)messageForCode:(BNCErrorCode)code { static NSMutableDictionary *messages; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -49,7 +49,7 @@ + (NSString *) messageForCode:(BNCErrorCode)code { return errorMessage; } -+ (NSError *) branchErrorWithCode:(BNCErrorCode)errorCode error:(NSError*)error localizedMessage:(NSString*_Nullable)message { ++ (NSError *)branchErrorWithCode:(BNCErrorCode)errorCode error:(NSError *)error localizedMessage:(NSString * _Nullable)message { NSMutableDictionary *userInfo = [NSMutableDictionary new]; NSString *localizedString = [self messageForCode:errorCode]; @@ -75,11 +75,11 @@ + (NSError *) branchErrorWithCode:(BNCErrorCode)errorCode { return [NSError branchErrorWithCode:errorCode error:nil localizedMessage:nil]; } -+ (NSError *) branchErrorWithCode:(BNCErrorCode)errorCode error:(NSError *_Nullable)error { ++ (NSError *) branchErrorWithCode:(BNCErrorCode)errorCode error:(NSError * _Nullable)error { return [NSError branchErrorWithCode:errorCode error:error localizedMessage:nil]; } -+ (NSError *) branchErrorWithCode:(BNCErrorCode)errorCode localizedMessage:(NSString *_Nullable)message { ++ (NSError *) branchErrorWithCode:(BNCErrorCode)errorCode localizedMessage:(NSString * _Nullable)message { return [NSError branchErrorWithCode:errorCode error:nil localizedMessage:message]; } diff --git a/BranchSDK/NSString+Branch.h b/BranchSDK/NSString+Branch.h index 369053f67..9c5a0e085 100644 --- a/BranchSDK/NSString+Branch.h +++ b/BranchSDK/NSString+Branch.h @@ -20,7 +20,7 @@ /// ignored for purposes of the compare. /// ///@return YES if string (ignoring any masked characters) is equal to the receiver. -- (BOOL) bnc_isEqualToMaskedString:(NSString*_Nullable)string; +- (BOOL)bnc_isEqualToMaskedString:(NSString * _Nullable)string; @end diff --git a/ChangeLog.md b/ChangeLog.md index 4d3aa4a2f..7482a929b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,9 @@ Branch iOS SDK Change Log -V.3.0.0 +v.3.0.1 +- Fix organic open when app is already running in background. + +v.3.0.0 - Add a Privacy Manifest for the Branch SDK. App developers may need add an App level Privacy Manifest for data they collect and pass into the Branch SDK. - Known Issue: When using cocoapods without the `use_frameworks!` option, the build can fail with a duplicate privacy manifest error. Workaround is to manually merge privacy manifests. @@ -21,13 +24,18 @@ V.3.0.0 - pre-iOS 10 locale support - Device carrier. This was used for fraud analysis, but is no longer available on new iOS versions. -V.2.2.1 +v.2.3.1 +This version is for a hotfix on Xamarin, it will not ship as a general iOS release. + +- SDK-2179 Fix LinkPresentation linker issue causing crash on Xamarin when run on iOS 12 or iOS 13. Thanks @LeadAssimilator. + +v.2.2.1 Branch iOS SDK 2.2.1 adds parameter for current SKAN 4.0 Window in /v1/open and /v2/event requests. - SDK-1982 - SKAN Simplification DB updates -V.2.2.0 +v.2.2.0 Branch iOS SDK 2.2.0 adds the ability to include developer ID in installs and a new method to change the Branch API base URL. @@ -35,7 +43,7 @@ Branch iOS SDK 2.2.0 adds the ability to include developer ID in installs and a - SDK-1755 - Remove old Apple Search Ads APIs - SDK-1934 - Expose a public method to change the Branch API base url -V.2.1.2 +v.2.1.2 Branch iOS SDK 2.1.2 adds additional support for Meta AEM links. It also includes some bug fixes and debugging improvements. diff --git a/fastlane/Fastfile b/fastlane/Fastfile index d7fce0fa8..6b9f7fda6 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -6,7 +6,7 @@ fastlane_version "2.69.0" lane :prepare_pods do # This helps optimize CI with caching by testing whether a pod install is necessary # from cocoapods_helper - pod_install_if_required '../Branch-TestBed' + # pod_install_if_required '../Branch-TestBed' # Can also turn on verbose output and disable repo update # pod_install_if_required '../Branch-TestBed', verbose: true, repo_update: false end @@ -19,7 +19,7 @@ lane :unit_tests do cobertura_xml: true, output_directory: "./fastlane/test_output", proj: "./Branch-TestBed/Branch-TestBed.xcodeproj", - workspace: "./Branch-TestBed/Branch-TestBed.xcworkspace", + #workspace: "./Branch-TestBed/Branch-TestBed.xcworkspace", scheme: "Branch-TestBed-CI" ) end diff --git a/fastlane/Scanfile b/fastlane/Scanfile index 83b068d38..11cd4873f 100644 --- a/fastlane/Scanfile +++ b/fastlane/Scanfile @@ -1,4 +1,4 @@ -workspace 'Branch-TestBed/Branch-TestBed.xcworkspace' +project 'Branch-TestBed/Branch-TestBed.xcodeproj' device 'iPhone 12' output_types 'junit,html' code_coverage true diff --git a/scripts/version.sh b/scripts/version.sh index e6e94ff8a..f2bd64133 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -30,7 +30,7 @@ Options: USAGE } -version=2.2.1 +version=3.0.1 prev_version="$version" if (( $# == 0 )); then @@ -107,7 +107,7 @@ if [[ $update ]]; then sed -i '' -e "/^[[:space:]]*s\.version/ {s/\".*\"/\"$version\"/; }" ../BranchSDK.podspec # Update framework version - sed -ie 's/MARKETING_VERSION = '"$prev_version"'/MARKETING_VERSION = '"$version"'/g' ../BranchSDK.xcodeproj/project.pbxproj + sed -i '' -e 's/MARKETING_VERSION = '"$prev_version"'/MARKETING_VERSION = '"$version"'/g' ../BranchSDK.xcodeproj/project.pbxproj fi