New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to domainURIPrefix
for FIRDynamicLinkComponents
#2119
Changes from 10 commits
5116bdc
2e82034
4260fde
2a3f260
16c4aab
2665390
2519db4
ead9b7b
be2f9b8
155ae37
73cf063
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ | |
|
||
#import <OCMock/OCMock.h> | ||
|
||
static NSString *const kFDLURLDomain = @"xyz.page.link"; | ||
static NSString *const kFDLURLDomain = @"https://xyz.page.link"; | ||
static NSString *const kFDLURLCustomDomain = @"https://foo.com/path"; | ||
|
||
@interface FDLURLComponentsTests : XCTestCase | ||
@end | ||
|
@@ -461,14 +462,14 @@ - (void)testLinkOptionsParamsPropertiesSetProperly { | |
|
||
- (void)testFDLComponentsFactoryReturnsInstanceOfCorrectClass { | ||
NSURL *link = [NSURL URLWithString:@"https://google.com"]; | ||
id returnValue = [FIRDynamicLinkComponents componentsWithLink:link domain:kFDLURLDomain]; | ||
id returnValue = [FIRDynamicLinkComponents componentsWithLink:link domainURIPrefix:kFDLURLDomain]; | ||
XCTAssertTrue([returnValue isKindOfClass:[FIRDynamicLinkComponents class]]); | ||
} | ||
|
||
- (void)testFDLComponentsFactoryReturnsInstanceWithAllNilProperties { | ||
NSURL *link = [NSURL URLWithString:@"https://google.com"]; | ||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:kFDLURLDomain]; | ||
[FIRDynamicLinkComponents componentsWithLink:link domainURIPrefix:kFDLURLDomain]; | ||
|
||
XCTAssertNil(components.analyticsParameters); | ||
XCTAssertNil(components.socialMetaTagParameters); | ||
|
@@ -484,11 +485,27 @@ - (void)testFDLComponentsCreatesSimplestLinkCorrectly { | |
NSURL *link = [NSURL URLWithString:linkString]; | ||
|
||
NSString *expectedURLString = | ||
[NSString stringWithFormat:@"https://%@/?link=%@", kFDLURLDomain, endcodedLinkString]; | ||
[NSString stringWithFormat:@"%@/?link=%@", kFDLURLDomain, endcodedLinkString]; | ||
NSURL *expectedURL = [NSURL URLWithString:expectedURLString]; | ||
|
||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:kFDLURLDomain]; | ||
[FIRDynamicLinkComponents componentsWithLink:link domainURIPrefix:kFDLURLDomain]; | ||
NSURL *actualURL = components.url; | ||
|
||
XCTAssertEqualObjects(actualURL, expectedURL); | ||
} | ||
|
||
- (void)testFDLComponentsCustomDomainWithPath { | ||
NSString *linkString = @"https://google.com"; | ||
NSString *endcodedLinkString = @"https%3A%2F%2Fgoogle%2Ecom"; | ||
NSURL *link = [NSURL URLWithString:linkString]; | ||
|
||
NSString *expectedURLString = | ||
[NSString stringWithFormat:@"%@/?link=%@", kFDLURLCustomDomain, endcodedLinkString]; | ||
NSURL *expectedURL = [NSURL URLWithString:expectedURLString]; | ||
|
||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domainURIPrefix:kFDLURLCustomDomain]; | ||
NSURL *actualURL = components.url; | ||
|
||
XCTAssertEqualObjects(actualURL, expectedURL); | ||
|
@@ -499,7 +516,8 @@ - (void)testFDLComponentsFailsOnMalformedDomain { | |
NSURL *link = [NSURL URLWithString:linkString]; | ||
|
||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:@"this is invalid domain"]; | ||
[FIRDynamicLinkComponents componentsWithLink:link | ||
domainURIPrefix:@"this is invalid domain URI Prefix"]; | ||
|
||
XCTAssertNil(components.url); | ||
} | ||
|
@@ -553,7 +571,7 @@ - (void)testFDLComponentsCreatesFullLinkCorrectly { | |
|
||
NSURL *link = [NSURL URLWithString:@"https://google.com"]; | ||
FIRDynamicLinkComponents *fdlComponents = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:kFDLURLDomain]; | ||
[FIRDynamicLinkComponents componentsWithLink:link domainURIPrefix:kFDLURLDomain]; | ||
fdlComponents.analyticsParameters = analyticsParams; | ||
fdlComponents.iOSParameters = iosParams; | ||
fdlComponents.iTunesConnectParameters = itcParams; | ||
|
@@ -642,7 +660,80 @@ - (void)testShortenURL { | |
XCTestExpectation *expectation = [self expectationWithDescription:@"completion called"]; | ||
NSURL *link = [NSURL URLWithString:@"https://google.com/abc"]; | ||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:kFDLURLDomain]; | ||
[FIRDynamicLinkComponents componentsWithLink:link domainURIPrefix:kFDLURLDomain]; | ||
[components | ||
shortenWithCompletion:^(NSURL *_Nullable shortURL, NSArray<NSString *> *_Nullable warnings, | ||
NSError *_Nullable error) { | ||
XCTAssertEqualObjects(shortURL.absoluteString, shortURLString); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:0.1 handler:nil]; | ||
|
||
[keyProviderClassMock verify]; | ||
[keyProviderClassMock stopMocking]; | ||
[componentsClassMock verify]; | ||
[componentsClassMock stopMocking]; | ||
} | ||
|
||
- (void)testDeprecatedMethodComponentsWithLinkForDomain { | ||
NSString *shortURLString = @"https://xyz.page.link/abcd"; | ||
|
||
// Mock key provider | ||
id keyProviderClassMock = OCMClassMock([FIRDynamicLinkComponentsKeyProvider class]); | ||
[[[keyProviderClassMock expect] andReturn:@"fake-api-key"] APIKey]; | ||
|
||
id componentsClassMock = OCMClassMock([FIRDynamicLinkComponents class]); | ||
[[componentsClassMock expect] | ||
sendHTTPRequest:OCMOCK_ANY | ||
completion:[OCMArg checkWithBlock:^BOOL(id obj) { | ||
void (^completion)(NSData *_Nullable, NSError *_Nullable) = obj; | ||
NSDictionary *JSON = @{@"shortLink" : shortURLString}; | ||
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:JSON options:0 error:0]; | ||
completion(JSONData, nil); | ||
return YES; | ||
}]]; | ||
|
||
XCTestExpectation *expectation = [self expectationWithDescription:@"completion called"]; | ||
NSURL *link = [NSURL URLWithString:@"https://google.com/abc"]; | ||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:@"xyz.page.link"]; | ||
[components | ||
shortenWithCompletion:^(NSURL *_Nullable shortURL, NSArray<NSString *> *_Nullable warnings, | ||
NSError *_Nullable error) { | ||
XCTAssertEqualObjects(shortURL.absoluteString, shortURLString); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:0.1 handler:nil]; | ||
|
||
[keyProviderClassMock verify]; | ||
[keyProviderClassMock stopMocking]; | ||
[componentsClassMock verify]; | ||
[componentsClassMock stopMocking]; | ||
} | ||
|
||
- (void)testDeprecatedMethodComponentsWithLinkForDomainWithInvalidDomainScheme { | ||
NSString *shortURLString = @"https://xyz.page.link/abcd"; | ||
|
||
// Mock key provider | ||
id keyProviderClassMock = OCMClassMock([FIRDynamicLinkComponentsKeyProvider class]); | ||
[[[keyProviderClassMock expect] andReturn:@"fake-api-key"] APIKey]; | ||
|
||
id componentsClassMock = OCMClassMock([FIRDynamicLinkComponents class]); | ||
[[componentsClassMock expect] | ||
sendHTTPRequest:OCMOCK_ANY | ||
completion:[OCMArg checkWithBlock:^BOOL(id obj) { | ||
void (^completion)(NSData *_Nullable, NSError *_Nullable) = obj; | ||
NSDictionary *JSON = @{@"shortLink" : shortURLString}; | ||
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:JSON options:0 error:0]; | ||
completion(JSONData, nil); | ||
return YES; | ||
}]]; | ||
|
||
XCTestExpectation *expectation = [self expectationWithDescription:@"completion called"]; | ||
NSURL *link = [NSURL URLWithString:@"https://google.com/abc"]; | ||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:@"http://xyz.page.link"]; | ||
XCTAssertNotNil(components); | ||
[components | ||
shortenWithCompletion:^(NSURL *_Nullable shortURL, NSArray<NSString *> *_Nullable warnings, | ||
NSError *_Nullable error) { | ||
|
@@ -679,7 +770,7 @@ - (void)testShortenURLReturnsErrorWhenAPIKeyMissing { | |
[self expectationWithDescription:@"completion called with error"]; | ||
NSURL *link = [NSURL URLWithString:@"https://google.com/abc"]; | ||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:kFDLURLDomain]; | ||
[FIRDynamicLinkComponents componentsWithLink:link domainURIPrefix:kFDLURLDomain]; | ||
[components | ||
shortenWithCompletion:^(NSURL *_Nullable shortURL, NSArray<NSString *> *_Nullable warnings, | ||
NSError *_Nullable error) { | ||
|
@@ -714,20 +805,11 @@ - (void)testShortenURLReturnsErrorWhenDomainIsMalformed { | |
return YES; | ||
}]]; | ||
|
||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"completion called with error"]; | ||
NSURL *link = [NSURL URLWithString:@"https://google.com/abc"]; | ||
FIRDynamicLinkComponents *components = | ||
[FIRDynamicLinkComponents componentsWithLink:link domain:@"this is invalid domain"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would also be good to keep (along with the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, will add more tests for the deprecated constructor. |
||
[components | ||
shortenWithCompletion:^(NSURL *_Nullable shortURL, NSArray<NSString *> *_Nullable warnings, | ||
NSError *_Nullable error) { | ||
XCTAssertNil(shortURL); | ||
if (error) { | ||
[expectation fulfill]; | ||
} | ||
}]; | ||
[self waitForExpectationsWithTimeout:0.1 handler:nil]; | ||
[FIRDynamicLinkComponents componentsWithLink:link | ||
domainURIPrefix:@"this is invalid domain URI Prefix"]; | ||
XCTAssertNil(components); | ||
|
||
[keyProviderClassMock verify]; | ||
[keyProviderClassMock stopMocking]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something I just realized now: it'd be good to keep a few tests around still for the old constructor to make sure we don't accidentally break it. I won't block this PR on it, but please add a few tests to make sure the old constructor isn't
nil
regardless of what's passed in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will add more tests for the deprecated constructor.