Skip to content

Commit 7a76d4c

Browse files
author
Edward Smith
committed
Updated tests.
1 parent 38a355d commit 7a76d4c

File tree

11 files changed

+108
-49
lines changed

11 files changed

+108
-49
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
@file BNCApplication+BNCTest.h
3+
@package Branch-SDK-Tests
4+
@brief Expose BNCApplication interfaces for testing.
5+
6+
@author Edward Smith
7+
@date May 4, 2018
8+
@copyright Copyright © 2018 Branch. All rights reserved.
9+
*/
10+
11+
#import <Foundation/Foundation.h>
12+
#import "BNCApplication.h"
13+
14+
@interface BNCApplication (BNCTest)
15+
16+
- (void) setAppOriginalInstallDate:(NSDate*)originalInstallDate
17+
firstInstallDate:(NSDate*)firstInstallDate
18+
lastUpdateDate:(NSDate*)lastUpdateDate;
19+
20+
@end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
@file BNCApplication+BNCTest.m
3+
@package Branch-SDK-Tests
4+
@brief Expose BNCApplication interfaces for testing.
5+
6+
@author Edward Smith
7+
@date May 4, 2018
8+
@copyright Copyright © 2018 Branch. All rights reserved.
9+
*/
10+
11+
#import "BNCApplication+BNCTest.h"

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ - (void)testParamAddForBranchKey {
4949
if (callCount == 1) {
5050
BOOL foundIt = ([request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound);
5151
XCTAssertTrue(foundIt, @"Branch Key not added");
52-
BNCAfterSecondsPerformBlock(0.01, ^{ [expectation fulfill]; });
52+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [expectation fulfill]; });
5353
return YES;
5454
}
5555
return NO;
@@ -108,7 +108,10 @@ - (void)testGetRequestAsyncRetriesWhenAppropriate {
108108
// Return actual data afterwards
109109
++successfulConnections;
110110
XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections);
111-
BNCAfterSecondsPerformBlock(0.01, ^{ NSLog(@"==> Fullfill."); [successExpectation fulfill]; });
111+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
112+
NSLog(@"==> Fullfill.");
113+
[successExpectation fulfill];
114+
});
112115

113116
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
114117
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
@@ -153,7 +156,7 @@ - (void)testGetRequestAsyncRetriesWhenInappropriateResponse {
153156
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
154157
connectionAttempts++;
155158
XCTAssertEqual(connectionAttempts, 1);
156-
BNCAfterSecondsPerformBlock(0.01, ^ {
159+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^ {
157160
[successExpectation fulfill];
158161
});
159162
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
@@ -191,7 +194,7 @@ - (void)testGetRequestAsyncRetriesWhenInappropriateRetryCount {
191194
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
192195
connectionAttempts++;
193196
XCTAssertEqual(connectionAttempts, 1);
194-
BNCAfterSecondsPerformBlock(0.01, ^{
197+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
195198
[successExpectation fulfill];
196199
});
197200
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
@@ -243,7 +246,10 @@ - (void)testPostRequestAsyncRetriesWhenAppropriate {
243246
++successfulConnections;
244247
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
245248
XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections);
246-
BNCAfterSecondsPerformBlock(0.01, ^ { NSLog(@"==>> Fullfill <<=="); [successExpectation fulfill]; });
249+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^ {
250+
NSLog(@"==>> Fullfill <<==");
251+
[successExpectation fulfill];
252+
});
247253
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
248254

249255
} else {
@@ -284,8 +290,7 @@ - (void)testPostRequestAsyncRetriesWhenInappropriateResponse {
284290
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
285291
connectionAttempts++;
286292
XCTAssertEqual(connectionAttempts, 1);
287-
BNCAfterSecondsPerformBlock(0.01, ^{ [successExpectation fulfill]; });
288-
293+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; });
289294
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
290295

291296
}];
@@ -321,10 +326,8 @@ - (void)testPostRequestAsyncRetriesWhenInappropriateRetryCount {
321326
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
322327
connectionAttempts++;
323328
XCTAssertEqual(connectionAttempts, 1);
324-
BNCAfterSecondsPerformBlock(0.01, ^{ [successExpectation fulfill]; });
325-
329+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; });
326330
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
327-
328331
}];
329332

330333
[serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL];

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ - (void)testCloseRequestsArentPersisted {
154154
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
155155
if ([reqs isKindOfClass:[NSArray class]]) {
156156
XCTAssert(reqs.count == 0);
157-
BNCAfterSecondsPerformBlock(0.01, ^{ [self safelyFulfillExpectation:expectation]; });
157+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
158+
[self safelyFulfillExpectation:expectation];
159+
});
158160
return YES;
159161
}
160162
return NO;
@@ -182,7 +184,9 @@ - (void)testDebugRequestsArentPersisted {
182184
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
183185
if ([reqs isKindOfClass:[NSArray class]]) {
184186
XCTAssert(reqs.count == 0);
185-
BNCAfterSecondsPerformBlock(0.01, ^{ [self safelyFulfillExpectation:expectation]; });
187+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
188+
[self safelyFulfillExpectation:expectation];
189+
});
186190
return YES;
187191
}
188192
return NO;

