Skip to content

Commit

Permalink
Merge branch 'master' into SDK-2458
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch authored Nov 5, 2024
2 parents 1e41bc3 + 3681750 commit 6a0293a
Show file tree
Hide file tree
Showing 34 changed files with 335 additions and 486 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automation-trigger-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Setup Node.js environment
uses: actions/[email protected].1
uses: actions/[email protected].3
- name: Build with Maven
id: build_maven
run: |
Expand Down
67 changes: 53 additions & 14 deletions Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,60 @@

#import <XCTest/XCTest.h>
#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 {

}

- (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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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 {
Expand All @@ -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);

Expand All @@ -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 {
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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
160 changes: 0 additions & 160 deletions Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m

This file was deleted.

Loading

0 comments on commit 6a0293a

Please sign in to comment.