|
1 | 1 | // |
2 | | -// PhoneAuthSignIn.swift |
| 2 | +// PhoneAuthTest.swift |
3 | 3 | // SwiftApiTests |
4 | 4 | // |
5 | 5 | // Created by Srushti Vaidya on 12/08/24. |
6 | 6 | // Copyright © 2024 Firebase. All rights reserved. |
7 | 7 | // |
8 | 8 |
|
9 | | -import Foundation |
10 | 9 | import FirebaseAuth |
| 10 | +import Foundation |
11 | 11 | import XCTest |
12 | 12 |
|
13 | 13 | class PhoneAuthTests: TestsBase { |
14 | | - |
15 | 14 | let kPhoneNumber = "+19999999999" |
16 | | - // This test verification code is specified for the given test phone number in the developer console. |
| 15 | + // This test verification code is specified for the given test phone number in the developer |
| 16 | + // console. |
17 | 17 | let kVerificationCode = "777777" |
18 | 18 |
|
19 | 19 | func testSignInWithPhoneNumber() throws { |
20 | | - Auth.auth().settings?.isAppVerificationDisabledForTesting = true //toAdd |
21 | | - let auth = Auth.auth() |
22 | | - let expectation = self.expectation(description: "Sign in with phone number") |
| 20 | + Auth.auth().settings?.isAppVerificationDisabledForTesting = true // toAdd |
| 21 | + let auth = Auth.auth() |
| 22 | + let expectation = self.expectation(description: "Sign in with phone number") |
23 | 23 |
|
24 | | - //PhoneAuthProvider used to initiate the Verification process and obtain a verificationID. |
25 | | - PhoneAuthProvider.provider().verifyPhoneNumber(kPhoneNumber, uiDelegate: nil) { verificationID, error in |
26 | | - if let error{ |
27 | | - XCTAssertNil(error, "Verification error should be nil") |
28 | | - XCTAssertNotNil(verificationID, "Verification ID should not be nil") |
29 | | - } |
| 24 | + // PhoneAuthProvider used to initiate the Verification process and obtain a verificationID. |
| 25 | + PhoneAuthProvider.provider() |
| 26 | + .verifyPhoneNumber(kPhoneNumber, uiDelegate: nil) { verificationID, error in |
| 27 | + if let error { |
| 28 | + XCTAssertNil(error, "Verification error should be nil") |
| 29 | + XCTAssertNotNil(verificationID, "Verification ID should not be nil") |
| 30 | + } |
30 | 31 |
|
31 | | - // Create a credential using the test verification code. |
32 | | - let credential = PhoneAuthProvider.provider().credential(withVerificationID: verificationID ?? "", verificationCode: self.kVerificationCode) |
33 | | - //signs in using the credential and verifies that the user is signed in correctly by checking auth.currentUser. |
34 | | - auth.signIn(with: credential) { authResult, error in |
35 | | - if let error{ |
36 | | - XCTAssertNil(error, "Sign in error should be nil") |
37 | | - XCTAssertNotNil(authResult, "AuthResult should not be nil") |
38 | | - XCTAssertEqual(auth.currentUser?.phoneNumber, self.kPhoneNumber, "Phone number does not match") |
39 | | - } |
40 | | - expectation.fulfill() |
| 32 | + // Create a credential using the test verification code. |
| 33 | + let credential = PhoneAuthProvider.provider().credential( |
| 34 | + withVerificationID: verificationID ?? "", |
| 35 | + verificationCode: self.kVerificationCode |
| 36 | + ) |
| 37 | + // signs in using the credential and verifies that the user is signed in correctly by |
| 38 | + // checking auth.currentUser. |
| 39 | + auth.signIn(with: credential) { authResult, error in |
| 40 | + if let error { |
| 41 | + XCTAssertNil(error, "Sign in error should be nil") |
| 42 | + XCTAssertNotNil(authResult, "AuthResult should not be nil") |
| 43 | + XCTAssertEqual( |
| 44 | + auth.currentUser?.phoneNumber, |
| 45 | + self.kPhoneNumber, |
| 46 | + "Phone number does not match" |
| 47 | + ) |
41 | 48 | } |
| 49 | + expectation.fulfill() |
| 50 | + } |
42 | 51 | } |
43 | 52 |
|
44 | | - waitForExpectations(timeout: TestsBase.kExpectationsTimeout) |
45 | | - //deleteCurrentUser() |
| 53 | + waitForExpectations(timeout: TestsBase.kExpectationsTimeout) |
| 54 | + // deleteCurrentUser() |
46 | 55 | } |
47 | 56 | } |
0 commit comments