PhoneAuthProviderFakeTests.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. @testable import FirebaseAuth
  15. @testable import FirebaseAuthTestingSupport
  16. import FirebaseCore
  17. import Foundation
  18. import XCTest
  19. class PhoneAuthProviderFakeTests: XCTestCase {
  20. var auth: Auth!
  21. static var testNum = 0
  22. override func setUp() {
  23. super.setUp()
  24. let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
  25. gcmSenderID: "00000000000000000-00000000000-000000000")
  26. options.apiKey = "TEST_API_KEY"
  27. options.projectID = "myProjectID"
  28. PhoneAuthProviderFakeTests.testNum = PhoneAuthProviderFakeTests.testNum + 1
  29. let name = "test-name\(PhoneAuthProviderFakeTests.testNum)"
  30. FirebaseApp.configure(name: name, options: options)
  31. auth = Auth(
  32. app: FirebaseApp.app(name: name)!
  33. )
  34. }
  35. func testPhoneAuthProviderFakeConstructor() throws {
  36. let fakePhoneAuthProvider = PhoneAuthProviderFake(auth: auth)
  37. XCTAssertNotNil(fakePhoneAuthProvider)
  38. }
  39. func testVerifyPhoneNumberHandler() {
  40. let fakePhoneAuthProvider = PhoneAuthProviderFake(auth: auth)
  41. let handlerExpectation = expectation(description: "Handler called")
  42. fakePhoneAuthProvider.verifyPhoneNumberHandler = { completion in
  43. handlerExpectation.fulfill()
  44. completion("test-id", nil)
  45. }
  46. let completionExpectation = expectation(description: "Completion called")
  47. fakePhoneAuthProvider.verifyPhoneNumber("", uiDelegate: nil) { verificationID, error in
  48. completionExpectation.fulfill()
  49. XCTAssertEqual(verificationID, "test-id")
  50. XCTAssertNil(error)
  51. }
  52. wait(for: [handlerExpectation, completionExpectation], timeout: 0.5)
  53. }
  54. }