FIRGetProjectConfigRequestTests.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 kAPIURLFormat
  30. @brief URL format for server API calls.
  31. */
  32. static NSString *const kAPIURLFormat = @"https://%@/identitytoolkit/v3/relyingparty/%@?key=%@";
  33. /** @var gAPIHost
  34. @brief Host for server API calls.
  35. */
  36. static NSString *gAPIHost = @"www.googleapis.com";
  37. @interface FIRGetProjectConfigRequestTests : XCTestCase
  38. @end
  39. @implementation FIRGetProjectConfigRequestTests {
  40. /** @var _RPCIssuer
  41. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  42. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  43. */
  44. FIRFakeBackendRPCIssuer *_RPCIssuer;
  45. }
  46. - (void)setUp {
  47. [super setUp];
  48. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  49. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  50. _RPCIssuer = RPCIssuer;
  51. }
  52. - (void)tearDown {
  53. _RPCIssuer = nil;
  54. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  55. [super tearDown];
  56. }
  57. /** @fn testGetProjectConfigRequest
  58. @brief Tests get project config request.
  59. */
  60. - (void)testGetProjectConfigRequest {
  61. FIRAuthRequestConfiguration *requestConfiguration =
  62. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey];
  63. FIRGetProjectConfigRequest *request =
  64. [[FIRGetProjectConfigRequest alloc] initWithRequestConfiguration:requestConfiguration];
  65. [FIRAuthBackend
  66. getProjectConfig:request
  67. callback:^(FIRGetProjectConfigResponse *_Nullable response, NSError *_Nullable error){
  68. }];
  69. XCTAssertFalse([request containsPostBody]);
  70. // Confirm that the quest has no decoded body as it is get request.
  71. XCTAssertNil(_RPCIssuer.decodedRequest);
  72. NSString *URLString =
  73. [NSString stringWithFormat:kAPIURLFormat, gAPIHost, kGetProjectConfigEndPoint, kTestAPIKey];
  74. XCTAssertEqualObjects(URLString, [request requestURL].absoluteString);
  75. }
  76. @end