FIRFunctionsTests.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2017 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <XCTest/XCTest.h>
  15. #import "Functions/FirebaseFunctions/FIRFunctions+Internal.h"
  16. #import "Functions/FirebaseFunctions/Public/FirebaseFunctions/FIRFunctions.h"
  17. @interface FIRFunctions (Test)
  18. @property(nonatomic, readonly) NSString *emulatorOrigin;
  19. @end
  20. @interface FIRFunctionsTests : XCTestCase
  21. @end
  22. @implementation FIRFunctionsTests {
  23. FIRFunctions *_functions;
  24. FIRFunctions *_functionsCustomDomain;
  25. }
  26. - (void)setUp {
  27. [super setUp];
  28. _functions = [[FIRFunctions alloc] initWithProjectID:@"my-project"
  29. region:@"my-region"
  30. customDomain:nil
  31. auth:nil
  32. messaging:nil];
  33. _functionsCustomDomain = [[FIRFunctions alloc] initWithProjectID:@"my-project"
  34. region:@"my-region"
  35. customDomain:@"https://mydomain.com"
  36. auth:nil
  37. messaging:nil];
  38. }
  39. - (void)tearDown {
  40. [super tearDown];
  41. }
  42. - (void)testURLWithName {
  43. NSString *url = [_functions URLWithName:@"my-endpoint"];
  44. XCTAssertEqualObjects(@"https://my-region-my-project.cloudfunctions.net/my-endpoint", url);
  45. }
  46. - (void)testRegionWithEmulator {
  47. [_functionsCustomDomain useEmulatorWithHost:@"localhost" port:5005];
  48. NSLog(@"%@", _functionsCustomDomain.emulatorOrigin);
  49. NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
  50. XCTAssertEqualObjects(@"localhost:5005/my-project/my-region/my-endpoint", url);
  51. }
  52. - (void)testCustomDomain {
  53. NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
  54. XCTAssertEqualObjects(@"https://mydomain.com/my-endpoint", url);
  55. }
  56. - (void)testCustomDomainWithEmulator {
  57. [_functionsCustomDomain useEmulatorWithHost:@"localhost" port:5005];
  58. NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
  59. XCTAssertEqualObjects(@"localhost:5005/my-project/my-region/my-endpoint", url);
  60. }
  61. - (void)testSetEmulatorSettings {
  62. [_functions useEmulatorWithHost:@"localhost" port:1000];
  63. XCTAssertEqualObjects(@"localhost:1000", _functions.emulatorOrigin);
  64. }
  65. @end