Skip to content

Commit 9f39fdc

Browse files
authored
Style Auth Integration Tests (#9229)
1 parent 22d6a45 commit 9f39fdc

File tree

9 files changed

+323
-319
lines changed

9 files changed

+323
-319
lines changed

FirebaseAuth/Tests/Sample/ApiTests/FIRAuthApiTestsBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
#import <XCTest/XCTest.h>
1818

19+
#import <FirebaseAuth/FirebaseAuth.h>
1920
#import <FirebaseCore/FIRApp.h>
2021
#import "AuthCredentials.h"
21-
#import <FirebaseAuth/FirebaseAuth.h>
2222

2323
#ifdef NO_NETWORK
2424
#import "ITUIOSTestUtil.h"

FirebaseAuth/Tests/Sample/ApiTests/PhoneMultiFactorTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PhoneMultiFactorTests: FIRAuthApiTestsBase {
5959
"Phone multi factor enroll failed. Error: \(error!.localizedDescription)")
6060
XCTAssertEqual(Auth.auth().currentUser?.multiFactor.enrolledFactors.first?
6161
.displayName,
62-
kPhoneSecondFactorDisplayName)
62+
kPhoneSecondFactorDisplayName)
6363
enrollExpectation.fulfill()
6464

6565
// Unenroll
@@ -70,7 +70,7 @@ class PhoneMultiFactorTests: FIRAuthApiTestsBase {
7070
"Phone multi factor unenroll failed. Error: \(error!.localizedDescription)")
7171
XCTAssertEqual(Auth.auth().currentUser?.multiFactor.enrolledFactors.count, 0)
7272
unenrollExpectation.fulfill()
73-
})
73+
})
7474
}
7575
}
7676
}
Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
* Copyright 2020 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
import XCTest
1818
import FirebaseAuth
@@ -26,78 +26,78 @@ class AccountInfoTests: TestsBase {
2626

2727
override func setUp() {
2828
let auth = Auth.auth()
29-
let expectation1 = self.expectation(description: "Created account with email and password.")
29+
let expectation1 = expectation(description: "Created account with email and password.")
3030
auth.createUser(withEmail: kOldUserEmail, password: "password") { user, error in
3131
// Succeed whether or not the user already exists.
3232
expectation1.fulfill()
3333
}
34-
waitForExpectations(timeout:TestsBase.kExpectationsTimeout)
34+
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
3535
}
3636

3737
override func tearDown() {
3838
// Clean up the created Firebase user for future runs.
39-
self.deleteCurrentUser()
39+
deleteCurrentUser()
4040
}
4141

4242
func testUpdatingUsersEmail() {
4343
let auth = Auth.auth()
44-
let expectation1 = self.expectation(description: "Created account with email and password.")
44+
let expectation1 = expectation(description: "Created account with email and password.")
4545
auth.createUser(withEmail: kOldUserEmail, password: "password") { user, error in
46-
if let error = error {
46+
if let error = error {
4747
XCTAssertEqual((error as NSError).code,
48-
AuthErrorCode.emailAlreadyInUse.rawValue,
49-
"Created a user despite it already exiting.")
48+
AuthErrorCode.emailAlreadyInUse.rawValue,
49+
"Created a user despite it already exiting.")
5050
} else {
5151
XCTFail("Did not get error for recreating a user")
5252
}
5353
expectation1.fulfill()
5454
}
55-
waitForExpectations(timeout:TestsBase.kExpectationsTimeout)
55+
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
5656

57-
let expectation2 = self.expectation(description: "Sign in with email and password.")
57+
let expectation2 = expectation(description: "Sign in with email and password.")
5858
auth.signIn(withEmail: kOldUserEmail, password: "password") { user, error in
5959
XCTAssertNil(error)
6060
XCTAssertEqual(auth.currentUser?.email,
6161
self.kOldUserEmail,
6262
"Signed user does not match request.")
6363
expectation2.fulfill()
6464
}
65-
waitForExpectations(timeout:TestsBase.kExpectationsTimeout)
65+
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
6666

67-
let expectation3 = self.expectation(description: "Update email address.")
67+
let expectation3 = expectation(description: "Update email address.")
6868
auth.currentUser?.updateEmail(to: kNewUserEmail) { error in
6969
XCTAssertNil(error)
7070
XCTAssertEqual(auth.currentUser?.email,
7171
self.kNewUserEmail,
7272
"Signed user does not match change.")
7373
expectation3.fulfill()
7474
}
75-
waitForExpectations(timeout:TestsBase.kExpectationsTimeout)
75+
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
7676
}
7777

78-
#if compiler(>=5.5) && canImport(_Concurrency)
79-
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
80-
func testUpdatingUsersEmailAsync() async throws {
81-
let auth = Auth.auth()
82-
do {
83-
let _ = try await auth.createUser(withEmail: kOldUserEmail, password: "password")
84-
XCTFail("Did not get error for recreating a user")
85-
} catch {
78+
#if compiler(>=5.5) && canImport(_Concurrency)
79+
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
80+
func testUpdatingUsersEmailAsync() async throws {
81+
let auth = Auth.auth()
82+
do {
83+
_ = try await auth.createUser(withEmail: kOldUserEmail, password: "password")
84+
XCTFail("Did not get error for recreating a user")
85+
} catch {
8686
XCTAssertEqual((error as NSError).code,
87-
AuthErrorCode.emailAlreadyInUse.rawValue,
88-
"Created a user despite it already exiting.")
89-
}
87+
AuthErrorCode.emailAlreadyInUse.rawValue,
88+
"Created a user despite it already exiting.")
89+
}
9090

91-
let user = try await auth.signIn(withEmail: kOldUserEmail, password: "password")
92-
XCTAssertEqual(user.user.email, kOldUserEmail)
93-
XCTAssertEqual(auth.currentUser?.email,
94-
self.kOldUserEmail,
95-
"Signed user does not match request.")
91+
let user = try await auth.signIn(withEmail: kOldUserEmail, password: "password")
92+
XCTAssertEqual(user.user.email, kOldUserEmail)
93+
XCTAssertEqual(auth.currentUser?.email,
94+
kOldUserEmail,
95+
"Signed user does not match request.")
9696

97-
try await auth.currentUser?.updateEmail(to: kNewUserEmail)
98-
XCTAssertEqual(auth.currentUser?.email,
99-
self.kNewUserEmail,
100-
"Signed user does not match change.")
101-
}
97+
try await auth.currentUser?.updateEmail(to: kNewUserEmail)
98+
XCTAssertEqual(auth.currentUser?.email,
99+
kNewUserEmail,
100+
"Signed user does not match change.")
101+
}
102102
#endif
103103
}
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
/*
2-
* Copyright 2020 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
import Foundation
1818
import FirebaseAuth
1919
import XCTest
2020

2121
class AnonymousTests: TestsBase {
2222
func testUpdatingUsersEmail() {
23-
self.signInAnonymously()
23+
signInAnonymously()
2424
if let isAnonymous = Auth.auth().currentUser?.isAnonymous {
2525
XCTAssertTrue(isAnonymous)
2626
} else {
2727
XCTFail("Missing currentUser after anonymous sign in")
2828
}
29-
self.deleteCurrentUser()
29+
deleteCurrentUser()
3030
}
3131

32-
#if compiler(>=5.5) && canImport(_Concurrency)
33-
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
34-
func testUpdatingUsersEmailAsync() async throws {
35-
try await self.signInAnonymouslyAsync()
36-
if let isAnonymous = Auth.auth().currentUser?.isAnonymous {
37-
XCTAssertTrue(isAnonymous)
38-
} else {
39-
XCTFail("Missing currentUser after anonymous sign in")
32+
#if compiler(>=5.5) && canImport(_Concurrency)
33+
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
34+
func testUpdatingUsersEmailAsync() async throws {
35+
try await signInAnonymouslyAsync()
36+
if let isAnonymous = Auth.auth().currentUser?.isAnonymous {
37+
XCTAssertTrue(isAnonymous)
38+
} else {
39+
XCTFail("Missing currentUser after anonymous sign in")
40+
}
41+
try await deleteCurrentUserAsync()
4042
}
41-
try await self.deleteCurrentUserAsync()
42-
}
4343
#endif
4444
}
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
11
/*
2-
* Copyright 2020 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
import Foundation
1818
import FirebaseAuth
1919
import XCTest
2020

2121
class EmailPasswordTests: TestsBase {
22-
23-
///** The testing email address for testCreateAccountWithEmailAndPassword. */
22+
/// ** The testing email address for testCreateAccountWithEmailAndPassword. */
2423
let kNewEmailToCreateUser = "[email protected]"
2524

