FIRFunctionsTests.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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(@"http://localhost:5005/my-project/my-region/my-endpoint", url);
  51. }
  52. - (void)testRegionWithEmulatorWithScheme {
  53. [_functionsCustomDomain useEmulatorWithHost:@"http://localhost" port:5005];
  54. NSLog(@"%@", _functionsCustomDomain.emulatorOrigin);
  55. NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
  56. XCTAssertEqualObjects(@"http://localhost:5005/my-project/my-region/my-endpoint", url);
  57. }
  58. - (void)testCustomDomain {
  59. NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
  60. XCTAssertEqualObjects(@"https://mydomain.com/my-endpoint", url);
  61. }
  62. - (void)testCustomDomainWithEmulator {
  63. [_functionsCustomDomain useEmulatorWithHost:@"localhost" port:5005];
  64. NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
  65. XCTAssertEqualObjects(@"http://localhost:5005/my-project/my-region/my-endpoint", url);
  66. }
  67. - (void)testSetEmulatorSettings {
  68. [_functions useEmulatorWithHost:@"localhost" port:1000];
  69. XCTAssertEqualObjects(@"http://localhost:1000", _functions.emulatorOrigin);
  70. }
  71. @end