Files
firebase-ios-sdk/Example/DynamicLinks/Tests/FIRDynamicLinkNetworkingTests.m
T
dmandar 36b79e633f Move to domainURIPrefix for FIRDynamicLinkComponents (#2119)
* Revert "Revert premature api changes (#2097)"
The new API is optional and current API is fully supported.

This reverts commit 46cb564067.

* Update comments to reflect API changes.

* Mark the FDLURLComponents initializer return as nullable.

* Run Style.

* Allow for new initializer for FIRDynamicLinkComponents to have a nullable instancetype return.

* Update Changelog for v3.3.0

* Keep deprecated method initalization separate.

* Comments updates and other minor fixes.

* Consider domainURIPrefixes for exact matches with incoming short/long URLs.

* Add warning for deprecated API if developer passes in a domain with a scheme.
2018-11-29 13:58:38 -05:00

101 lines
3.4 KiB
Objective-C

/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import <GoogleUtilities/GULSwizzler.h>
#import "DynamicLinks/FIRDynamicLinkNetworking+Private.h"
static NSString *const kAPIKey = @"myfakeapikey";
static NSString *const kClientID = @"myfakeclientid";
const NSInteger kJSONParsingErrorCode = 3840;
static NSString *const kURLScheme = @"gindeeplinkurl";
static const NSTimeInterval kAsyncTestTimout = 0.5;
@interface FIRDynamicLinkNetworkingTests : XCTestCase
@property(strong, nonatomic) FIRDynamicLinkNetworking *service;
@end
@implementation FIRDynamicLinkNetworkingTests
- (void)tearDown {
self.service = nil;
}
- (FIRDynamicLinkNetworking *)service {
if (!_service) {
_service = [[FIRDynamicLinkNetworking alloc] initWithAPIKey:kAPIKey
clientID:kClientID
URLScheme:kURLScheme];
}
return _service;
}
- (void)testFIRDynamicLinkAPIKeyParameterReturnsCorrectlyFormattedParameterString {
NSString *expectedValue = [NSString stringWithFormat:@"?key=%@", kAPIKey];
NSString *parameter = FIRDynamicLinkAPIKeyParameter(kAPIKey);
XCTAssertEqualObjects(parameter, expectedValue,
@"FIRDynamicLinkAPIKeyParameter() returned incorrect parameter string");
}
- (void)testFIRDynamicLinkAPIKeyParameterReturnsNilParameterStringWhenAPIKeyIsNil {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
NSString *parameter = FIRDynamicLinkAPIKeyParameter(nil);
#pragma clang diagnostic pop
XCTAssertNil(parameter,
@"FIRDynamicLinkAPIKeyParameter() returned non-nil result when API key was nil");
}
- (void)testResolveShortLinkServiceCompletionDoesntCrashWhenNilDataIsRetrieved {
NSURL *url = [NSURL URLWithString:@"https://google.com"];
void (^executeRequestBlock)(id, NSDictionary *, NSString *, FIRNetworkRequestCompletionHandler) =
^(id p1, NSDictionary *requestBody, NSString *requestURLString,
FIRNetworkRequestCompletionHandler handler) {
handler(nil, nil);
};
SEL executeRequestSelector = @selector(executeOnePlatformRequest:forURL:completionHandler:);
[GULSwizzler swizzleClass:[FIRDynamicLinkNetworking class]
selector:executeRequestSelector
isClassSelector:NO
withBlock:executeRequestBlock];
XCTestExpectation *expectation = [self expectationWithDescription:@"completion called"];
[self.service resolveShortLink:url
completion:^(NSURL *_Nullable url, NSError *_Nullable error) {
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kAsyncTestTimout handler:nil];
[GULSwizzler unswizzleClass:[FIRDynamicLinkNetworking class]
selector:executeRequestSelector
isClassSelector:NO];
}
@end