Skip to content

Commit

Permalink
Fixed Unit tests and added encoding functions
Browse files Browse the repository at this point in the history
* Fixed property type of linkParams (strong) and added code to initialize it.
* Added encoding functions for class BranchOpenRequestLinkParams.
* Fixed value passed to saveAppClipData. It should be local variable referringURL.
  • Loading branch information
NidhiDixit09 committed Dec 4, 2024
1 parent 943ab31 commit 2d63de1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
10 changes: 6 additions & 4 deletions Branch-TestBed/Branch-SDK-Tests/BNCClassSerializationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ - (void)testBranchEventRequestArchive {

- (void)testBranchOpenRequestArchive {
BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:nil];
request.urlString = @"https://branch.io";
request.linkParams = [[BranchOpenRequestLinkParams alloc] init];
request.linkParams.referringURL = @"https://branch.io";

// archive the event
NSError *error = nil;
Expand All @@ -88,14 +89,15 @@ - (void)testBranchOpenRequestArchive {
XCTAssertTrue([object isKindOfClass:BranchOpenRequest.class]);
BranchOpenRequest *unarchivedRequest = (BranchOpenRequest *)object;

XCTAssertTrue([request.urlString isEqualToString:unarchivedRequest.urlString]);
XCTAssertTrue([request.linkParams.referringURL isEqualToString:unarchivedRequest.linkParams.referringURL]);
XCTAssertNil(unarchivedRequest.callback);
XCTAssertTrue([@"open" isEqualToString:[unarchivedRequest getActionName]]);
}

- (void)testBranchInstallRequestArchive {
BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:nil];
request.urlString = @"https://branch.io";
request.linkParams = [[BranchOpenRequestLinkParams alloc] init];
request.linkParams.referringURL = @"https://branch.io";

// archive the event
NSError *error = nil;
Expand All @@ -112,7 +114,7 @@ - (void)testBranchInstallRequestArchive {
XCTAssertTrue([object isKindOfClass:BranchInstallRequest.class]);
BranchInstallRequest *unarchivedRequest = (BranchInstallRequest *)object;

XCTAssertTrue([request.urlString isEqualToString:unarchivedRequest.urlString]);
XCTAssertTrue([request.linkParams.referringURL isEqualToString:unarchivedRequest.linkParams.referringURL]);
XCTAssertNil(unarchivedRequest.callback);
XCTAssertTrue([@"install" isEqualToString:[unarchivedRequest getActionName]]);
}
Expand Down
7 changes: 0 additions & 7 deletions Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,6 @@ - (void)testSetLastStrongMatchDate {
XCTAssertEqualObjects(expectedDate, actualDate);
}

- (void)testSetAppVersion {
NSString *expectedVersion = @"1.0.0";
[self.prefHelper setAppVersion: expectedVersion];

NSString *actualVersion = [self.prefHelper appVersion];
XCTAssertEqualObjects(expectedVersion, actualVersion);
}

- (void)testSetLocalUrl {
NSString *expectedLocalURL = @"https://local.example.com";
Expand Down
10 changes: 5 additions & 5 deletions Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)tearDown {

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

// key is omitted when nil
Expand All @@ -40,7 +40,7 @@ - (void)testInitWithBranchKeyNil {

- (void)testInitWithBranchKeyEmpty {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);

// empty string is allowed
Expand All @@ -52,7 +52,7 @@ - (void)testInitWithBranchKeyEmpty {

- (void)testInitWithBranchKey {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);

Expand All @@ -62,7 +62,7 @@ - (void)testInitWithBranchKey {

- (void)testDataForInstall {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);

XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
Expand All @@ -79,7 +79,7 @@ - (void)testDataForInstall {

- (void)testDataForOpen {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *json = [factory dataForOpenWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);

XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
Expand Down
26 changes: 22 additions & 4 deletions Sources/BranchSDK/BranchOpenRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ - (id)initWithCallback:(callbackWithStatus)callback isInstall:(BOOL)isInstall {
if ((self = [super init])) {
_callback = callback;
_isInstall = isInstall;
_linkParams = [[BranchOpenRequestLinkParams alloc] init];
}

return self;
Expand Down Expand Up @@ -166,7 +167,7 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error {
[BranchOpenRequest releaseOpenResponseLock];

if (self.isInstall) {
[[BNCAppGroupsData shared] saveAppClipData: self.linkParams.referringURL];
[[BNCAppGroupsData shared] saveAppClipData: referringURL];
}

#if !TARGET_OS_TV
Expand Down Expand Up @@ -248,14 +249,15 @@ - (NSString *)getActionName {

- (instancetype)initWithCoder:(NSCoder *)decoder {
self = [super initWithCoder:decoder];
if (!self) return self;
self.linkParams.referringURL = [decoder decodeObjectOfClass:NSString.class forKey:@"urlString"];
if (self) {
self.linkParams = [decoder decodeObjectOfClass:BranchOpenRequestLinkParams.class forKey:@"urlString"];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];
[coder encodeObject:self.linkParams.referringURL forKey:@"urlString"];
[coder encodeObject:self.linkParams forKey:@"urlString"];
}

+ (BOOL)supportsSecureCoding {
Expand Down Expand Up @@ -322,4 +324,20 @@ - (instancetype)init
return self;
}

- (instancetype)initWithCoder:(NSCoder *)decoder {
self = [super init];
if (self) {
self.referringURL = [decoder decodeObjectOfClass:NSString.class forKey:@"referringURL"];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:self.referringURL forKey:@"referringURL"];
}

+ (BOOL)supportsSecureCoding {
return YES;
}

@end
1 change: 0 additions & 1 deletion Sources/BranchSDK/Private/BNCRequestFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import <Foundation/Foundation.h>
#import "BranchOpenRequest.h"
#import "BranchInstallRequest.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
4 changes: 2 additions & 2 deletions Sources/BranchSDK/Private/BranchOpenRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "BNCServerRequest.h"
#import "BNCCallbacks.h"

@interface BranchOpenRequestLinkParams : NSObject
@interface BranchOpenRequestLinkParams : NSObject <NSSecureCoding>
@property (copy, nonatomic) NSString *linkClickIdentifier;
@property (copy, nonatomic) NSString *spotlightIdentifier;
@property (copy, nonatomic) NSString *referringURL; // URL that triggered this install or open event
Expand All @@ -20,7 +20,7 @@


@property (nonatomic, copy) callbackWithStatus callback;
@property (nonatomic, copy, readwrite) BranchOpenRequestLinkParams *linkParams;
@property (nonatomic, strong, readwrite) BranchOpenRequestLinkParams *linkParams;

+ (void) waitForOpenResponseLock;
+ (void) releaseOpenResponseLock;
Expand Down

0 comments on commit 2d63de1

Please sign in to comment.