Skip to content

Commit 4b4626b

Browse files
Merge branch 'master' into SDK-2094
2 parents e192038 + b0525ec commit 4b4626b

File tree

70 files changed

+1490
-2296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1490
-2296
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCAPIServerTest.m

Lines changed: 323 additions & 71 deletions
Large diffs are not rendered by default.

Branch-TestBed/Branch-SDK-Tests/BNCAppleReceiptTests.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ - (void)tearDown {
2525

2626
- (void)testReceiptOnSimulator {
2727
BNCAppleReceipt *receipt = [[BNCAppleReceipt alloc] init];
28-
XCTAssertNil([receipt installReceipt]);
28+
// Appears the simulator can have a receipt
29+
//XCTAssertNil([receipt installReceipt]);
2930
XCTAssertFalse([receipt isTestFlight]);
3031
}
3132

Branch-TestBed/Branch-SDK-Tests/BNCDeviceInfoTests.m

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ - (void)testIsFirstOptIn {
8282
XCTAssert(self.deviceInfo.isFirstOptIn == NO);
8383
}
8484

85-
- (void)testIsAdTrackingEnabled {
86-
// on iOS 14+, this is always NO
87-
XCTAssert(self.deviceInfo.isAdTrackingEnabled == NO);
88-
}
89-
9085
- (void)testLocalIPAddress {
9186
NSString *address = [self.deviceInfo localIPAddress];
9287
XCTAssertNotNil(address);
@@ -192,16 +187,4 @@ - (void)testRegisterPluginNameVersion {
192187
XCTAssert([expectedVersion isEqualToString:self.deviceInfo.pluginVersion]);
193188
}
194189

195-
// just a sanity check on the V2 dictionary
196-
- (void)testV2Dictionary {
197-
NSDictionary *dict = [self.deviceInfo v2dictionary];
198-
XCTAssertNotNil(dict);
199-
XCTAssertNotNil(dict[@"brand"]);
200-
XCTAssertNotNil(dict[@"os"]);
201-
XCTAssertNotNil(dict[@"sdk"]);
202-
XCTAssertNotNil(dict[@"sdk_version"]);
203-
204-
XCTAssertNil(dict[@"disable_ad_network_callouts"]);
205-
}
206-
207190
@end

Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,16 @@ - (void)testPreferenceSets {
5252
XCTAssertEqual(self.prefHelper.timeout, NSIntegerMax);
5353
}
5454

55+
/*
56+
// This test is not reliable when run concurrently with other tests that set the patterListURL
5557
- (void)testURLFilter {
5658
XCTAssertTrue([@"https://cdn.branch.io" isEqualToString:self.prefHelper.patternListURL]);
5759
5860
NSString *customURL = @"https://banned.branch.io";
5961
self.prefHelper.patternListURL = customURL;
6062
XCTAssertTrue([customURL isEqualToString:self.prefHelper.patternListURL]);
6163
}
62-
63-
// only verifies that the flag is stored correctly
64-
// there are no tests to verify close calls are sent or omitted
65-
- (void)testSendCloseRequests {
66-
XCTAssertFalse(self.prefHelper.sendCloseRequests);
67-
[self.prefHelper setSendCloseRequests:YES];
68-
XCTAssertTrue(self.prefHelper.sendCloseRequests);
69-
70-
// restore to default
71-
[self.prefHelper setSendCloseRequests:NO];
72-
}
64+
*/
7365

7466
- (void)testSerializeDict_Nil {
7567
NSMutableDictionary *dict = nil;
@@ -210,6 +202,7 @@ - (void)testURLSkipList {
210202
XCTAssert([filterDesc isEqualToString:valueDesc]);
211203
}
212204

205+
/*
213206
- (void)testSetAPIURL_Example {
214207
215208
NSString *url = @"https://www.example.com/";
@@ -265,5 +258,6 @@ - (void)testSetCDNBaseURL_InvalidEmpty {
265258
XCTAssert(![urlStored isEqualToString:@""]);
266259
XCTAssert([urlStored isEqualToString:BNC_CDN_URL]);
267260
}
261+
*/
268262

269263
@end
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
//
2+
// BNCRequestFactoryTests.m
3+
// Branch-SDK-Tests
4+
//
5+
// Created by Ernest Cho on 8/21/23.
6+
// Copyright © 2023 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "BNCRequestFactory.h"
11+
12+
@interface BNCRequestFactoryTests : XCTestCase
13+
14+
@end
15+
16+
@implementation BNCRequestFactoryTests
17+
18+
- (void)setUp {
19+
20+
}
21+
22+
- (void)tearDown {
23+
24+
}
25+
26+
- (void)testInitWithBranchKeyNil {
27+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil];
28+
NSDictionary *json = [factory dataForInstall];
29+
XCTAssertNotNil(json);
30+
31+
// key is omitted when nil
32+
XCTAssertNil([json objectForKey:@"branch_key"]);
33+
}
34+
35+
- (void)testInitWithBranchKeyEmpty {
36+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@""];
37+
NSDictionary *json = [factory dataForInstall];
38+
XCTAssertNotNil(json);
39+
40+
// empty string is allowed
41+
XCTAssertTrue([@"" isEqualToString:[json objectForKey:@"branch_key"]]);
42+
}
43+
44+
- (void)testInitWithBranchKey {
45+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
46+
NSDictionary *json = [factory dataForInstall];
47+
XCTAssertNotNil(json);
48+
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
49+
}
50+
51+
- (void)testDataForInstall {
52+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
53+
NSDictionary *json = [factory dataForInstall];
54+
XCTAssertNotNil(json);
55+
56+
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
57+
XCTAssertNotNil([json objectForKey:@"sdk"]);
58+
XCTAssertTrue([@"Apple" isEqualToString:[json objectForKey:@"brand"]]);
59+
XCTAssertNotNil([json objectForKey:@"ios_vendor_id"]);
60+
61+
// not present on installs
62+
XCTAssertNil([json objectForKey:@"randomized_bundle_token"]);
63+
}
64+
65+
- (void)testDataForOpen {
66+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
67+
NSDictionary *json = [factory dataForOpen];
68+
XCTAssertNotNil(json);
69+
70+
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
71+
XCTAssertNotNil([json objectForKey:@"sdk"]);
72+
XCTAssertTrue([@"Apple" isEqualToString:[json objectForKey:@"brand"]]);
73+
XCTAssertNotNil([json objectForKey:@"ios_vendor_id"]);
74+
75+
// Present only on opens. Assumes test runs after the host app completes an install.
76+
// This is not a reliable assumption on test runners
77+
//XCTAssertNotNil([json objectForKey:@"randomized_bundle_token"]);
78+
}
79+
80+
- (void)testDataForEvent {
81+
NSDictionary *event = @{@"name": @"ADD_TO_CART"};
82+
83+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
84+
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
85+
XCTAssertNotNil(json);
86+
87+
XCTAssertTrue([@"ADD_TO_CART" isEqualToString:[json objectForKey:@"name"]]);
88+
89+
NSDictionary *userData = [json objectForKey:@"user_data"];
90+
XCTAssertNotNil(userData);
91+
XCTAssertNotNil([userData objectForKey:@"idfv"]);
92+
}
93+
94+
- (void)testDataForEventWithContentItem {
95+
NSDictionary *event = @{
96+
@"name": @"ADD_TO_CART",
97+
@"content_items": @[
98+
@{
99+
@"$og_title": @"TestTitle",
100+
@"$quantity": @(2),
101+
@"$product_name": @"TestProduct",
102+
@"$price": @(10)
103+
}
104+
]
105+
};
106+
107+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
108+
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
109+
XCTAssertNotNil(json);
110+
111+
XCTAssertTrue([@"ADD_TO_CART" isEqualToString:[json objectForKey:@"name"]]);
112+
113+
NSDictionary *contentItems = [json objectForKey:@"content_items"];
114+
XCTAssertNotNil(contentItems);
115+
XCTAssertTrue(contentItems.count == 1);
116+
117+
NSDictionary *userData = [json objectForKey:@"user_data"];
118+
XCTAssertNotNil(userData);
119+
XCTAssertNotNil([userData objectForKey:@"idfv"]);
120+
}
121+
122+
- (void)testDataForEventWithTwoContentItem {
123+
NSDictionary *event = @{
124+
@"name": @"ADD_TO_CART",
125+
@"content_items": @[
126+
@{
127+
@"$og_title": @"TestTitle1",
128+
@"$quantity": @(2),
129+
@"$product_name": @"TestProduct1",
130+
@"$price": @(10)
131+
},
132+
@{
133+
@"$og_title": @"TestTitle2",
134+
@"$quantity": @(3),
135+
@"$product_name": @"TestProduct2",
136+
@"$price": @(20)
137+
}
138+
]
139+
};
140+
141+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
142+
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
143+
XCTAssertNotNil(json);
144+
145+
XCTAssertTrue([@"ADD_TO_CART" isEqualToString:[json objectForKey:@"name"]]);
146+
147+
NSDictionary *contentItems = [json objectForKey:@"content_items"];
148+
XCTAssertNotNil(contentItems);
149+
XCTAssertTrue(contentItems.count == 2);
150+
151+
NSDictionary *userData = [json objectForKey:@"user_data"];
152+
XCTAssertNotNil(userData);
153+
XCTAssertNotNil([userData objectForKey:@"idfv"]);
154+
}
155+
156+
- (void)testDataForEventEmpty {
157+
NSDictionary *event = @{};
158+
159+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
160+
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
161+
XCTAssertNotNil(json);
162+
163+
XCTAssertNil([json objectForKey:@"name"]);
164+
165+
NSDictionary *userData = [json objectForKey:@"user_data"];
166+
XCTAssertNotNil(userData);
167+
XCTAssertNotNil([userData objectForKey:@"idfv"]);
168+
}
169+
170+
- (void)testDataForEventNil {
171+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
172+
NSDictionary *json = [factory dataForEventWithEventDictionary:nil];
173+
XCTAssertNotNil(json);
174+
175+
XCTAssertNil([json objectForKey:@"name"]);
176+
177+
NSDictionary *userData = [json objectForKey:@"user_data"];
178+
XCTAssertNotNil(userData);
179+
XCTAssertNotNil([userData objectForKey:@"idfv"]);
180+
}
181+
182+
183+
- (void)testDataForShortURL {
184+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
185+
NSDictionary *json = [factory dataForInstall];
186+
XCTAssertNotNil(json);
187+
}
188+
189+
- (void)testDataForLATD {
190+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
191+
NSDictionary *json = [factory dataForInstall];
192+
XCTAssertNotNil(json);
193+
}
194+
195+
@end

Branch-TestBed/Branch-SDK-Tests/BNCServerInterface.Test.m

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -347,52 +347,6 @@ - (void)testPostRequestAsyncRetriesWhenInappropriateRetryCount {
347347
[self waitForExpectationsWithTimeout:1.0 handler:nil];
348348
}
349349

350-
//==================================================================================
351-
// TEST 09
352-
// Test certifcate pinning functionality.
353-
354-
// We do NOT pin by default anymore.
355-
//- (void) testCertificatePinning {
356-
//
357-
// [OHHTTPStubs removeAllStubs];
358-
// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init];
359-
//
360-
// XCTestExpectation* pinSuccess = [self expectationWithDescription:@"PinSuccess1"];
361-
// [serverInterface getRequest:[NSDictionary new]
362-
// url:@"https://branch.io"
363-
// key:@""
364-
// callback:^ (BNCServerResponse*response, NSError*error) {
365-
// XCTAssertEqualObjects(response.statusCode, @200);
366-
// [pinSuccess fulfill];
367-
// }];
368-
//
369-
// XCTestExpectation* pinFail1 = [self expectationWithDescription:@"PinFail1"];
370-
// [serverInterface getRequest:[NSDictionary new]
371-
// url:@"https://google.com"
372-
// key:@""
373-
// callback:^ (BNCServerResponse*response, NSError*error) {
374-
// XCTAssertEqualObjects(response.statusCode, @-999);
375-
// [pinFail1 fulfill];
376-
// }];
377-
//
378-
//#if 0
379-
// // TODO: Fix so the end point so the test works on external (outside the Branch office) networks.
380-
//
381-
// XCTestExpectation* pinFail2 = [self expectationWithDescription:@"PinFail2"];
382-
// [serverInterface getRequest:[NSDictionary new]
383-
// url:@"https://internal-cert-pinning-test-470549067.us-west-1.elb.amazonaws.com/"
384-
// key:@""
385-
// callback:^ (BNCServerResponse*response, NSError*error) {
386-
// XCTAssertEqualObjects(response.statusCode, @-999);
387-
// //XCTAssertEqualObjects(response.statusCode, @200);
388-
// [pinFail2 fulfill];
389-
// }];
390-
//#endif
391-
//
392-
// [self waitForExpectationsWithTimeout:10.0 handler:nil];
393-
//}
394-
395-
396350
//==================================================================================
397351
// TEST 10
398352
// Test mapping of X-Branch-Request-Id to [BNCServerResponse requestId]

Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueOldTests.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import "BNCTestCase.h"
1010
#import "BNCServerRequestQueue.h"
1111
#import "BranchOpenRequest.h"
12-
#import "BranchCloseRequest.h"
1312
#import <OCMock/OCMock.h>
1413
#import "Branch.h"
1514

Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import <XCTest/XCTest.h>
1010
#import "BNCServerRequestQueue.h"
1111
#import "BNCServerRequest.h"
12-
#import "BranchCloseRequest.h"
1312

1413
// Analytics requests
1514
#import "BranchInstallRequest.h"

Branch-TestBed/Branch-SDK-Tests/BNCSystemObserverTests.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ - (void)testIsSimulator_Simulator {
7777
XCTAssert([BNCSystemObserver isSimulator]);
7878
}
7979

80-
- (void)testAdTrackingEnabled {
81-
XCTAssert(![BNCSystemObserver adTrackingEnabled]);
82-
}
83-
8480
- (void)testAdvertiserIdentifier_NoATTPrompt {
8581
XCTAssertNil([BNCSystemObserver advertiserIdentifier]);
8682
}

Branch-TestBed/Branch-SDK-Tests/BNCURLFilterTests.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ - (void) tearDown {
3232
[BNCPreferenceHelper sharedInstance].dropURLOpen = NO;
3333
}
3434

35+
/*
36+
// Test is unreliable when run in parallel with other tests, it's using a persistent datastore...
3537
- (void)testListDownLoad {
3638
XCTestExpectation *expectation = [self expectationWithDescription:@"List Download"];
3739
BNCURLFilter *filter = [BNCURLFilter new];
3840
[filter updatePatternListWithCompletion:^ (NSError*error, NSArray*list) {
3941
XCTAssertNil(error);
40-
XCTAssertTrue(list.count == 6);
42+
XCTAssertTrue(list.count > 0);
4143
[expectation fulfill];
4244
}];
4345
[self awaitExpectations];
4446
}
47+
*/
4548

4649
- (NSArray*) badURLs {
4750
NSArray *kBadURLs = @[

0 commit comments

Comments
 (0)