Skip to content

Commit fc48967

Browse files
committed
SDK-842 add some tests
1 parent 8ef897c commit fc48967

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

Branch-SDK-Tests/BNCDeviceInfoTests.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ - (void)testV2Dictionary {
140140
XCTAssertNotNil([dict objectForKey:@"os"]);
141141
XCTAssertNotNil([dict objectForKey:@"sdk"]);
142142
XCTAssertNotNil([dict objectForKey:@"sdk_version"]);
143+
144+
XCTAssertNil([dict objectForKey:@"disable_ad_network_callouts"]);
143145
}
144146

145147
@end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// BNCDisableAdNetworkCalloutsTests.m
3+
// Branch-SDK-Tests
4+
//
5+
// Created by Ernest Cho on 3/2/20.
6+
// Copyright © 2020 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "BNCPreferenceHelper.h"
11+
#import "BNCDeviceInfo.h"
12+
#import "BNCServerInterface.h"
13+
14+
@interface BNCServerInterface()
15+
- (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict;
16+
@end
17+
18+
@interface BNCDisableAdNetworkCalloutsTests : XCTestCase
19+
20+
@end
21+
22+
// These tests are not parallelizable and therefore disabled by default
23+
// This is due to the tight coupling between BNCPreferenceHelper and BNCDeviceInfo
24+
@implementation BNCDisableAdNetworkCalloutsTests
25+
26+
- (void)setUp {
27+
[BNCPreferenceHelper preferenceHelper].disableAdNetworkCallouts = YES;
28+
}
29+
30+
- (void)tearDown {
31+
[BNCPreferenceHelper preferenceHelper].disableAdNetworkCallouts = NO;
32+
}
33+
34+
// check on the V2 dictionary
35+
- (void)testV2Dictionary {
36+
NSDictionary *dict = [[BNCDeviceInfo getInstance] v2dictionary];
37+
XCTAssertNotNil(dict);
38+
XCTAssertNotNil([dict objectForKey:@"brand"]);
39+
XCTAssertNotNil([dict objectForKey:@"os"]);
40+
XCTAssertNotNil([dict objectForKey:@"sdk"]);
41+
XCTAssertNotNil([dict objectForKey:@"sdk_version"]);
42+
43+
XCTAssertTrue([dict objectForKey:@"disable_ad_network_callouts"]);
44+
}
45+
46+
// check on V1 payload
47+
- (void)testV1Payload {
48+
BNCServerInterface *interface = [BNCServerInterface new];
49+
interface.preferenceHelper = [BNCPreferenceHelper preferenceHelper];
50+
51+
NSMutableDictionary *tmp = [NSMutableDictionary new];
52+
[interface updateDeviceInfoToMutableDictionary:tmp];
53+
54+
XCTAssertNotNil(tmp);
55+
XCTAssertTrue([tmp objectForKey:@"disable_ad_network_callouts"]);
56+
}
57+
58+
@end

Branch-SDK-Tests/BNCPreferenceHelperTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ - (void)testPreferenceDefaults {
2929
XCTAssertEqual(self.prefHelper.timeout, 5.5);
3030
XCTAssertEqual(self.prefHelper.retryInterval, 0);
3131
XCTAssertEqual(self.prefHelper.retryCount, 3);
32+
XCTAssertFalse(self.prefHelper.disableAdNetworkCallouts);
3233
}
3334

3435
- (void)testPreferenceSets {

Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@
445445
54FF1F901BD1DC320004CE2E /* BranchLinkProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchLinkProperties.m; sourceTree = "<group>"; };
446446
5F08460F23480008005B17E6 /* BNCTuneUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCTuneUtility.h; sourceTree = "<group>"; };
447447
5F08461023480008005B17E6 /* BNCTuneUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCTuneUtility.m; sourceTree = "<group>"; };
448+
5F2035CB240DDE90004FDC3E /* BNCDisableAdNetworkCalloutsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCDisableAdNetworkCalloutsTests.m; sourceTree = "<group>"; };
448449
5F205D022318641700C776D1 /* BNCUserAgentCollectorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCUserAgentCollectorTests.m; sourceTree = "<group>"; };
449450
5F205D04231864E800C776D1 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
450451
5F3D6712232C589100454FF1 /* BranchLastAttributedTouchData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchLastAttributedTouchData.m; sourceTree = "<group>"; };
@@ -763,6 +764,7 @@
763764
4AB16367239E3A2700D42931 /* DispatchToIsolationQueueTests.m */,
764765
5F437E39237DE3480052064B /* BNCTelephonyTests.m */,
765766
5F437E3F237E1A560052064B /* BNCDeviceSystemTests.m */,
767+
5F2035CB240DDE90004FDC3E /* BNCDisableAdNetworkCalloutsTests.m */,
766768
);
767769
name = "Branch-SDK-Tests";
768770
path = "../Branch-SDK-Tests";

Branch-TestBed/Branch-TestBed/AppDelegate.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ - (BOOL)application:(UIApplication *)application
2626
*/
2727

2828
// Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!!
29-
30-
//
3129
Branch *branch = [Branch getInstance];
3230

33-
3431
// test pre init support
3532
//[self testDispatchToIsolationQueue:branch]
3633

0 commit comments

Comments
 (0)