FIRDeleteAccountRequestTests.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "FIRAuthBackend.h"
  18. #import "FIRAuthErrors.h"
  19. #import "FIRDeleteAccountRequest.h"
  20. #import "FIRDeleteAccountResponse.h"
  21. #import "FIRFakeBackendRPCIssuer.h"
  22. /** @var kTestAPIKey
  23. @brief Fake API key used for testing.
  24. */
  25. static NSString *const kTestAPIKey = @"APIKey";
  26. /** @var kLocalID
  27. @brief Fake LocalID used for testing.
  28. */
  29. static NSString *const kLocalID = @"LocalID";
  30. /** @var kLocalIDKey
  31. @brief The name of the "localID" property in the request.
  32. */
  33. static NSString *const kLocalIDKey = @"localId";
  34. /** @var kAccessToken
  35. @brief The name of the "AccessToken" property in the request.
  36. */
  37. static NSString *const kAccessToken = @"AccessToken";
  38. /** @var kExpectedAPIURL
  39. @brief The expected URL for test calls.
  40. */
  41. static NSString *const kExpectedAPIURL =
  42. @"https://www.googleapis.com/identitytoolkit/v3/relyingparty/deleteAccount?key=APIKey";
  43. /** @class FIRDeleteUserRequestTests
  44. @brief Tests for @c FIRDeleteAccountRequest.
  45. */
  46. @interface FIRDeleteAccountRequestTests : XCTestCase
  47. @end
  48. @implementation FIRDeleteAccountRequestTests {
  49. /** @var _RPCIssuer
  50. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  51. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  52. */
  53. FIRFakeBackendRPCIssuer *_RPCIssuer;
  54. }
  55. - (void)setUp {
  56. [super setUp];
  57. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  58. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  59. _RPCIssuer = RPCIssuer;
  60. }
  61. - (void)tearDown {
  62. _RPCIssuer = nil;
  63. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  64. [super tearDown];
  65. }
  66. /** @fn testDeleteAccountRequest
  67. @brief Tests the delete account request.
  68. */
  69. - (void)testDeleteAccountRequest {
  70. FIRAuthRequestConfiguration *requestConfiguration =
  71. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey];
  72. FIRDeleteAccountRequest *request =
  73. [[FIRDeleteAccountRequest alloc] initWitLocalID:kLocalID
  74. accessToken:kAccessToken
  75. requestConfiguration:requestConfiguration];
  76. __block BOOL callbackInvoked;
  77. __block NSError *RPCError;
  78. [FIRAuthBackend deleteAccount:request
  79. callback:^(NSError *_Nullable error) {
  80. callbackInvoked = YES;
  81. RPCError = error;
  82. }];
  83. XCTAssertEqualObjects(_RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
  84. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  85. XCTAssertNotNil(_RPCIssuer.decodedRequest[kLocalIDKey]);
  86. }
  87. @end