AccountInfoTests.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 FirebaseAuth;
  18. #import "FIRAuthApiTestsBase.h"
  19. /** The testing email address for testCreateAccountWithEmailAndPassword. */
  20. static NSString *const kOldUserEmail = @"user+user_old_email@example.com";
  21. /** The testing email address for testUpdatingUsersEmail. */
  22. static NSString *const kNewUserEmail = @"user+user_new_email@example.com";
  23. @interface AccountInfoTests : FIRAuthApiTestsBase
  24. @end
  25. @implementation AccountInfoTests
  26. - (void)setUp {
  27. XCTestExpectation *expectation = [self expectationWithDescription:@"setup old email expectation"];
  28. FIRAuth *auth = [FIRAuth auth];
  29. [auth createUserWithEmail:kOldUserEmail
  30. password:@"password"
  31. completion:^(FIRAuthDataResult *user, NSError *error) {
  32. // Succeed whether or not the user already exists.
  33. [expectation fulfill];
  34. }];
  35. [self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
  36. }
  37. - (void)testUpdatingUsersEmailAlreadyInUse {
  38. SKIP_IF_ON_MOBILE_HARNESS
  39. FIRAuth *auth = [FIRAuth auth];
  40. if (!auth) {
  41. XCTFail(@"Could not obtain auth object.");
  42. }
  43. XCTestExpectation *expectation =
  44. [self expectationWithDescription:@"Created account with email and password."];
  45. [auth createUserWithEmail:kOldUserEmail
  46. password:@"password"
  47. completion:^(FIRAuthDataResult *user, NSError *error) {
  48. XCTAssertEqual(error.code, FIRAuthErrorCodeEmailAlreadyInUse);
  49. [expectation fulfill];
  50. }];
  51. [self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
  52. }
  53. @end