AccountInfoTests.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2019 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 "FIRAuthApiTestsBase.h"
  18. /** The testing email address for testCreateAccountWithEmailAndPassword. */
  19. static NSString *const kOldUserEmail = @"user+user_old_email@example.com";
  20. /** The testing email address for testUpdatingUsersEmail. */
  21. static NSString *const kNewUserEmail = @"user+user_new_email@example.com";
  22. @interface AccountInfoTests : FIRAuthApiTestsBase
  23. @end
  24. @implementation AccountInfoTests
  25. - (void)testUpdatingUsersEmail {
  26. SKIP_IF_ON_MOBILE_HARNESS
  27. FIRAuth *auth = [FIRAuth auth];
  28. if (!auth) {
  29. XCTFail(@"Could not obtain auth object.");
  30. }
  31. __block NSError *apiError;
  32. XCTestExpectation *expectation =
  33. [self expectationWithDescription:@"Created account with email and password."];
  34. [auth createUserWithEmail:kOldUserEmail
  35. password:@"password"
  36. completion:^(FIRAuthDataResult *user, NSError *error) {
  37. if (error.code != FIRAuthErrorCodeEmailAlreadyInUse) {
  38. apiError = error;
  39. }
  40. [expectation fulfill];
  41. }];
  42. [self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
  43. expectation = [self expectationWithDescription:@"Sign in with email and password."];
  44. [auth signInWithEmail:kOldUserEmail
  45. password:@"password"
  46. completion:^(FIRAuthDataResult *_Nullable authResult, NSError *_Nullable error) {
  47. apiError = error;
  48. [expectation fulfill];
  49. }];
  50. [self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
  51. XCTAssertEqualObjects(auth.currentUser.email, kOldUserEmail);
  52. XCTAssertNil(apiError);
  53. expectation = [self expectationWithDescription:@"Update email address."];
  54. [auth.currentUser updateEmail:kNewUserEmail
  55. completion:^(NSError *_Nullable error) {
  56. apiError = error;
  57. [expectation fulfill];
  58. }];
  59. [self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
  60. XCTAssertNil(apiError);
  61. XCTAssertEqualObjects(auth.currentUser.email, kNewUserEmail);
  62. // Clean up the created Firebase user for future runs.
  63. [self deleteCurrentUser];
  64. }
  65. @end