diff options
author | Paul Beusterien <paulbeusterien@google.com> | 2018-03-20 11:59:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-20 11:59:03 -0700 |
commit | b7f35a0b76bb2afd682b806d2b25568611612557 (patch) | |
tree | deb4577d3e54c3fafa2a065605faef228a186c1b /Functions/Example/IntegrationTests | |
parent | 7e65885762757209e0e14ec28e99ec91380e9c2f (diff) |
Initial Firebase Functions (#948)
Diffstat (limited to 'Functions/Example/IntegrationTests')
-rw-r--r-- | Functions/Example/IntegrationTests/FIRIntegrationTests.m | 190 | ||||
-rw-r--r-- | Functions/Example/IntegrationTests/IntegrationTests-Info.plist | 22 |
2 files changed, 212 insertions, 0 deletions
diff --git a/Functions/Example/IntegrationTests/FIRIntegrationTests.m b/Functions/Example/IntegrationTests/FIRIntegrationTests.m new file mode 100644 index 0000000..15a5af5 --- /dev/null +++ b/Functions/Example/IntegrationTests/FIRIntegrationTests.m @@ -0,0 +1,190 @@ +// Copyright 2017 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; + +#import "FIRError.h" +#import "FIRFunctions+Internal.h" +#import "FIRFunctions.h" +#import "FIRHTTPSCallable.h" +#import "FUNFakeApp.h" +#import "FUNFakeInstanceID.h" + +@interface FIRIntegrationTests : XCTestCase { + FIRFunctions *_functions; +} +@end + +@implementation FIRIntegrationTests + +- (void)setUp { + [super setUp]; + id app = [[FUNFakeApp alloc] initWithProjectID:@"functions-integration-test"]; + _functions = [FIRFunctions functionsForApp:app]; + [_functions useLocalhost]; +} + +- (void)tearDown { + [super tearDown]; +} + +- (void)testData { + NSDictionary *data = @{ + @"bool" : @YES, + @"int" : @2, + @"long" : @3L, + @"string" : @"four", + @"array" : @[ @5, @6 ], + @"null" : [NSNull null], + }; + + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"dataTest"]; + [function callWithObject:data + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNil(error); + XCTAssertEqualObjects(@"stub response", result.data[@"message"]); + XCTAssertEqualObjects(@42, result.data[@"code"]); + XCTAssertEqualObjects(@420L, result.data[@"long"]); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testScalar { + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"scalarTest"]; + [function callWithObject:@17 + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNil(error); + XCTAssertEqualObjects(@76, result.data); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testToken { + // Recreate _functions with a token. + id app = [[FUNFakeApp alloc] initWithProjectID:@"functions-integration-test" token:@"token"]; + FIRFunctions *functions = [FIRFunctions functionsForApp:app]; + [functions useLocalhost]; + + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [functions HTTPSCallableWithName:@"tokenTest"]; + [function callWithObject:@{} + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNil(error); + XCTAssertEqualObjects(@{}, result.data); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testInstanceID { + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"instanceIdTest"]; + [function callWithObject:@{} + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNil(error); + XCTAssertEqualObjects(@{}, result.data); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testNull { + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"nullTest"]; + [function callWithObject:[NSNull null] + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertEqualObjects([NSNull null], result.data); + XCTAssertNil(error); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; + + // Test the version with no arguments. + [function + callWithCompletion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertEqualObjects([NSNull null], result.data); + XCTAssertNil(error); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testMissingResult { + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"missingResultTest"]; + [function + callWithCompletion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNotNil(error); + XCTAssertEqual(FIRFunctionsErrorCodeInternal, error.code); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testUnhandledError { + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"unhandledErrorTest"]; + [function callWithObject:@{} + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNotNil(error); + XCTAssertEqual(FIRFunctionsErrorCodeInternal, error.code); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testUnknownError { + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"unknownErrorTest"]; + [function callWithObject:@{} + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNotNil(error); + XCTAssertEqual(FIRFunctionsErrorCodeInternal, error.code); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testExplicitError { + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"explicitErrorTest"]; + [function callWithObject:@{} + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNotNil(error); + XCTAssertEqual(FIRFunctionsErrorCodeOutOfRange, error.code); + XCTAssertEqualObjects(@"explicit nope", error.userInfo[NSLocalizedDescriptionKey]); + NSDictionary *expectedDetails = @{ @"start" : @10, @"end" : @20, @"long" : @30L }; + XCTAssertEqualObjects(expectedDetails, error.userInfo[FIRFunctionsErrorDetailsKey]); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +- (void)testHttpError { + XCTestExpectation *expectation = [[XCTestExpectation alloc] init]; + FIRHTTPSCallable *function = [_functions HTTPSCallableWithName:@"httpErrorTest"]; + [function callWithObject:@{} + completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { + XCTAssertNotNil(error); + XCTAssertEqual(FIRFunctionsErrorCodeInvalidArgument, error.code); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:10]; +} + +@end diff --git a/Functions/Example/IntegrationTests/IntegrationTests-Info.plist b/Functions/Example/IntegrationTests/IntegrationTests-Info.plist new file mode 100644 index 0000000..169b6f7 --- /dev/null +++ b/Functions/Example/IntegrationTests/IntegrationTests-Info.plist @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>en</string> + <key>CFBundleExecutable</key> + <string>${EXECUTABLE_NAME}</string> + <key>CFBundleIdentifier</key> + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>BNDL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>1</string> +</dict> +</plist> |