AccountInfoTests.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 = @"iosgcip+user_old_email@gmail.com";
  20. /** The testing email address for testUpdatingUsersEmail. */
  21. static NSString *const kNewUserEmail = @"iosgcip+user_new_email@gmail.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. apiError = error;
  38. [expectation fulfill];
  39. }];
  40. [self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
  41. expectation = [self expectationWithDescription:@"Created account with email and password."];
  42. XCTAssertEqualObjects(auth.currentUser.email, kOldUserEmail);
  43. XCTAssertNil(apiError);
  44. [auth.currentUser updateEmail:kNewUserEmail
  45. completion:^(NSError *_Nullable error) {
  46. apiError = error;
  47. [expectation fulfill];
  48. }];
  49. [self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
  50. XCTAssertNil(apiError);
  51. XCTAssertEqualObjects(auth.currentUser.email, kNewUserEmail);
  52. // Clean up the created Firebase user for future runs.
  53. [self deleteCurrentUser];
  54. }
  55. @end