21
21
22
22
#import < OCMock/OCMock.h>
23
23
24
- static NSString *const kFDLURLDomain = @" https://xyz.page.link" ;
25
- static NSString *const kFDLURLCustomDomain = @" https://foo.com/path" ;
24
+ static NSString *const kFDLURLDomain = @" xyz.page.link" ;
26
25
27
26
@interface FDLURLComponentsTests : XCTestCase
28
27
@end
@@ -462,14 +461,14 @@ - (void)testLinkOptionsParamsPropertiesSetProperly {
462
461
463
462
- (void )testFDLComponentsFactoryReturnsInstanceOfCorrectClass {
464
463
NSURL *link = [NSURL URLWithString: @" https://google.com" ];
465
- id returnValue = [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix :kFDLURLDomain ];
464
+ id returnValue = [FIRDynamicLinkComponents componentsWithLink: link domain :kFDLURLDomain ];
466
465
XCTAssertTrue ([returnValue isKindOfClass: [FIRDynamicLinkComponents class ]]);
467
466
}
468
467
469
468
- (void )testFDLComponentsFactoryReturnsInstanceWithAllNilProperties {
470
469
NSURL *link = [NSURL URLWithString: @" https://google.com" ];
471
470
FIRDynamicLinkComponents *components =
472
- [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix :kFDLURLDomain ];
471
+ [FIRDynamicLinkComponents componentsWithLink: link domain :kFDLURLDomain ];
473
472
474
473
XCTAssertNil (components.analyticsParameters );
475
474
XCTAssertNil (components.socialMetaTagParameters );
@@ -485,27 +484,11 @@ - (void)testFDLComponentsCreatesSimplestLinkCorrectly {
485
484
NSURL *link = [NSURL URLWithString: linkString];
486
485
487
486
NSString *expectedURLString =
488
- [NSString stringWithFormat: @" %@ /?link=%@ " , kFDLURLDomain , endcodedLinkString];
487
+ [NSString stringWithFormat: @" https:// %@ /?link=%@ " , kFDLURLDomain , endcodedLinkString];
489
488
NSURL *expectedURL = [NSURL URLWithString: expectedURLString];
490
489
491
490
FIRDynamicLinkComponents *components =
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 ];
491
+ [FIRDynamicLinkComponents componentsWithLink: link domain: kFDLURLDomain ];
509
492
NSURL *actualURL = components.url ;
510
493
511
494
XCTAssertEqualObjects (actualURL, expectedURL);
@@ -516,8 +499,7 @@ - (void)testFDLComponentsFailsOnMalformedDomain {
516
499
NSURL *link = [NSURL URLWithString: linkString];
517
500
518
501
FIRDynamicLinkComponents *components =
519
- [FIRDynamicLinkComponents componentsWithLink: link
520
- domainURIPrefix: @" this is invalid domain URI Prefix" ];
502
+ [FIRDynamicLinkComponents componentsWithLink: link domain: @" this is invalid domain" ];
521
503
522
504
XCTAssertNil (components.url );
523
505
}
@@ -571,7 +553,7 @@ - (void)testFDLComponentsCreatesFullLinkCorrectly {
571
553
572
554
NSURL *link = [NSURL URLWithString: @" https://google.com" ];
573
555
FIRDynamicLinkComponents *fdlComponents =
574
- [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix :kFDLURLDomain ];
556
+ [FIRDynamicLinkComponents componentsWithLink: link domain :kFDLURLDomain ];
575
557
fdlComponents.analyticsParameters = analyticsParams;
576
558
fdlComponents.iOSParameters = iosParams;
577
559
fdlComponents.iTunesConnectParameters = itcParams;
@@ -660,43 +642,7 @@ - (void)testShortenURL {
660
642
XCTestExpectation *expectation = [self expectationWithDescription: @" completion called" ];
661
643
NSURL *link = [NSURL URLWithString: @" https://google.com/abc" ];
662
644
FIRDynamicLinkComponents *components =
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" ];
645
+ [FIRDynamicLinkComponents componentsWithLink: link domain: kFDLURLDomain ];
700
646
[components
701
647
shortenWithCompletion: ^(NSURL *_Nullable shortURL, NSArray <NSString *> *_Nullable warnings,
702
648
NSError *_Nullable error) {
@@ -733,7 +679,7 @@ - (void)testShortenURLReturnsErrorWhenAPIKeyMissing {
733
679
[self expectationWithDescription: @" completion called with error" ];
734
680
NSURL *link = [NSURL URLWithString: @" https://google.com/abc" ];
735
681
FIRDynamicLinkComponents *components =
736
- [FIRDynamicLinkComponents componentsWithLink: link domainURIPrefix :kFDLURLDomain ];
682
+ [FIRDynamicLinkComponents componentsWithLink: link domain :kFDLURLDomain ];
737
683
[components
738
684
shortenWithCompletion: ^(NSURL *_Nullable shortURL, NSArray <NSString *> *_Nullable warnings,
739
685
NSError *_Nullable error) {
@@ -768,11 +714,20 @@ - (void)testShortenURLReturnsErrorWhenDomainIsMalformed {
768
714
return YES ;
769
715
}]];
770
716
717
+ XCTestExpectation *expectation =
718
+ [self expectationWithDescription: @" completion called with error" ];
771
719
NSURL *link = [NSURL URLWithString: @" https://google.com/abc" ];
772
720
FIRDynamicLinkComponents *components =
773
- [FIRDynamicLinkComponents componentsWithLink: link
774
- domainURIPrefix: @" this is invalid domain URI Prefix" ];
775
- XCTAssertNil (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 ];
776
731
777
732
[keyProviderClassMock verify ];
778
733
[keyProviderClassMock stopMocking ];
0 commit comments