Skip to content

Commit

Permalink
Merge branch 'master' into SDK-2094
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch authored Oct 5, 2023
2 parents e192038 + b0525ec commit 4b4626b
Show file tree
Hide file tree
Showing 70 changed files with 1,490 additions and 2,296 deletions.
394 changes: 323 additions & 71 deletions Branch-TestBed/Branch-SDK-Tests/BNCAPIServerTest.m

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Branch-TestBed/Branch-SDK-Tests/BNCAppleReceiptTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ - (void)tearDown {

- (void)testReceiptOnSimulator {
BNCAppleReceipt *receipt = [[BNCAppleReceipt alloc] init];
XCTAssertNil([receipt installReceipt]);
// Appears the simulator can have a receipt
//XCTAssertNil([receipt installReceipt]);
XCTAssertFalse([receipt isTestFlight]);
}

Expand Down
17 changes: 0 additions & 17 deletions Branch-TestBed/Branch-SDK-Tests/BNCDeviceInfoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ - (void)testIsFirstOptIn {
XCTAssert(self.deviceInfo.isFirstOptIn == NO);
}

- (void)testIsAdTrackingEnabled {
// on iOS 14+, this is always NO
XCTAssert(self.deviceInfo.isAdTrackingEnabled == NO);
}

- (void)testLocalIPAddress {
NSString *address = [self.deviceInfo localIPAddress];
XCTAssertNotNil(address);
Expand Down Expand Up @@ -192,16 +187,4 @@ - (void)testRegisterPluginNameVersion {
XCTAssert([expectedVersion isEqualToString:self.deviceInfo.pluginVersion]);
}

// just a sanity check on the V2 dictionary
- (void)testV2Dictionary {
NSDictionary *dict = [self.deviceInfo v2dictionary];
XCTAssertNotNil(dict);
XCTAssertNotNil(dict[@"brand"]);
XCTAssertNotNil(dict[@"os"]);
XCTAssertNotNil(dict[@"sdk"]);
XCTAssertNotNil(dict[@"sdk_version"]);

XCTAssertNil(dict[@"disable_ad_network_callouts"]);
}

@end
16 changes: 5 additions & 11 deletions Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,16 @@ - (void)testPreferenceSets {
XCTAssertEqual(self.prefHelper.timeout, NSIntegerMax);
}

/*
// 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]);
NSString *customURL = @"https://banned.branch.io";
self.prefHelper.patternListURL = customURL;
XCTAssertTrue([customURL isEqualToString:self.prefHelper.patternListURL]);
}

// only verifies that the flag is stored correctly
// there are no tests to verify close calls are sent or omitted
- (void)testSendCloseRequests {
XCTAssertFalse(self.prefHelper.sendCloseRequests);
[self.prefHelper setSendCloseRequests:YES];
XCTAssertTrue(self.prefHelper.sendCloseRequests);

// restore to default
[self.prefHelper setSendCloseRequests:NO];
}
*/

- (void)testSerializeDict_Nil {
NSMutableDictionary *dict = nil;
Expand Down Expand Up @@ -210,6 +202,7 @@ - (void)testURLSkipList {
XCTAssert([filterDesc isEqualToString:valueDesc]);
}

/*
- (void)testSetAPIURL_Example {
NSString *url = @"https://www.example.com/";
Expand Down Expand Up @@ -265,5 +258,6 @@ - (void)testSetCDNBaseURL_InvalidEmpty {
XCTAssert(![urlStored isEqualToString:@""]);
XCTAssert([urlStored isEqualToString:BNC_CDN_URL]);
}
*/

@end
195 changes: 195 additions & 0 deletions Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
//
// BNCRequestFactoryTests.m
// Branch-SDK-Tests
//
// Created by Ernest Cho on 8/21/23.
// Copyright © 2023 Branch, Inc. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "BNCRequestFactory.h"

@interface BNCRequestFactoryTests : XCTestCase

@end

@implementation BNCRequestFactoryTests

- (void)setUp {

}

- (void)tearDown {

}

- (void)testInitWithBranchKeyNil {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil];
NSDictionary *json = [factory dataForInstall];
XCTAssertNotNil(json);

// key is omitted when nil
XCTAssertNil([json objectForKey:@"branch_key"]);
}

- (void)testInitWithBranchKeyEmpty {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@""];
NSDictionary *json = [factory dataForInstall];
XCTAssertNotNil(json);

// empty string is allowed
XCTAssertTrue([@"" isEqualToString:[json objectForKey:@"branch_key"]]);
}

- (void)testInitWithBranchKey {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForInstall];
XCTAssertNotNil(json);
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
}

