Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Integration Test for Phone Number Authentication in Firebase #13538

Open
wants to merge 21 commits into
base: rce-phone-tests
Choose a base branch
from
Open
Changes from 8 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 2024 Google LLC
*
* 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
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved

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"
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved

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
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
// 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()
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading