Skip to content

Commit 3997ecd

Browse files
authored
Merge branch 'master' into SDK-2060-Add-endpoint-manager
2 parents 7bdeb72 + 3294927 commit 3997ecd

36 files changed

+357
-1644
lines changed

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,116 @@ - (void)verifyOldGbraidDataIsCleared {
401401
XCTAssertNil([BNCPreferenceHelper sharedInstance].referrerGBRAIDInitDate);
402402
}
403403

404+
- (void)testReferringURLWithSccid {
405+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=12345"];
406+
NSDictionary *expected = @{
407+
@"sccid": @"12345"
408+
};
409+
410+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
411+
[utility parseReferringURL:url];
412+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
413+
414+
XCTAssert([expected isEqualToDictionary:params]);
415+
}
416+
417+
- (void)testReferringURLWithSccidMixedCase {
418+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?ScCiD=12345"];
419+
NSDictionary *expected = @{
420+
@"sccid": @"12345"
421+
};
422+
423+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
424+
[utility parseReferringURL:url];
425+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
426+
427+
XCTAssert([expected isEqualToDictionary:params]);
428+
}
429+
430+
- (void)testReferringURLWithSccidNoValue {
431+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid="];
432+
NSDictionary *expected = @{
433+
@"sccid": @""
434+
};
435+
436+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
437+
[utility parseReferringURL:url];
438+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
439+
440+
XCTAssert([expected isEqualToDictionary:params]);
441+
}
442+
443+
- (void)testReferringURLWithSccidValueCasePreserved {
444+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=aAbBcC"];
445+
NSDictionary *expected = @{
446+
@"sccid": @"aAbBcC"
447+
};
448+
449+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
450+
[utility parseReferringURL:url];
451+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
452+
453+
XCTAssert([expected isEqualToDictionary:params]);
454+
}
455+
456+
- (void)testReferringURLWithSccidIgnoredParam {
457+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=12345&other=abcde"];
458+
NSDictionary *expected = @{
459+
@"sccid": @"12345"
460+
};
461+
462+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
463+
[utility parseReferringURL:url];
464+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
465+
466+
XCTAssert([expected isEqualToDictionary:params]);
467+
}
468+
469+
- (void)testReferringURLWithSccidFragment{
470+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=12345#header"];
471+
NSDictionary *expected = @{
472+
@"sccid": @"12345"
473+
};
474+
475+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
476+
[utility parseReferringURL:url];
477+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
478+
479+
XCTAssert([expected isEqualToDictionary:params]);
480+
}
481+
482+
- (void)testReferringURLWithSccidAsFragment{
483+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?other=abcde#sccid=12345"];
484+
NSDictionary *expected = @{ };
485+
486+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
487+
[utility parseReferringURL:url];
488+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
489+
490+
XCTAssert([expected isEqualToDictionary:params]);
491+
}
492+
493+
- (void)testReferringURLWithSccidOverwritesValue {
494+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=12345"];
495+
NSDictionary *expected = @{
496+
@"sccid": @"12345"
497+
};
498+
499+
NSURL *url2 = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=abcde"];
500+
NSDictionary *expected2 = @{
501+
@"sccid": @"abcde"
502+
};
503+
504+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
505+
[utility parseReferringURL:url];
506+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
507+
XCTAssert([expected isEqualToDictionary:params]);
508+
509+
[utility parseReferringURL:url2];
510+
NSDictionary *params2 = [utility referringURLQueryParamsForEndpoint:openEndpoint];
511+
512+
XCTAssert([expected2 isEqualToDictionary:params2]);
513+
}
514+
515+
404516
@end

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

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#import "BranchInstallRequest.h"
1616
#import "BranchOpenRequest.h"
1717
#import "BranchEvent.h"
18-
#import "BNCCommerceEvent.h"
19-
#import "BranchUserCompletedActionRequest.h"
20-
#import "BranchSetIdentityRequest.h"
21-
#import "BranchLogoutRequest.h"
2218

2319
@interface BNCServerRequestQueue ()
2420
- (NSData *)archiveQueue:(NSArray<BNCServerRequest *> *)queue;
@@ -106,58 +102,6 @@ - (void)testArchiveEventRequest {
106102
// The request object is not very test friendly, so comparing the two is not helpful at the moment
107103
}
108104

