Prechádzať zdrojové kódy

[Auth] Add background modes capability to plist (#13548)

Nick Cooke 1 rok pred
rodič
commit
e50bb48ea2

+ 1 - 1
.github/workflows/auth.yml

@@ -78,7 +78,7 @@ jobs:
         scripts/decrypt_gha_secret.sh scripts/gha-encrypted/AuthCredentials.h.gpg \
           FirebaseAuth/Tests/SampleSwift/ObjCApiTests/AuthCredentials.h "$plist_secret"
         scripts/decrypt_gha_secret.sh scripts/gha-encrypted/AuthSample/SwiftApplication.plist.gpg \
-          FirebaseAuth/Tests/SampleSwift/SwiftApplication.plist "$plist_secret"
+          FirebaseAuth/Tests/SampleSwift/AuthenticationExample/SwiftApplication.plist "$plist_secret"
         scripts/decrypt_gha_secret.sh scripts/gha-encrypted/AuthSample/AuthCredentials.h.gpg \
           FirebaseAuth/Tests/SampleSwift/AuthCredentials.h "$plist_secret"
         scripts/decrypt_gha_secret.sh scripts/gha-encrypted/AuthSample/GoogleService-Info.plist.gpg \

+ 1 - 1
.gitignore

@@ -1,4 +1,4 @@
-FirebaseAuth/Tests/SampleSwift/SwiftApplication.plist
+FirebaseAuth/Tests/SampleSwift/AuthenticationExample/SwiftApplication.plist
 FirebaseAuth/Tests/SampleSwift/ObjCApiTests/AuthCredentials.h
 FirebaseAuth/Tests/SampleSwift/GoogleService-Info_multi.plist
 FirebaseAuth/Tests/SampleSwift/GoogleService-Info.plist

+ 12 - 3
FirebaseAuth/Tests/SampleSwift/SwiftApiTests/EmailPasswordTests.swift

@@ -25,8 +25,12 @@ class EmailPasswordTests: TestsBase {
   /// ** The testing email address for testSignInExistingUserWithEmailAndPassword. */
   let kExistingEmailToSignIn = "user+email_existing_user@example.com"
 
-  func testCreateAccountWithEmailAndPassword() {
+  func testCreateAccountWithEmailAndPassword() async throws {
     let auth = Auth.auth()
+    // Ensure the account that will be created does not already exist.
+    let result = try? await auth.signIn(withEmail: kNewEmailToCreateUser, password: "password")
+    try? await result?.user.delete()
+
     let expectation = self.expectation(description: "Created account with email and password.")
     auth.createUser(withEmail: kNewEmailToCreateUser, password: "password") { result, error in
       if let error {
@@ -34,13 +38,18 @@ class EmailPasswordTests: TestsBase {
       }
       expectation.fulfill()
     }
-    waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
+    await fulfillment(of: [expectation], timeout: TestsBase.kExpectationsTimeout)
+
     XCTAssertEqual(auth.currentUser?.email, kNewEmailToCreateUser, "Expected email doesn't match")
-    deleteCurrentUser()
+    try? await deleteCurrentUserAsync()
   }
 
   func testCreateAccountWithEmailAndPasswordAsync() async throws {
     let auth = Auth.auth()
+    // Ensure the account that will be created does not already exist.
+    let result = try? await auth.signIn(withEmail: kNewEmailToCreateUser, password: "password")
+    try? await result?.user.delete()
+
     try await auth.createUser(withEmail: kNewEmailToCreateUser, password: "password")
     XCTAssertEqual(auth.currentUser?.email, kNewEmailToCreateUser, "Expected email doesn't match")
     try await deleteCurrentUserAsync()

+ 2 - 2
FirebaseAuth/Tests/SampleSwift/SwiftApiTests/TestsBase.swift

@@ -54,9 +54,9 @@ class TestsBase: XCTestCase {
   }
 
   func deleteCurrentUser() {
-    let auth = Auth.auth()
+    guard let currentUser = Auth.auth().currentUser else { return }
     let expectation = self.expectation(description: "Delete current user finished.")
-    auth.currentUser?.delete { error in
+    currentUser.delete { error in
       if let error {
         print("Anonymous sign in error: \(error)")
       }

BIN
scripts/gha-encrypted/AuthSample/SwiftApplication.plist.gpg