TestsBase.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2020 Google LLC
  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 Foundation
  17. import FirebaseAuth
  18. import XCTest
  19. class TestsBase : XCTestCase {
  20. static let kExpectationsTimeout = 10.0
  21. func signInAnonymously() {
  22. let auth = Auth.auth()
  23. let expectation = self.expectation(description: "Anonymous sign-in finished.")
  24. auth.signInAnonymously() { (result, error) in
  25. if let error = error {
  26. print("Anonymous sign in error: \(error)")
  27. }
  28. expectation.fulfill()
  29. }
  30. waitForExpectations(timeout:TestsBase.kExpectationsTimeout)
  31. }
  32. func signOut() {
  33. let auth = Auth.auth()
  34. do {
  35. try auth.signOut()
  36. } catch (let error) {
  37. print("Error signing out: \(error)")
  38. }
  39. }
  40. func deleteCurrentUser() {
  41. let auth = Auth.auth()
  42. let expectation = self.expectation(description: "Delete current user finished.")
  43. auth.currentUser?.delete() { (error) in
  44. if let error = error {
  45. print("Anonymous sign in error: \(error)")
  46. }
  47. expectation.fulfill()
  48. }
  49. waitForExpectations(timeout:TestsBase.kExpectationsTimeout)
  50. }
  51. }