Skip to content

Commit 13de0ad

Browse files
committed
Release 3.6.4
1 parent cf78105 commit 13de0ad

21 files changed

+325
-41
lines changed

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

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,60 @@
88

99
#import <XCTest/XCTest.h>
1010
#import "BNCRequestFactory.h"
11+
#import "BranchConstants.h"
12+
#import "BNCEncodingUtils.h"
1113

1214
@interface BNCRequestFactoryTests : XCTestCase
13-
15+
@property (nonatomic, copy, readwrite) NSString *requestUUID;
16+
@property (nonatomic, copy, readwrite) NSNumber *requestCreationTimeStamp;
1417
@end
1518

1619
@implementation BNCRequestFactoryTests
1720

1821
- (void)setUp {
19-
22+
_requestUUID = [[NSUUID UUID ] UUIDString];
23+
_requestCreationTimeStamp = BNCWireFormatFromDate([NSDate date]);
2024
}
2125

2226
- (void)tearDown {
2327

2428
}
2529

2630
- (void)testInitWithBranchKeyNil {
27-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil];
31+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil UUID:_requestUUID TimeStamp:_requestCreationTimeStamp];
2832
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
2933
XCTAssertNotNil(json);
3034

3135
// key is omitted when nil
3236
XCTAssertNil([json objectForKey:@"branch_key"]);
37+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
38+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
3339
}
3440

3541
- (void)testInitWithBranchKeyEmpty {
36-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@""];
42+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
3743
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
3844
XCTAssertNotNil(json);
3945

4046
// empty string is allowed
4147
XCTAssertTrue([@"" isEqualToString:[json objectForKey:@"branch_key"]]);
48+
49+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
50+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
4251
}
4352

4453
- (void)testInitWithBranchKey {
45-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
54+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
4655
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
4756
XCTAssertNotNil(json);
4857
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
58+
59+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
60+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
4961
}
5062

5163
- (void)testDataForInstall {
52-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
64+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
5365
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
5466
XCTAssertNotNil(json);
5567

@@ -60,10 +72,13 @@ - (void)testDataForInstall {
6072

6173
// not present on installs
6274
XCTAssertNil([json objectForKey:@"randomized_bundle_token"]);
75+
76+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
77+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
6378
}
6479

6580
- (void)testDataForOpen {
66-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
81+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
6782
NSDictionary *json = [factory dataForOpenWithURLString:@"https://branch.io"];
6883
XCTAssertNotNil(json);
6984

@@ -75,12 +90,15 @@ - (void)testDataForOpen {
7590
// Present only on opens. Assumes test runs after the host app completes an install.
7691
// This is not a reliable assumption on test runners
7792
//XCTAssertNotNil([json objectForKey:@"randomized_bundle_token"]);
93+
94+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
95+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
7896
}
7997

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

83-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
101+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
84102
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
85103
XCTAssertNotNil(json);
86104

@@ -89,6 +107,9 @@ - (void)testDataForEvent {
89107
NSDictionary *userData = [json objectForKey:@"user_data"];
90108
XCTAssertNotNil(userData);
91109
XCTAssertNotNil([userData objectForKey:@"idfv"]);
110+
111+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
112+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
92113
}
93114

94115
- (void)testDataForEventWithContentItem {
@@ -104,7 +125,7 @@ - (void)testDataForEventWithContentItem {
104125
]
105126
};
106127

107-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
128+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
108129
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
109130
XCTAssertNotNil(json);
110131

@@ -117,6 +138,9 @@ - (void)testDataForEventWithContentItem {
117138
NSDictionary *userData = [json objectForKey:@"user_data"];
118139
XCTAssertNotNil(userData);
119140
XCTAssertNotNil([userData objectForKey:@"idfv"]);
141+
142+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
143+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
120144
}
121145

122146
- (void)testDataForEventWithTwoContentItem {
@@ -138,7 +162,7 @@ - (void)testDataForEventWithTwoContentItem {
138162
]
139163
};
140164

141-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
165+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
142166
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
143167
XCTAssertNotNil(json);
144168

@@ -151,12 +175,15 @@ - (void)testDataForEventWithTwoContentItem {
151175
NSDictionary *userData = [json objectForKey:@"user_data"];
152176
XCTAssertNotNil(userData);
153177
XCTAssertNotNil([userData objectForKey:@"idfv"]);
178+
179+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
180+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
154181
}
155182

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

159-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
186+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
160187
NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]];
161188
XCTAssertNotNil(json);
162189

@@ -165,10 +192,13 @@ - (void)testDataForEventEmpty {
165192
NSDictionary *userData = [json objectForKey:@"user_data"];
166193
XCTAssertNotNil(userData);
167194
XCTAssertNotNil([userData objectForKey:@"idfv"]);
195+
196+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
197+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
168198
}
169199

170200
- (void)testDataForEventNil {
171-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
201+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
172202
NSDictionary *json = [factory dataForEventWithEventDictionary:nil];
173203
XCTAssertNotNil(json);
174204

@@ -177,19 +207,28 @@ - (void)testDataForEventNil {
177207
NSDictionary *userData = [json objectForKey:@"user_data"];
178208
XCTAssertNotNil(userData);
179209
XCTAssertNotNil([userData objectForKey:@"idfv"]);
210+
211+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
212+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
180213
}
181214

182215

183216
- (void)testDataForShortURL {
184-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
217+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
185218
NSDictionary *json = [factory dataForShortURLWithLinkDataDictionary:@{}.mutableCopy isSpotlightRequest:NO];
186219
XCTAssertNotNil(json);
220+
221+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
222+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
187223
}
188224

189225
- (void)testDataForLATD {
190-
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
226+
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
191227
NSDictionary *json = [factory dataForLATDWithDataDictionary:@{}.mutableCopy];
192228
XCTAssertNotNil(json);
229+
230+
XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]);
231+
XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]);
193232
}
194233

195234
@end

0 commit comments

Comments
 (0)