FIRGetProjectConfigRequestTests.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  18. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetProjectConfigRequest.h"
  19. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetProjectConfigResponse.h"
  20. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  21. /** @var kGetProjectConfigEndPoint
  22. @brief The "getProjectConfig" endpoint.
  23. */
  24. static NSString *const kGetProjectConfigEndPoint = @"getProjectConfig";
  25. /** @var kTestAPIKey
  26. @brief Fake API key used for testing.
  27. */
  28. static NSString *const kTestAPIKey = @"APIKey";
  29. /** @var kTestFirebaseAppID
  30. @brief Fake Firebase app ID used for testing.
  31. */
  32. static NSString *const kTestFirebaseAppID = @"appID";
  33. /** @var kAPIURLFormat
  34. @brief URL format for server API calls.
  35. */
  36. static NSString *const kAPIURLFormat = @"https://%@/identitytoolkit/v3/relyingparty/%@?key=%@";
  37. /** @var gAPIHost
  38. @brief Host for server API calls.
  39. */
  40. static NSString *gAPIHost = @"www.googleapis.com";
  41. @interface FIRGetProjectConfigRequestTests : XCTestCase
  42. @end
  43. @implementation FIRGetProjectConfigRequestTests {
  44. /** @var _RPCIssuer
  45. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  46. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  47. */
  48. FIRFakeBackendRPCIssuer *_RPCIssuer;
  49. }
  50. - (void)setUp {
  51. [super setUp];
  52. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  53. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  54. _RPCIssuer = RPCIssuer;
  55. }
  56. - (void)tearDown {
  57. _RPCIssuer = nil;
  58. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  59. [super tearDown];
  60. }
  61. /** @fn testGetProjectConfigRequest
  62. @brief Tests get project config request.
  63. */
  64. - (void)testGetProjectConfigRequest {
  65. FIRAuthRequestConfiguration *requestConfiguration =
  66. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey appID:kTestFirebaseAppID];
  67. FIRGetProjectConfigRequest *request =
  68. [[FIRGetProjectConfigRequest alloc] initWithRequestConfiguration:requestConfiguration];
  69. [FIRAuthBackend
  70. getProjectConfig:request
  71. callback:^(FIRGetProjectConfigResponse *_Nullable response, NSError *_Nullable error){
  72. }];
  73. XCTAssertFalse([request containsPostBody]);
  74. // Confirm that the quest has no decoded body as it is get request.
  75. XCTAssertNil(_RPCIssuer.decodedRequest);
  76. NSString *URLString =
  77. [NSString stringWithFormat:kAPIURLFormat, gAPIHost, kGetProjectConfigEndPoint, kTestAPIKey];
  78. XCTAssertEqualObjects(URLString, [request requestURL].absoluteString);
  79. }
  80. @end