- (void)testDataForInstall {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForInstall];
XCTAssertNotNil(json);

XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
XCTAssertNotNil([json objectForKey:@"sdk"]);
XCTAssertTrue([@"Apple" isEqualToString:[json objectForKey:@"brand"]]);
XCTAssertNotNil([json objectForKey:@"ios_vendor_id"]);

// not present on installs
XCTAssertNil([json objectForKey:@"randomized_bundle_token"]);
}

- (void)testDataForOpen {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForOpen];
XCTAssertNotNil(json);

XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
XCTAssertNotNil([json objectForKey:@"sdk"]);
XCTAssertTrue([@"Apple" isEqualToString:[json objectForKey:@"brand"]]);
XCTAssertNotNil([json objectForKey:@"ios_vendor_id"]);

// Present only on opens. Assumes test runs after the host app completes an install.
// This is not a reliable assumption on test runners
//XCTAssertNotNil([json objectForKey:@"randomized_bundle_token"]);
}

- (void)testDataForEvent {
NSDictionary *event = @{@"name": @"ADD_TO_CART"};

BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
XCTAssertNotNil(json);

XCTAssertTrue([@"ADD_TO_CART" isEqualToString:[json objectForKey:@"name"]]);

NSDictionary *userData = [json objectForKey:@"user_data"];
XCTAssertNotNil(userData);
XCTAssertNotNil([userData objectForKey:@"idfv"]);
}

- (void)testDataForEventWithContentItem {
NSDictionary *event = @{
@"name": @"ADD_TO_CART",
@"content_items": @[
@{
@"$og_title": @"TestTitle",
@"$quantity": @(2),
@"$product_name": @"TestProduct",
@"$price": @(10)
}
]
};

BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
XCTAssertNotNil(json);

XCTAssertTrue([@"ADD_TO_CART" isEqualToString:[json objectForKey:@"name"]]);

NSDictionary *contentItems = [json objectForKey:@"content_items"];
XCTAssertNotNil(contentItems);
XCTAssertTrue(contentItems.count == 1);

NSDictionary *userData = [json objectForKey:@"user_data"];
XCTAssertNotNil(userData);
XCTAssertNotNil([userData objectForKey:@"idfv"]);
}

- (void)testDataForEventWithTwoContentItem {
NSDictionary *event = @{
@"name": @"ADD_TO_CART",
@"content_items": @[
@{
@"$og_title": @"TestTitle1",
@"$quantity": @(2),
@"$product_name": @"TestProduct1",
@"$price": @(10)
},
@{
@"$og_title": @"TestTitle2",
@"$quantity": @(3),
@"$product_name": @"TestProduct2",
@"$price": @(20)
}
]
};

BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
XCTAssertNotNil(json);

XCTAssertTrue([@"ADD_TO_CART" isEqualToString:[json objectForKey:@"name"]]);

NSDictionary *contentItems = [json objectForKey:@"content_items"];
XCTAssertNotNil(contentItems);
XCTAssertTrue(contentItems.count == 2);

NSDictionary *userData = [json objectForKey:@"user_data"];
XCTAssertNotNil(userData);
XCTAssertNotNil([userData objectForKey:@"idfv"]);
}

- (void)testDataForEventEmpty {
NSDictionary *event = @{};

BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
XCTAssertNotNil(json);

XCTAssertNil([json objectForKey:@"name"]);

NSDictionary *userData = [json objectForKey:@"user_data"];
XCTAssertNotNil(userData);
XCTAssertNotNil([userData objectForKey:@"idfv"]);
}

- (void)testDataForEventNil {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForEventWithEventDictionary:nil];
XCTAssertNotNil(json);

XCTAssertNil([json objectForKey:@"name"]);

NSDictionary *userData = [json objectForKey:@"user_data"];
XCTAssertNotNil(userData);
XCTAssertNotNil([userData objectForKey:@"idfv"]);
}


