Skip to content

Commit c40ff5c

Browse files
author
Edward Smith
committed
Fixed some unit tests.
1 parent caaa07e commit c40ff5c

20 files changed

+83
-25
lines changed

Branch-SDK-Tests/BNCDeviceInfo.Test.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ - (void) testV2Dictionary {
134134
BNCPreferenceHelper *preferences = [BNCPreferenceHelper preferenceHelper];
135135

136136
NSMutableDictionary *truth = [self mutableDictionaryFromBundleJSONWithKey:@"BNCDeviceDictionaryV2"];
137-
truth[@"app_version"] = nil;//@"1.1";
137+
truth[@"app_version"] = @"1.1";
138138
truth[@"os_version"] = [UIDevice currentDevice].systemVersion;
139139
truth[@"sdk_version"] = BNC_SDK_VERSION;
140140
truth[@"developer_identity"] = preferences.userIdentity;

Branch-SDK-Tests/BNCKeyChain.Test.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ - (void)testKeyChain {
6262
value = [BNCKeyChain retrieveValueForService:kServiceName key:@"key2" error:&error];
6363
XCTAssertTrue(error == nil && [value isEqualToString:@"2xyz123"]);
6464

65+
error = [BNCKeyChain storeValue:@"3xyz123" forService:@"Service2" key:@"skey2" cloudAccessGroup:nil];
66+
XCTAssertTrue(error == nil);
67+
value = [BNCKeyChain retrieveValueForService:@"Service2" key:@"skey2" error:&error];
68+
XCTAssertTrue(error == nil && [value isEqualToString:@"3xyz123"]);
69+
6570
// Remove by service:
6671

6772
error = [BNCKeyChain removeValuesForService:kServiceName key:nil];

Branch-SDK-Tests/BNCTestCase.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
#import "BNCTestCase.h"
1212
#import "BNCLog.h"
13+
#import "Branch.h"
14+
15+
@interface Branch (BNCTest)
16+
+ (void) clearAll;
17+
@end
1318

1419
NSString* kTestStringResourceName = @"BNCTestCase"; // File is 'BNCTestCase.strings'. Omit the '.string'.
1520

@@ -99,17 +104,25 @@ + (BOOL) breakpointsAreEnabledInTests {
99104
return _breakpointsAreEnabledInTests;
100105
}
101106

107+
static NSString* savedIdentityID = nil;
108+
102109
+ (void) initialize {
103110
if (self != [BNCTestCase self]) return;
104111
BNCLogSetDisplayLevel(BNCLogLevelAll);
105112

106113
// Load test options from environment variables:
107-
108114
NSDictionary<NSString*, NSString*> *environment = [NSProcessInfo processInfo].environment;
109115
NSString *BNCTestBreakpoints = environment[@"BNCTestBreakpointsEnabled"];
110116
if ([BNCTestBreakpoints boolValue]) {
111117
_breakpointsAreEnabledInTests = YES;
112118
}
119+
120+
savedIdentityID = [BNCPreferenceHelper preferenceHelper].identityID;
121+
[Branch clearAll];
122+
}
123+
124+
+ (void)tearDown {
125+
[BNCPreferenceHelper preferenceHelper].identityID = savedIdentityID;
113126
}
114127

115128
@end

Branch-SDK-Tests/BNCURLBlackList.Test.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ - (void) testDownloadGoodURLs {
131131
}
132132

133133
- (void) testStandardBlackList {
134+
BNCLogSetDisplayLevel(BNCLogLevelAll);
134135
Branch *branch = [Branch getInstance:@"key_live_foo"];
135136
id serverInterfaceMock = OCMPartialMock(branch.serverInterface);
136137
XCTestExpectation *expectation = [self expectationWithDescription:@"OpenRequest Expectation"];
@@ -146,9 +147,10 @@ - (void) testStandardBlackList {
146147

147148
NSLog(@"d: %@", dictionary);
148149
NSString* link = dictionary[@"external_intent_uri"];
149-
NSString *pattern = @"^(?i)((http|https):\\/\\/).*[\\/|?|#].*\\b(password|o?auth|o?auth.?token|access|access.?token)\\b";
150-
NSLog(@"\n Link: '%@'\nPattern: '%@'\n.", link, pattern);
151-
XCTAssertEqualObjects(link, pattern);
150+
NSString *pattern1 = @"^(?i)((http|https):\\/\\/).*[\\/|?|#].*\\b(password|o?auth|o?auth.?token|access|access.?token)\\b";
151+
NSString *pattern2 = @"^(?i).+:.*[?].*\\b(password|o?auth|o?auth.?token|access|access.?token)\\b";
152+
NSLog(@"\n Link: '%@'\nPattern1: '%@'\nPattern2: '%@'.", link, pattern1, pattern2);
153+
XCTAssertTrue([link isEqualToString:pattern1] || [link isEqualToString:pattern2]);
152154
[expectation fulfill];
153155
});
154156

Branch-SDK-Tests/BranchCloseRequestTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ @implementation BranchCloseRequestTests
2020

2121
- (void)testRequestBody {
2222
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
23+
preferenceHelper.identityID = @"foo_identity";
2324
NSDictionary * const expectedParams = @{
2425
BRANCH_REQUEST_KEY_BRANCH_IDENTITY: preferenceHelper.identityID,
2526
BRANCH_REQUEST_KEY_DEVICE_FINGERPRINT_ID: preferenceHelper.deviceFingerprintID,

Branch-SDK-Tests/BranchEvent.Test.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ @interface BranchEventTest : BNCTestCase
2121

2222
@implementation BranchEventTest
2323

24+
- (void) setUp {
25+
[BNCPreferenceHelper preferenceHelper].identityID = @"575759106028389737";
26+
[[BNCPreferenceHelper preferenceHelper] clearInstrumentationDictionary];
27+
}
28+
2429
- (void) testDescription {
2530
BranchEvent *event = [BranchEvent standardEvent:BranchStandardEventPurchase];
2631
event.transactionID = @"1234";
@@ -112,6 +117,7 @@ - (void) testEvent {
112117

113118
NSMutableDictionary *expectedRequest =
114119
[self mutableDictionaryFromBundleJSONWithKey:@"V2EventJSON"];
120+
expectedRequest[@"branch_key"] = Branch.branchKey;
115121
expectedRequest[@"user_data"] = [[BNCDeviceInfo getInstance] v2dictionary];
116122

117123
Branch *branch = [Branch getInstance:@"key_live_foo"];
@@ -131,8 +137,9 @@ - (void) testEvent {
131137
NSError *error = nil;
132138
NSString *url = request.URL.absoluteString;
133139
NSData *bodyData = request.HTTPBody;
134-
NSDictionary *parameters =
135-
[NSJSONSerialization JSONObjectWithData:bodyData options:0 error:&error];
140+
NSMutableDictionary *parameters =
141+
[NSJSONSerialization JSONObjectWithData:bodyData
142+
options:NSJSONReadingMutableContainers error:&error];
136143
XCTAssertNil(error);
137144

138145
NSLog(@"testEvent 1");
@@ -157,6 +164,7 @@ - (void) testUserCompletedAction {
157164

158165
NSMutableDictionary *expectedRequest =
159166
[self mutableDictionaryFromBundleJSONWithKey:@"V2EventJSON"];
167+
expectedRequest[@"branch_key"] = Branch.branchKey;
160168
expectedRequest[@"user_data"] = [[BNCDeviceInfo getInstance] v2dictionary];
161169
expectedRequest[@"event_data"] = nil;
162170
expectedRequest[@"custom_data"] = nil;

Branch-SDK-Tests/BranchInstallRequestTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ - (void)testRequestBody {
8383
@"facebook_app_link_checked": @0,
8484
@"latest_install_time": BNCWireFormatFromDate(appDate),
8585
@"ios_bundle_id": @"foo-bundle-id",
86+
@"ios_team_id": @"R63EM248DP",
8687
@"lastest_update_time": BNCWireFormatFromDate(appDate),
8788
@"link_identifier": @"foo-link-id",
8889
@"first_install_time": BNCWireFormatFromDate(appDate),

Branch-SDK-Tests/BranchOpenRequestTests.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ - (void)testRequestBodyWithNoFingerprintID {
8181
@"mv": @"-1",
8282
@"pn": BUNDLE_ID
8383
},
84-
@"debug": @1,
84+
@"debug": IS_DEBUG,
8585
@"facebook_app_link_checked": @0,
8686
@"identity_id": IDENTITY_ID,
8787
@"ios_bundle_id": BUNDLE_ID,
88+
@"ios_team_id": @"R63EM248DP",
8889
@"link_identifier": LINK_IDENTIFIER,
8990
@"uri_scheme": URI_SCHEME,
9091

@@ -156,11 +157,12 @@ - (void)testRequestBodyWithFingerprintID {
156157
@"mv": @"-1",
157158
@"pn": BUNDLE_ID
158159
},
159-
@"debug": @1,
160+
@"debug": IS_DEBUG,
160161
@"device_fingerprint_id": FINGERPRINT_ID,
161162
@"facebook_app_link_checked": @0,
162163
@"identity_id": IDENTITY_ID,
163164
@"ios_bundle_id": BUNDLE_ID,
165+
@"ios_team_id": @"R63EM248DP",
164166
@"link_identifier": LINK_IDENTIFIER,
165167
@"uri_scheme": URI_SCHEME,
166168

Branch-SDK-Tests/BranchShortUrlRequestTests.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@ - (void)testRequestBody {
7373
callback:NULL];
7474

7575
id serverInterfaceMock = OCMClassMock([BNCServerInterface class]);
76-
[[serverInterfaceMock expect] postRequest:expectedParams url:[self stringMatchingPattern:BRANCH_REQUEST_ENDPOINT_GET_SHORT_URL] key:[OCMArg any] callback:[OCMArg any]];
76+
[[serverInterfaceMock expect]
77+
postRequest:expectedParams
78+
url:[self stringMatchingPattern:BRANCH_REQUEST_ENDPOINT_GET_SHORT_URL]
79+
key:[OCMArg any]
80+
callback:[OCMArg any]];
7781

7882
[request makeRequest:serverInterfaceMock key:nil callback:NULL];
79-
8083
[serverInterfaceMock verify];
8184
}
8285

@@ -112,7 +115,11 @@ - (void)testRequestBodyWhenOptionalValuesArentProvided {
112115
callback:NULL];
113116

114117
id serverInterfaceMock = OCMClassMock([BNCServerInterface class]);
115-
[[serverInterfaceMock expect] postRequest:expectedParams url:[OCMArg any] key:[OCMArg any] callback:[OCMArg any]];
118+
[[serverInterfaceMock expect]
119+
postRequest:expectedParams
120+
url:[OCMArg any]
121+
key:[OCMArg any]
122+
callback:[OCMArg any]];
116123

117124
[request makeRequest:serverInterfaceMock key:nil callback:NULL];
118125

Branch-SDK/Branch-SDK/BNCKeyChain.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ + (id) retrieveValueForService:(NSString*)service key:(NSString*)key error:(NSEr
124124
};
125125
CFDataRef valueData = NULL;
126126
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dictionary, (CFTypeRef *)&valueData);
127-
if (status) {
127+
if (status != errSecSuccess) {
128128
NSError *localError = [self errorWithKey:key OSStatus:status];
129129
BNCLogDebugSDK(@"Can't retrieve key: %@.", localError);
130130
if (error) *error = localError;

0 commit comments

Comments
 (0)