109-
- (void)testArchiveCommerceEventRequest {
110-
BranchCommerceEventRequest *object = [BranchCommerceEventRequest new];
111-
112-
NSData *archived = [self.queue archiveObject:object];
113-
XCTAssertNotNil(archived);
114-
115-
BranchCommerceEventRequest *unarchived = [self.queue unarchiveObjectFromData:archived];
116-
XCTAssertNotNil(unarchived);
117-
XCTAssert([unarchived isKindOfClass:[BranchCommerceEventRequest class]]);
118-
119-
// The request object is not very test friendly, so comparing the two is not helpful at the moment
120-
}
121-
122-
- (void)testArchiveUserCompletedActionRequest {
123-
BranchUserCompletedActionRequest *object = [BranchUserCompletedActionRequest new];
124-
125-
NSData *archived = [self.queue archiveObject:object];
126-
XCTAssertNotNil(archived);
127-
128-
BranchUserCompletedActionRequest *unarchived = [self.queue unarchiveObjectFromData:archived];
129-
XCTAssertNotNil(unarchived);
130-
XCTAssert([unarchived isKindOfClass:[BranchUserCompletedActionRequest class]]);
131-
132-
// The request object is not very test friendly, so comparing the two is not helpful at the moment
133-
}
134-
135-
- (void)testArchiveSetIdentityRequest {
136-
BranchSetIdentityRequest *object = [BranchSetIdentityRequest new];
137-
138-
NSData *archived = [self.queue archiveObject:object];
139-
XCTAssertNotNil(archived);
140-
141-
BranchSetIdentityRequest *unarchived = [self.queue unarchiveObjectFromData:archived];
142-
XCTAssertNotNil(unarchived);
143-
XCTAssert([unarchived isKindOfClass:[BranchSetIdentityRequest class]]);
144-
145-
// The request object is not very test friendly, so comparing the two is not helpful at the moment
146-
}
147-
148-
- (void)testArchiveLogoutRequest {
149-
BranchLogoutRequest *object = [BranchLogoutRequest new];
150-
151-
NSData *archived = [self.queue archiveObject:object];
152-
XCTAssertNotNil(archived);
153-
154-
BranchLogoutRequest *unarchived = [self.queue unarchiveObjectFromData:archived];
155-
XCTAssertNotNil(unarchived);
156-
XCTAssert([unarchived isKindOfClass:[BranchLogoutRequest class]]);
157-
158-
// The request object is not very test friendly, so comparing the two is not helpful at the moment
159-
}
160-
161105
- (void)testArchiveArrayOfRequests {
162106
NSMutableArray<BNCServerRequest *> *tmp = [NSMutableArray<BNCServerRequest *> new];
163107
[tmp addObject:[BranchOpenRequest new]];
@@ -189,7 +133,6 @@ - (void)testArchiveArrayOfInvalidObjects {
189133
[tmp addObject:[BranchOpenRequest new]];
190134
[tmp addObject:@"Hello World"];
191135
[tmp addObject:[BranchEventRequest new]];
192-
[tmp addObject:[BranchCloseRequest new]];
193136

194137
NSData *data = [self.queue archiveQueue:tmp];
195138
XCTAssertNotNil(data);
@@ -205,7 +148,6 @@ - (void)testOldArchiveArrayOfInvalidObjects {
205148
[tmp addObject:[BranchOpenRequest new]];
206149
[tmp addObject:@"Hello World"];
207150
[tmp addObject:[BranchEventRequest new]];
208-
[tmp addObject:[BranchCloseRequest new]];
209151

210152
NSData *data = [self.queue oldArchiveQueue:tmp];
211153
XCTAssertNotNil(data);

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

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -170,99 +170,6 @@ - (void) testEvent {
170170
[serverInterfaceMock stopMocking];
171171
}
172172

173-
- (void) testUserCompletedAction {
174-
// Mock the result. Fix up the expectedParameters for simulator hardware --
175-
176-
NSMutableDictionary *expectedRequest =
177-
[self mutableDictionaryFromBundleJSONWithKey:@"V2EventJSON"];
178-
expectedRequest[@"branch_key"] = Branch.branchKey;
179-
expectedRequest[@"user_data"] = [[BNCDeviceInfo getInstance] v2dictionary];
180-
expectedRequest[@"event_data"] = nil;
181-
expectedRequest[@"custom_data"] = nil;
182-
expectedRequest[@"customer_event_alias"] = nil;
183-
184-
Branch *branch = [Branch getInstance:@"key_live_foo"];
185-
XCTestExpectation *expectation = [self expectationWithDescription:@"v2-event-user-action"];
186-
id serverInterfaceMock = OCMPartialMock(branch.serverInterface);
187-
188-
OCMStub(
189-
[serverInterfaceMock genericHTTPRequest:[OCMArg any]
190-
retryNumber:0
191-
callback:[OCMArg any]
192-
retryHandler:[OCMArg any]]
193-
).andDo(^(NSInvocation *invocation) {
194-
195-
__unsafe_unretained NSURLRequest *request = nil;
196-
[invocation getArgument:&request atIndex:2];
197-
198-
NSError *error = nil;
199-
NSString *url = request.URL.absoluteString;
200-
NSData *bodyData = request.HTTPBody;
201-
NSDictionary *parameters =
202-
[NSJSONSerialization JSONObjectWithData:bodyData options:0 error:&error];
203-
XCTAssertNil(error);
204-
205-
NSLog(@"2");
206-
NSLog(@"URL: %@.", url);
207-
NSLog(@"Body: %@.", parameters);
208-
209-
if ([url containsString:@"branch.io/v2/event/standard"]) {
210-
XCTAssertEqualObjects(expectedRequest, parameters);
211-
[expectation fulfill];
212-
} else {
213-
XCTFail(@"URL is unexpected. %@", url);
214-
}
215-
});
216-
217-
// Set up the Branch Univseral Object --
218-
219-
BranchUniversalObject *buo = [BranchUniversalObject new];
220-
buo.canonicalIdentifier = @"item/12345";
221-
buo.canonicalUrl = @"https://branch.io/deepviews";
222-
buo.title = @"My Content Title";
223-
buo.contentDescription = @"my_product_description1";
224-
buo.imageUrl = @"https://test_img_url";
225-
buo.keywords = @[ @"My_Keyword1", @"My_Keyword2"];
226-
buo.creationDate = [NSDate dateWithTimeIntervalSince1970:1501869445321.0/1000.0];
227-
buo.expirationDate = [NSDate dateWithTimeIntervalSince1970:212123232544.0/1000.0];
228-
buo.locallyIndex = YES;
229-
buo.publiclyIndex = NO;
230-
231-
buo.contentMetadata.contentSchema = BranchContentSchemaCommerceProduct;
232-
buo.contentMetadata.quantity = 2;
233-
buo.contentMetadata.price = [NSDecimalNumber decimalNumberWithString:@"23.2"];
234-
buo.contentMetadata.currency = BNCCurrencyUSD;
235-
buo.contentMetadata.sku = @"1994320302";
236-
buo.contentMetadata.productName = @"my_product_name1";
237-
buo.contentMetadata.productBrand = @"my_prod_Brand1";
238-
buo.contentMetadata.productCategory = BNCProductCategoryBabyToddler;
239-
buo.contentMetadata.productVariant = @"3T";
240-
buo.contentMetadata.condition = @"FAIR";
241-
buo.contentMetadata.ratingAverage = 5;
242-
buo.contentMetadata.ratingCount = 5;
243-
buo.contentMetadata.ratingMax = 7;
244-
buo.contentMetadata.rating = 6;
245-
buo.contentMetadata.addressStreet = @"Street_name1";
246-
buo.contentMetadata.addressCity = @"city1";
247-
buo.contentMetadata.addressRegion = @"Region1";
248-
buo.contentMetadata.addressCountry = @"Country1";
249-
buo.contentMetadata.addressPostalCode= @"postal_code";
250-
buo.contentMetadata.latitude = 12.07;
251-
buo.contentMetadata.longitude = -97.5;
252-
buo.contentMetadata.imageCaptions = (id) @[@"my_img_caption1", @"my_img_caption_2"];
253-
buo.contentMetadata.customMetadata = (NSMutableDictionary*) @{
254-
@"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1",
255-
@"Custom_Content_metadata_key2": @"Custom_Content_metadata_val2"
256-
};
257-
258-
// Set up and invoke --
259-
[branch clearNetworkQueue];
260-
[buo userCompletedAction:@"PURCHASE"];
261-
262-
[self waitForExpectationsWithTimeout:5.0 handler:nil];
263-
[serverInterfaceMock stopMocking];
264-
}
265-
266173
- (void) testExampleSyntax {
267174
BranchUniversalObject *contentItem = [BranchUniversalObject new];
268175
contentItem.canonicalIdentifier = @"item/123";

0 commit comments

Comments
 (0)