21
21
22
22
#import < OCMock/OCMock.h>
23
23
24
- static NSString *const kFDLURLDomain = @" xyz.page.link" ;
24
+ static NSString *const kFDLURLDomain = @" https://xyz.page.link" ;
25
+ static NSString *const kFDLURLCustomDomain = @" https://foo.com/path" ;
25
26
26
27
@interface FDLURLComponentsTests : XCTestCase
27
28
@end
@@ -461,14 +462,14 @@ - (void)testLinkOptionsParamsPropertiesSetProperly {
461
462
462
463
- (void )testFDLComponentsFactoryReturnsInstanceOfCorrectClass {
463
464
NSURL *link = [NSURL URLWithString: @" https://google.com" ];
464
- id returnValue = [FIRDynamicLinkComponents componentsWithLink: link domain :kFDLURLDomain ];
465
+ id returnValue = [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix :kFDLURLDomain ];
465
466
XCTAssertTrue ([returnValue isKindOfClass: [FIRDynamicLinkComponents class ]]);
466
467
}
467
468
468
469
- (void )testFDLComponentsFactoryReturnsInstanceWithAllNilProperties {
469
470
NSURL *link = [NSURL URLWithString: @" https://google.com" ];
470
471
FIRDynamicLinkComponents *components =
471
- [FIRDynamicLinkComponents componentsWithLink: link domain :kFDLURLDomain ];
472
+ [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix :kFDLURLDomain ];
472
473
473
474
XCTAssertNil (components.analyticsParameters );
474
475
XCTAssertNil (components.socialMetaTagParameters );
@@ -484,11 +485,27 @@ - (void)testFDLComponentsCreatesSimplestLinkCorrectly {
484
485
NSURL *link = [NSURL URLWithString: linkString];
485
486
486
487
NSString *expectedURLString =
487
- [NSString stringWithFormat: @" https:// %@ /?link=%@ " , kFDLURLDomain , endcodedLinkString];
488
+ [NSString stringWithFormat: @" %@ /?link=%@ " , kFDLURLDomain , endcodedLinkString];
488
489
NSURL *expectedURL = [NSURL URLWithString: expectedURLString];
489
490
490
491
FIRDynamicLinkComponents *components =
491
- [FIRDynamicLinkComponents componentsWithLink: link domain: kFDLURLDomain ];
492
+ [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix: kFDLURLDomain ];
493
+ NSURL *actualURL = components.url ;
494
+
495
+ XCTAssertEqualObjects (actualURL, expectedURL);
496
+ }
497
+
498
+ - (void )testFDLComponentsCustomDomainWithPath {
499
+ NSString *linkString = @" https://google.com" ;
500
+ NSString *endcodedLinkString = @" https%3A%2F%2F google%2E com" ;
501
+ NSURL *link = [NSURL URLWithString: linkString];
502
+
503
+ NSString *expectedURLString =
504
+ [NSString stringWithFormat: @" %@ /?link=%@ " , kFDLURLCustomDomain , endcodedLinkString];
505
+ NSURL *expectedURL = [NSURL URLWithString: expectedURLString];
506
+
507
+ FIRDynamicLinkComponents *components =
508
+ [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix: kFDLURLCustomDomain ];
492
509
NSURL *actualURL = components.url ;
493
510
494
511
XCTAssertEqualObjects (actualURL, expectedURL);
@@ -499,7 +516,8 @@ - (void)testFDLComponentsFailsOnMalformedDomain {
499
516
NSURL *link = [NSURL URLWithString: linkString];
500
517
501
518
FIRDynamicLinkComponents *components =
502
- [FIRDynamicLinkComponents componentsWithLink: link domain: @" this is invalid domain" ];
519
+ [FIRDynamicLinkComponents componentsWithLink: link
520
+ domainURIPrefix: @" this is invalid domain URI Prefix" ];
503
521
504
522
XCTAssertNil (components.url );
505
523
}
@@ -553,7 +571,7 @@ - (void)testFDLComponentsCreatesFullLinkCorrectly {
553
571
554
572
NSURL *link = [NSURL URLWithString: @" https://google.com" ];
555
573
FIRDynamicLinkComponents *fdlComponents =
556
- [FIRDynamicLinkComponents componentsWithLink: link domain :kFDLURLDomain ];
574
+ [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix :kFDLURLDomain ];
557
575
fdlComponents.analyticsParameters = analyticsParams;
558
576
fdlComponents.iOSParameters = iosParams;
559
577
fdlComponents.iTunesConnectParameters = itcParams;
@@ -642,7 +660,43 @@ - (void)testShortenURL {
642
660
XCTestExpectation *expectation = [self expectationWithDescription: @" completion called" ];
643
661
NSURL *link = [NSURL URLWithString: @" https://google.com/abc" ];
644
662
FIRDynamicLinkComponents *components =
645
- [FIRDynamicLinkComponents componentsWithLink: link domain: kFDLURLDomain ];
663
+ [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix: kFDLURLDomain ];
664
+ [components
665
+ shortenWithCompletion: ^(NSURL *_Nullable shortURL, NSArray <NSString *> *_Nullable warnings,
666
+ NSError *_Nullable error) {
667
+ XCTAssertEqualObjects (shortURL.absoluteString , shortURLString);
668
+ [expectation fulfill ];
669
+ }];
670
+ [self waitForExpectationsWithTimeout: 0.1 handler: nil ];
671
+
672
+ [keyProviderClassMock verify ];
673
+ [keyProviderClassMock stopMocking ];
674
+ [componentsClassMock verify ];
675
+ [componentsClassMock stopMocking ];
676
+ }
677
+
678
+ - (void )testDeprecatedMethodComponentsWithLinkForDomain {
679
+ NSString *shortURLString = @" https://xyz.page.link/abcd" ;
680
+
681
+ // Mock key provider
682
+ id keyProviderClassMock = OCMClassMock ([FIRDynamicLinkComponentsKeyProvider class ]);
683
+ [[[keyProviderClassMock expect ] andReturn: @" fake-api-key" ] APIKey ];
684
+
685
+ id componentsClassMock = OCMClassMock ([FIRDynamicLinkComponents class ]);
686
+ [[componentsClassMock expect ]
687
+ sendHTTPRequest: OCMOCK_ANY
688
+ completion: [OCMArg checkWithBlock: ^BOOL (id obj) {
689
+ void (^completion)(NSData *_Nullable, NSError *_Nullable) = obj;
690
+ NSDictionary *JSON = @{@" shortLink" : shortURLString};
691
+ NSData *JSONData = [NSJSONSerialization dataWithJSONObject: JSON options: 0 error: 0 ];
692
+ completion (JSONData, nil );
693
+ return YES ;
694
+ }]];
695
+
696
+ XCTestExpectation *expectation = [self expectationWithDescription: @" completion called" ];
697
+ NSURL *link = [NSURL URLWithString: @" https://google.com/abc" ];
698
+ FIRDynamicLinkComponents *components =
699
+ [FIRDynamicLinkComponents componentsWithLink: link domain: @" xyz.page.link" ];
646
700
[components
647
701
shortenWithCompletion: ^(NSURL *_Nullable shortURL, NSArray <NSString *> *_Nullable warnings,
648
702
NSError *_Nullable error) {
@@ -679,7 +733,7 @@ - (void)testShortenURLReturnsErrorWhenAPIKeyMissing {
679
733
[self expectationWithDescription: @" completion called with error" ];
680
734
NSURL *link = [NSURL URLWithString: @" https://google.com/abc" ];
681
735
FIRDynamicLinkComponents *components =
682
- [FIRDynamicLinkComponents componentsWithLink: link domain :kFDLURLDomain ];
736
+ [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix :kFDLURLDomain ];
683
737
[components
684
738
shortenWithCompletion: ^(NSURL *_Nullable shortURL, NSArray <NSString *> *_Nullable warnings,
685
739
NSError *_Nullable error) {
@@ -714,20 +768,11 @@ - (void)testShortenURLReturnsErrorWhenDomainIsMalformed {
714
768
return YES ;
715
769
}]];
716
770
717
- XCTestExpectation *expectation =
718
- [self expectationWithDescription: @" completion called with error" ];
719
771
NSURL *link = [NSURL URLWithString: @" https://google.com/abc" ];
720
772
FIRDynamicLinkComponents *components =
721
- [FIRDynamicLinkComponents componentsWithLink: link domain: @" this is invalid domain" ];
722
- [components
723
- shortenWithCompletion: ^(NSURL *_Nullable shortURL, NSArray <NSString *> *_Nullable warnings,
724
- NSError *_Nullable error) {
725
- XCTAssertNil (shortURL);
726
- if (error) {
727
- [expectation fulfill ];
728
- }
729
- }];
730
- [self waitForExpectationsWithTimeout: 0.1 handler: nil ];
773
+ [FIRDynamicLinkComponents componentsWithLink: link
774
+ domainURIPrefix: @" this is invalid domain URI Prefix" ];
775
+ XCTAssertNil (components);
731
776
732
777
[keyProviderClassMock verify ];
733
778
[keyProviderClassMock stopMocking ];
0 commit comments