8
8
9
9
#import < XCTest/XCTest.h>
10
10
#import " BNCRequestFactory.h"
11
+ #import " BranchConstants.h"
12
+ #import " BNCEncodingUtils.h"
11
13
12
14
@interface BNCRequestFactoryTests : XCTestCase
13
-
15
+ @property (nonatomic , copy , readwrite ) NSString *requestUUID;
16
+ @property (nonatomic , copy , readwrite ) NSNumber *requestCreationTimeStamp;
14
17
@end
15
18
16
19
@implementation BNCRequestFactoryTests
17
20
18
21
- (void )setUp {
19
-
22
+ _requestUUID = [[NSUUID UUID ] UUIDString ];
23
+ _requestCreationTimeStamp = BNCWireFormatFromDate ([NSDate date ]);
20
24
}
21
25
22
26
- (void )tearDown {
23
27
24
28
}
25
29
26
30
- (void )testInitWithBranchKeyNil {
27
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: nil ];
31
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: nil UUID: _requestUUID TimeStamp: _requestCreationTimeStamp ];
28
32
NSDictionary *json = [factory dataForInstallWithURLString: @" https://branch.io" ];
29
33
XCTAssertNotNil (json);
30
34
31
35
// key is omitted when nil
32
36
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]]);
33
39
}
34
40
35
41
- (void )testInitWithBranchKeyEmpty {
36
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" " ];
42
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" " UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
37
43
NSDictionary *json = [factory dataForInstallWithURLString: @" https://branch.io" ];
38
44
XCTAssertNotNil (json);
39
45
40
46
// empty string is allowed
41
47
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]]);
42
51
}
43
52
44
53
- (void )testInitWithBranchKey {
45
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
54
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
46
55
NSDictionary *json = [factory dataForInstallWithURLString: @" https://branch.io" ];
47
56
XCTAssertNotNil (json);
48
57
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]]);
49
61
}
50
62
51
63
- (void )testDataForInstall {
52
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
64
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
53
65
NSDictionary *json = [factory dataForInstallWithURLString: @" https://branch.io" ];
54
66
XCTAssertNotNil (json);
55
67
@@ -60,10 +72,13 @@ - (void)testDataForInstall {
60
72
61
73
// not present on installs
62
74
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]]);
63
78
}
64
79
65
80
- (void )testDataForOpen {
66
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
81
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
67
82
NSDictionary *json = [factory dataForOpenWithURLString: @" https://branch.io" ];
68
83
XCTAssertNotNil (json);
69
84
@@ -75,12 +90,15 @@ - (void)testDataForOpen {
75
90
// Present only on opens. Assumes test runs after the host app completes an install.
76
91
// This is not a reliable assumption on test runners
77
92
// 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]]);
78
96
}
79
97
80
98
- (void )testDataForEvent {
81
99
NSDictionary *event = @{@" name" : @" ADD_TO_CART" };
82
100
83
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
101
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
84
102
NSDictionary *json = [factory dataForEventWithEventDictionary: [event mutableCopy ]];
85
103
XCTAssertNotNil (json);
86
104
@@ -89,6 +107,9 @@ - (void)testDataForEvent {
89
107
NSDictionary *userData = [json objectForKey: @" user_data" ];
90
108
XCTAssertNotNil (userData);
91
109
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]]);
92
113
}
93
114
94
115
- (void )testDataForEventWithContentItem {
@@ -104,7 +125,7 @@ - (void)testDataForEventWithContentItem {
104
125
]
105
126
};
106
127
107
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
128
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
108
129
NSDictionary *json = [factory dataForEventWithEventDictionary: [event mutableCopy ]];
109
130
XCTAssertNotNil (json);
110
131
@@ -117,6 +138,9 @@ - (void)testDataForEventWithContentItem {
117
138
NSDictionary *userData = [json objectForKey: @" user_data" ];
118
139
XCTAssertNotNil (userData);
119
140
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]]);
120
144
}
121
145
122
146
- (void )testDataForEventWithTwoContentItem {
@@ -138,7 +162,7 @@ - (void)testDataForEventWithTwoContentItem {
138
162
]
139
163
};
140
164
141
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
165
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
142
166
NSDictionary *json = [factory dataForEventWithEventDictionary: [event mutableCopy ]];
143
167
XCTAssertNotNil (json);
144
168
@@ -151,12 +175,15 @@ - (void)testDataForEventWithTwoContentItem {
151
175
NSDictionary *userData = [json objectForKey: @" user_data" ];
152
176
XCTAssertNotNil (userData);
153
177
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]]);
154
181
}
155
182
156
183
- (void )testDataForEventEmpty {
157
184
NSDictionary *event = @{};
158
185
159
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
186
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
160
187
NSDictionary *json = [factory dataForEventWithEventDictionary: [event mutableCopy ]];
161
188
XCTAssertNotNil (json);
162
189
@@ -165,10 +192,13 @@ - (void)testDataForEventEmpty {
165
192
NSDictionary *userData = [json objectForKey: @" user_data" ];
166
193
XCTAssertNotNil (userData);
167
194
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]]);
168
198
}
169
199
170
200
- (void )testDataForEventNil {
171
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
201
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
172
202
NSDictionary *json = [factory dataForEventWithEventDictionary: nil ];
173
203
XCTAssertNotNil (json);
174
204
@@ -177,19 +207,28 @@ - (void)testDataForEventNil {
177
207
NSDictionary *userData = [json objectForKey: @" user_data" ];
178
208
XCTAssertNotNil (userData);
179
209
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]]);
180
213
}
181
214
182
215
183
216
- (void )testDataForShortURL {
184
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
217
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
185
218
NSDictionary *json = [factory dataForShortURLWithLinkDataDictionary: @{}.mutableCopy isSpotlightRequest: NO ];
186
219
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]]);
187
223
}
188
224
189
225
- (void )testDataForLATD {
190
- BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" ];
226
+ BNCRequestFactory *factory = [[BNCRequestFactory alloc ] initWithBranchKey: @" key_abcd" UUID: self .requestUUID TimeStamp: self .requestCreationTimeStamp ];
191
227
NSDictionary *json = [factory dataForLATDWithDataDictionary: @{}.mutableCopy];
192
228
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]]);
193
232
}
194
233
195
234
@end
0 commit comments