- (void)testDataForShortURL {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForInstall];
XCTAssertNotNil(json);
}

- (void)testDataForLATD {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
NSDictionary *json = [factory dataForInstall];
XCTAssertNotNil(json);
}

@end
46 changes: 0 additions & 46 deletions Branch-TestBed/Branch-SDK-Tests/BNCServerInterface.Test.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,52 +347,6 @@ - (void)testPostRequestAsyncRetriesWhenInappropriateRetryCount {
[self waitForExpectationsWithTimeout:1.0 handler:nil];
}

//==================================================================================
// TEST 09
// Test certifcate pinning functionality.

// We do NOT pin by default anymore.
//- (void) testCertificatePinning {
//
// [OHHTTPStubs removeAllStubs];
// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init];
//
// XCTestExpectation* pinSuccess = [self expectationWithDescription:@"PinSuccess1"];
// [serverInterface getRequest:[NSDictionary new]
// url:@"https://branch.io"
// key:@""
// callback:^ (BNCServerResponse*response, NSError*error) {
// XCTAssertEqualObjects(response.statusCode, @200);
// [pinSuccess fulfill];
// }];
//
// XCTestExpectation* pinFail1 = [self expectationWithDescription:@"PinFail1"];
// [serverInterface getRequest:[NSDictionary new]
// url:@"https://google.com"
// key:@""
// callback:^ (BNCServerResponse*response, NSError*error) {
// XCTAssertEqualObjects(response.statusCode, @-999);
// [pinFail1 fulfill];
// }];
//
//#if 0
// // TODO: Fix so the end point so the test works on external (outside the Branch office) networks.
//
// XCTestExpectation* pinFail2 = [self expectationWithDescription:@"PinFail2"];
// [serverInterface getRequest:[NSDictionary new]
// url:@"https://internal-cert-pinning-test-470549067.us-west-1.elb.amazonaws.com/"
// key:@""
// callback:^ (BNCServerResponse*response, NSError*error) {
// XCTAssertEqualObjects(response.statusCode, @-999);
// //XCTAssertEqualObjects(response.statusCode, @200);
// [pinFail2 fulfill];
// }];
//#endif
//
// [self waitForExpectationsWithTimeout:10.0 handler:nil];
//}


//==================================================================================
// TEST 10
// Test mapping of X-Branch-Request-Id to [BNCServerResponse requestId]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#import "BNCTestCase.h"
#import "BNCServerRequestQueue.h"
#import "BranchOpenRequest.h"
#import "BranchCloseRequest.h"
#import <OCMock/OCMock.h>
#import "Branch.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#import <XCTest/XCTest.h>
#import "BNCServerRequestQueue.h"
#import "BNCServerRequest.h"
#import "BranchCloseRequest.h"

// Analytics requests
#import "BranchInstallRequest.h"
Expand Down
4 changes: 0 additions & 4 deletions Branch-TestBed/Branch-SDK-Tests/BNCSystemObserverTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ - (void)testIsSimulator_Simulator {
XCTAssert([BNCSystemObserver isSimulator]);
}

- (void)testAdTrackingEnabled {
XCTAssert(![BNCSystemObserver adTrackingEnabled]);
}

- (void)testAdvertiserIdentifier_NoATTPrompt {
XCTAssertNil([BNCSystemObserver advertiserIdentifier]);
}
Expand Down
5 changes: 4 additions & 1 deletion Branch-TestBed/Branch-SDK-Tests/BNCURLFilterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ - (void) tearDown {
[BNCPreferenceHelper sharedInstance].dropURLOpen = NO;
}

/*
// Test is unreliable when run in parallel with other tests, it's using a persistent datastore...
- (void)testListDownLoad {
XCTestExpectation *expectation = [self expectationWithDescription:@"List Download"];
BNCURLFilter *filter = [BNCURLFilter new];
[filter updatePatternListWithCompletion:^ (NSError*error, NSArray*list) {
XCTAssertNil(error);
XCTAssertTrue(list.count == 6);
XCTAssertTrue(list.count > 0);
[expectation fulfill];
}];
[self awaitExpectations];
}
*/

- (NSArray*) badURLs {
NSArray *kBadURLs = @[
Expand Down
Loading

0 comments on commit 4b4626b

Please sign in to comment.