-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from BranchMetrics/SDK-2350-sync-3.4.1
SDK-2350 sync 3.4.1
- Loading branch information
Showing
51 changed files
with
878 additions
and
2,335 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
Branch-TestBed/Branch-SDK-Tests/BNCClassSerializationTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// | ||
// BNCClassSerializationTests.m | ||
// Branch-SDK-Tests | ||
// | ||
// Created by Ernest Cho on 3/28/24. | ||
// Copyright © 2024 Branch, Inc. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import "BranchEvent.h" | ||
#import "BranchOpenRequest.h" | ||
#import "BranchInstallRequest.h" | ||
|
||
@interface BranchEvent() | ||
// private BranchEvent methods used to build a BranchEventRequest | ||
- (NSDictionary *)buildEventDictionary; | ||
@end | ||
|
||
@interface BranchOpenRequest() | ||
- (NSString *)getActionName; | ||
@end | ||
|
||
@interface BNCClassSerializationTests : XCTestCase | ||
|
||
@end | ||
|
||
// Test serialization of replayable requests | ||
@implementation BNCClassSerializationTests | ||
|
||
- (void)setUp { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
- (void)tearDown { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
// BranchEventRequest is creation is tightly coupled with the BranchEvent class | ||
// In order to test building it, we need to expose some private methods. :( | ||
- (BranchEventRequest *)buildBranchEventRequest { | ||
BranchEvent *event = [BranchEvent standardEvent:BranchStandardEventPurchase]; | ||
NSURL *url = [NSURL URLWithString:@"https://api3.branch.io/v2/event/standard"]; | ||
NSDictionary *eventDictionary = [event buildEventDictionary]; | ||
|
||
BranchEventRequest *request = [[BranchEventRequest alloc] initWithServerURL:url eventDictionary:eventDictionary completion:nil]; | ||
return request; | ||
} | ||
|
||
- (void)testBranchEventRequestArchive { | ||
BranchEventRequest *request = [self buildBranchEventRequest]; | ||
|
||
// archive the event | ||
NSError *error = nil; | ||
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:request requiringSecureCoding:YES error:&error]; | ||
XCTAssertNil(error); | ||
XCTAssertNotNil(data); | ||
|
||
// unarchive the event | ||
id object = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet setWithArray:@[BranchEventRequest.class]] fromData:data error:&error]; | ||
XCTAssertNil(error); | ||
XCTAssertNotNil(object); | ||
|
||
// check object | ||
XCTAssertTrue([object isKindOfClass:BranchEventRequest.class]); | ||
BranchEventRequest *unarchivedRequest = (BranchEventRequest *)object; | ||
|
||
XCTAssertTrue([request.serverURL.absoluteString isEqualToString:unarchivedRequest.serverURL.absoluteString]); | ||
XCTAssertTrue(request.eventDictionary.count == unarchivedRequest.eventDictionary.count); | ||
XCTAssertNil(unarchivedRequest.completion); | ||
} | ||
|
||
- (void)testBranchOpenRequestArchive { | ||
BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:nil]; | ||
request.urlString = @"https://branch.io"; | ||
|
||
// archive the event | ||
NSError *error = nil; | ||
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:request requiringSecureCoding:YES error:&error]; | ||
XCTAssertNil(error); | ||
XCTAssertNotNil(data); | ||
|
||
// unarchive the event | ||
id object = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet setWithArray:@[BranchOpenRequest.class]] fromData:data error:&error]; | ||
XCTAssertNil(error); | ||
XCTAssertNotNil(object); | ||
|
||
// check object | ||
XCTAssertTrue([object isKindOfClass:BranchOpenRequest.class]); | ||
BranchOpenRequest *unarchivedRequest = (BranchOpenRequest *)object; | ||
|
||
XCTAssertTrue([request.urlString isEqualToString:unarchivedRequest.urlString]); | ||
XCTAssertNil(unarchivedRequest.callback); | ||
XCTAssertTrue([@"open" isEqualToString:[unarchivedRequest getActionName]]); | ||
} | ||
|
||
- (void)testBranchInstallRequestArchive { | ||
BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:nil]; | ||
request.urlString = @"https://branch.io"; | ||
|
||
// archive the event | ||
NSError *error = nil; | ||
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:request requiringSecureCoding:YES error:&error]; | ||
XCTAssertNil(error); | ||
XCTAssertNotNil(data); | ||
|
||
// unarchive the event | ||
id object = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet setWithArray:@[BranchInstallRequest.class]] fromData:data error:&error]; | ||
XCTAssertNil(error); | ||
XCTAssertNotNil(object); | ||
|
||
// check object | ||
XCTAssertTrue([object isKindOfClass:BranchInstallRequest.class]); | ||
BranchInstallRequest *unarchivedRequest = (BranchInstallRequest *)object; | ||
|
||
XCTAssertTrue([request.urlString isEqualToString:unarchivedRequest.urlString]); | ||
XCTAssertNil(unarchivedRequest.callback); | ||
XCTAssertTrue([@"install" isEqualToString:[unarchivedRequest getActionName]]); | ||
} | ||
|
||
@end |
Oops, something went wrong.