Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions FirebaseAuth/Tests/SampleSwift/SwiftApiTests/PhoneAuthTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2019 Google
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright 2019 Google
* Copyright 2024 Google

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// PhoneAuthTest.swift
// SwiftApiTests

import FirebaseAuth
import Foundation
import XCTest

class PhoneAuthTests: TestsBase {
let kPhoneNumber = "+19999999999"
// This test verification code is specified for the given test phone number in the developer
// console.
let kVerificationCode = "777777"

func testSignInWithPhoneNumber() throws {
Auth.auth().settings?.isAppVerificationDisabledForTesting = true // toAdd
let auth = Auth.auth()
let expectation = self.expectation(description: "Sign in with phone number")

// PhoneAuthProvider used to initiate the Verification process and obtain a verificationID.
PhoneAuthProvider.provider()
.verifyPhoneNumber(kPhoneNumber, uiDelegate: nil) { verificationID, error in
if let error {
XCTAssertNil(error, "Verification error should be nil")
XCTAssertNotNil(verificationID, "Verification ID should not be nil")
}

// Create a credential using the test verification code.
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationID ?? "",
verificationCode: self.kVerificationCode
)
// signs in using the credential and verifies that the user is signed in correctly by
// checking auth.currentUser.
auth.signIn(with: credential) { authResult, error in
if let error {
XCTAssertNil(error, "Sign in error should be nil")
XCTAssertNotNil(authResult, "AuthResult should not be nil")
XCTAssertEqual(
auth.currentUser?.phoneNumber,
self.kPhoneNumber,
"Phone number does not match"
)
}
expectation.fulfill()
}
}

waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
// deleteCurrentUser()
}
}