Branch-SDK-Tests/Branch-SDK-Tests/BNCURLBlackList.Test.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#import "BNCTestCase.h"
1212
#import "BNCURLBlackList.h"
13+
#import "Branch.h"
1314

1415
@interface BNCURLBlackList ()
1516
@property (readwrite) NSURL *blackListJSONURL;

Branch-SDK-Tests/Branch-SDK-Tests/BranchDelegate.Test.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "BNCTestCase.h"
10+
#import "Branch.h"
1011
#import "BNCEncodingUtils.h"
1112

1213
@interface BranchDelegateTest : BNCTestCase <BranchDelegate>

Branch-SDK-Tests/Branch-SDK-Tests/BranchInstallRequestTests.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "BNCTestCase.h"
1010
#import "Branch.h"
11+
#import "BNCApplication.h"
12+
#import "BNCApplication+BNCTest.h"
1113
#import "BranchInstallRequest.h"
1214
#import "BNCPreferenceHelper.h"
1315
#import "BNCSystemObserver.h"
@@ -68,10 +70,11 @@ - (void)testRequestBody {
6870
[[[systemObserverMock stub] andReturn:SCREEN_HEIGHT] getScreenHeight];
6971

7072
NSDate *appDate = [NSDate date];
71-
[BNCTestCase setAppOriginalInstallDate:appDate
73+
[[BNCApplication currentApplication]
74+
setAppOriginalInstallDate:appDate
7275
firstInstallDate:appDate
73-
lastUpdateDate:appDate
74-
previousUpdateDate:nil];
76+
lastUpdateDate:appDate];
77+
[preferenceHelper setPreviousAppBuildDate:nil];
7578

7679
NSDictionary *expectedParams = @{
7780
@"app_version": @"foo-app-version",

Branch-SDK-Tests/Branch-SDK-Tests/BranchOpenRequestTests.m

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//
88

99
#import "BNCTestCase.h"
10+
#import "Branch.h"
11+
#import "BNCApplication+BNCTest.h"
1012
#import "BranchOpenRequest.h"
1113
#import "BranchConstants.h"
1214
#import "BNCPreferenceHelper.h"
@@ -66,10 +68,11 @@ - (void)testRequestBodyWithNoFingerprintID {
6668
NSTimeInterval kOneDayAgo = -1.0*24.0*60.0*60.0;
6769
NSDate *installDate = [NSDate dateWithTimeIntervalSinceNow:2.0*kOneDayAgo];
6870
NSDate *updateDate = [NSDate dateWithTimeIntervalSinceNow:1.0*kOneDayAgo];
69-
[BNCTestCase setAppOriginalInstallDate:installDate
71+
[[BNCApplication currentApplication]
72+
setAppOriginalInstallDate:installDate
7073
firstInstallDate:installDate
71-
lastUpdateDate:installDate
72-
previousUpdateDate:updateDate];
74+
lastUpdateDate:installDate];
75+
[preferenceHelper setPreviousAppBuildDate:updateDate];
7376

7477
NSDictionary *expectedParams = @{
7578
@"app_version": APP_VERSION,
@@ -140,10 +143,11 @@ - (void)testRequestBodyWithFingerprintID {
140143
NSTimeInterval kOneDayAgo = -1.0*24.0*60.0*60.0;
141144
NSDate *installDate = [NSDate dateWithTimeIntervalSinceNow:2.0*kOneDayAgo];
142145
NSDate *updateDate = [NSDate dateWithTimeIntervalSinceNow:1.0*kOneDayAgo];
143-
[BNCTestCase setAppOriginalInstallDate:installDate
146+
[[BNCApplication currentApplication]
147+
setAppOriginalInstallDate:installDate
144148
firstInstallDate:installDate
145-
lastUpdateDate:installDate
146-
previousUpdateDate:updateDate];
149+
lastUpdateDate:installDate];
150+
[preferenceHelper setPreviousAppBuildDate:updateDate];
147151

148152
NSDictionary *expectedParams = @{
149153
@"app_version": APP_VERSION,

Branch-SDK-Tests/Branch-SDK-Tests/BranchSDKFunctionalityTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "BNCTestCase.h"
10+
#import "Branch.h"
1011

1112
NSString * const TEST_BRANCH_KEY = @"key_live_78801a996de4287481fe73708cc95da2";
1213
NSString * const TEST_DEVICE_FINGERPRINT_ID = @"94938498586381084";

Branch-SDK/Branch-SDK/BNCApplication.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ - (NSDictionary*) deviceKeyIdentityValueDictionary {
145145
}
146146
}
147147

148+
@end
149+
150+
@implementation BNCApplication (BNCTest)
151+
148152
- (void) setAppOriginalInstallDate:(NSDate*)originalInstallDate
149153
firstInstallDate:(NSDate*)firstInstallDate
150154
lastUpdateDate:(NSDate*)lastUpdateDate {
@@ -154,3 +158,4 @@ - (void) setAppOriginalInstallDate:(NSDate*)originalInstallDate
154158
}
155159

156160
@end
161+

0 commit comments

Comments
 (0)