26-
///** The testing email address for testSignInExistingUserWithEmailAndPassword. */
25+
/// ** The testing email address for testSignInExistingUserWithEmailAndPassword. */
2726
let kExistingEmailToSignIn = "[email protected]"
2827

2928
func testCreateAccountWithEmailAndPassword() {
3029
let auth = Auth.auth()
3130
let expectation = self.expectation(description: "Created account with email and password.")
32-
auth.createUser(withEmail: kNewEmailToCreateUser, password: "password") { (result, error) in
31+
auth.createUser(withEmail: kNewEmailToCreateUser, password: "password") { result, error in
3332
if let error = error {
3433
print("createUserWithEmail has error: \(error)")
3534
}
3635
expectation.fulfill()
3736
}
38-
waitForExpectations(timeout:TestsBase.kExpectationsTimeout)
37+
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
3938
XCTAssertEqual(auth.currentUser?.email, kNewEmailToCreateUser, "Expected email doesn't match")
40-
self.deleteCurrentUser()
39+
deleteCurrentUser()
4140
}
4241

43-
#if compiler(>=5.5) && canImport(_Concurrency)
44-
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
45-
func testCreateAccountWithEmailAndPasswordAsync() async throws {
46-
let auth = Auth.auth()
47-
try await auth.createUser(withEmail: kNewEmailToCreateUser, password: "password")
48-
XCTAssertEqual(auth.currentUser?.email, kNewEmailToCreateUser, "Expected email doesn't match")
49-
try await self.deleteCurrentUserAsync()
50-
}
42+
#if compiler(>=5.5) && canImport(_Concurrency)
43+
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
44+
func testCreateAccountWithEmailAndPasswordAsync() async throws {
45+
let auth = Auth.auth()
46+
try await auth.createUser(withEmail: kNewEmailToCreateUser, password: "password")
47+
XCTAssertEqual(auth.currentUser?.email, kNewEmailToCreateUser, "Expected email doesn't match")
48+
try await deleteCurrentUserAsync()
49+
}
5150
#endif
5251

5352
func testSignInExistingUserWithEmailAndPassword() {
5453
let auth = Auth.auth()
55-
let expectation = self.expectation(description: "Signed in existing account with email and password.")
54+
let expectation = self
55+
.expectation(description: "Signed in existing account with email and password.")
5656
auth.signIn(withEmail: kExistingEmailToSignIn, password: "password") { user, error in
5757
XCTAssertNil(error)
5858
XCTAssertEqual(auth.currentUser?.email,
5959
self.kExistingEmailToSignIn,
6060
"Signed user does not match request.")
6161
expectation.fulfill()
6262
}
63-
waitForExpectations(timeout:TestsBase.kExpectationsTimeout)
63+
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
6464
}
6565

66-
#if compiler(>=5.5) && canImport(_Concurrency)
67-
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
68-
func testSignInExistingUserWithEmailAndPasswordAsync() async throws {
69-
let auth = Auth.auth()
70-
try await auth.signIn(withEmail: kExistingEmailToSignIn, password: "password")
71-
XCTAssertEqual(auth.currentUser?.email,
72-
self.kExistingEmailToSignIn,
73-
"Signed user does not match request.")
74-
}
66+
#if compiler(>=5.5) && canImport(_Concurrency)
67+
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
68+
func testSignInExistingUserWithEmailAndPasswordAsync() async throws {
69+
let auth = Auth.auth()
70+
try await auth.signIn(withEmail: kExistingEmailToSignIn, password: "password")
71+
XCTAssertEqual(auth.currentUser?.email,
72+
kExistingEmailToSignIn,
73+
"Signed user does not match request.")
74+
}
7575
#endif
7676
}

0 commit comments

Comments
 (0)