Skip to content

Commit

Permalink
Removed BranchDelegate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Oct 23, 2023
1 parent da6e7af commit a8dff3d
Showing 1 changed file with 163 additions and 163 deletions.
326 changes: 163 additions & 163 deletions Branch-TestBed/Branch-SDK-Tests/BranchDelegate.Test.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,169 +27,169 @@ @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;
}
//- (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

Expand Down

0 comments on commit a8dff3d

Please sign in to comment.