diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m index c18505774..c28d3b6e0 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m @@ -8,15 +8,19 @@ #import #import "BNCRequestFactory.h" +#import "BranchConstants.h" +#import "BNCEncodingUtils.h" @interface BNCRequestFactoryTests : XCTestCase - +@property (nonatomic, copy, readwrite) NSString *requestUUID; +@property (nonatomic, copy, readwrite) NSNumber *requestCreationTimeStamp; @end @implementation BNCRequestFactoryTests - (void)setUp { - + _requestUUID = [[NSUUID UUID ] UUIDString]; + _requestCreationTimeStamp = BNCWireFormatFromDate([NSDate date]); } - (void)tearDown { @@ -24,32 +28,40 @@ - (void)tearDown { } - (void)testInitWithBranchKeyNil { - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil UUID:_requestUUID TimeStamp:_requestCreationTimeStamp]; NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"]; XCTAssertNotNil(json); // key is omitted when nil XCTAssertNil([json objectForKey:@"branch_key"]); + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testInitWithBranchKeyEmpty { - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@""]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"]; XCTAssertNotNil(json); // empty string is allowed XCTAssertTrue([@"" isEqualToString:[json objectForKey:@"branch_key"]]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testInitWithBranchKey { - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"]; XCTAssertNotNil(json); XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForInstall { - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"]; XCTAssertNotNil(json); @@ -60,10 +72,13 @@ - (void)testDataForInstall { // not present on installs XCTAssertNil([json objectForKey:@"randomized_bundle_token"]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForOpen { - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForOpenWithURLString:@"https://branch.io"]; XCTAssertNotNil(json); @@ -75,12 +90,15 @@ - (void)testDataForOpen { // Present only on opens. Assumes test runs after the host app completes an install. // This is not a reliable assumption on test runners //XCTAssertNotNil([json objectForKey:@"randomized_bundle_token"]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForEvent { NSDictionary *event = @{@"name": @"ADD_TO_CART"}; - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]]; XCTAssertNotNil(json); @@ -89,6 +107,9 @@ - (void)testDataForEvent { NSDictionary *userData = [json objectForKey:@"user_data"]; XCTAssertNotNil(userData); XCTAssertNotNil([userData objectForKey:@"idfv"]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForEventWithContentItem { @@ -104,7 +125,7 @@ - (void)testDataForEventWithContentItem { ] }; - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]]; XCTAssertNotNil(json); @@ -117,6 +138,9 @@ - (void)testDataForEventWithContentItem { NSDictionary *userData = [json objectForKey:@"user_data"]; XCTAssertNotNil(userData); XCTAssertNotNil([userData objectForKey:@"idfv"]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForEventWithTwoContentItem { @@ -138,7 +162,7 @@ - (void)testDataForEventWithTwoContentItem { ] }; - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]]; XCTAssertNotNil(json); @@ -151,12 +175,15 @@ - (void)testDataForEventWithTwoContentItem { NSDictionary *userData = [json objectForKey:@"user_data"]; XCTAssertNotNil(userData); XCTAssertNotNil([userData objectForKey:@"idfv"]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForEventEmpty { NSDictionary *event = @{}; - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForEventWithEventDictionary:[event mutableCopy]]; XCTAssertNotNil(json); @@ -165,10 +192,13 @@ - (void)testDataForEventEmpty { NSDictionary *userData = [json objectForKey:@"user_data"]; XCTAssertNotNil(userData); XCTAssertNotNil([userData objectForKey:@"idfv"]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForEventNil { - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForEventWithEventDictionary:nil]; XCTAssertNotNil(json); @@ -177,19 +207,28 @@ - (void)testDataForEventNil { NSDictionary *userData = [json objectForKey:@"user_data"]; XCTAssertNotNil(userData); XCTAssertNotNil([userData objectForKey:@"idfv"]); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForShortURL { - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForShortURLWithLinkDataDictionary:@{}.mutableCopy isSpotlightRequest:NO]; XCTAssertNotNil(json); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } - (void)testDataForLATD { - BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"]; + BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *json = [factory dataForLATDWithDataDictionary:@{}.mutableCopy]; XCTAssertNotNil(json); + + XCTAssertTrue(self.requestCreationTimeStamp == [json objectForKey:BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP]); + XCTAssertTrue([self.requestUUID isEqualToString:[json objectForKey:BRANCH_REQUEST_KEY_REQUEST_UUID]]); } @end