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

[auth-swift] Reimplement AuthTestingSupport in Swift #12377

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ import Foundation
private let callbackScheme: String
private let usingClientIDScheme: Bool

private init(auth: Auth) {
init(auth: Auth) {
self.auth = auth
if let clientID = auth.app?.options.clientID {
let reverseClientIDScheme = clientID.components(separatedBy: ".").reversed()
Expand Down
21 changes: 6 additions & 15 deletions FirebaseAuthTestingSupport.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FirebaseAuthTestingSupport'
s.version = '1.0.0'
s.version = '2.0.0'
s.summary = 'Firebase SDKs testing support types and utilities.'

s.description = <<-DESC
Expand All @@ -17,10 +17,10 @@ Pod::Spec.new do |s|
:tag => 'CocoaPods-' + s.version.to_s
}

ios_deployment_target = '11.0'
ios_deployment_target = '13.0'
osx_deployment_target = '10.13'
tvos_deployment_target = '12.0'
watchos_deployment_target = '6.0'
tvos_deployment_target = '13.0'
watchos_deployment_target = '7.0'

s.swift_version = '5.3'

Expand All @@ -36,19 +36,10 @@ Pod::Spec.new do |s|
base_dir = 'FirebaseTestingSupport/Auth/'

s.source_files = [
base_dir + 'Sources/**/*.{m,mm,h}',
base_dir + 'Sources/**/*.swift',
]

s.public_header_files = base_dir + '**/*.h'

s.dependency 'FirebaseAuth', '~> 10.0'

s.pod_target_xcconfig = {
'GCC_C_LANGUAGE_STANDARD' => 'c99',
'OTHER_CFLAGS' => '-fno-autolink',
'HEADER_SEARCH_PATHS' =>
'"${PODS_TARGET_SRCROOT}" '
}
s.dependency 'FirebaseAuth', '~> 10.22'

s.test_spec 'unit' do |unit_tests|
unit_tests.scheme = { :code_coverage => true }
Expand Down
32 changes: 0 additions & 32 deletions FirebaseTestingSupport/Auth/Sources/FIRPhoneAuthProviderFake.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Google LLC
// 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.
Expand All @@ -12,24 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#import <FirebaseAuth/FirebaseAuth.h>

NS_ASSUME_NONNULL_BEGIN

typedef void (^FIRVerifyPhoneNumberHandler)(FIRVerificationResultCallback completion);
@testable import FirebaseAuth
import Foundation

/// A fake object to replace a real `AuthAPNSTokenManager` in tests.
NS_SWIFT_NAME(PhoneAuthProviderFake)
@interface FIRPhoneAuthProviderFake : FIRPhoneAuthProvider

- (instancetype)init;

/// The block to be called each time when `verifyPhoneNumber(_:uiDelegate:completion:)` method is
/// called.
@property(nonatomic, nullable, copy) FIRVerifyPhoneNumberHandler verifyPhoneNumberHandler;

// TODO: Implement other handlers as needed.

@end

NS_ASSUME_NONNULL_END
public class PhoneAuthProviderFake: PhoneAuthProvider {
override init(auth: Auth) {
super.init(auth: auth)
}

var verifyPhoneNumberHandler: (((String?, Error?) -> Void) -> Void)?

override public func verifyPhoneNumber(_ phoneNumber: String,
uiDelegate: AuthUIDelegate? = nil,
completion: ((_: String?, _: Error?) -> Void)?) {
if let verifyPhoneNumberHandler,
let completion {
verifyPhoneNumberHandler(completion)
}
}
}
30 changes: 23 additions & 7 deletions FirebaseTestingSupport/Auth/Tests/PhoneAuthProviderFakeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,47 @@
// See the License for the specific language governing permissions and
// limitations under the License.

@testable import FirebaseAuth
@testable import FirebaseAuthTestingSupport
import FirebaseCore
import Foundation
import XCTest

class PhoneAuthProviderFakeTests: XCTestCase {
var auth: Auth!
static var testNum = 0
override func setUp() {
super.setUp()
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
options.apiKey = "TEST_API_KEY"
options.projectID = "myProjectID"
PhoneAuthProviderFakeTests.testNum = PhoneAuthProviderFakeTests.testNum + 1
let name = "test-name\(PhoneAuthProviderFakeTests.testNum)"
FirebaseApp.configure(name: name, options: options)
auth = Auth(
app: FirebaseApp.app(name: name)!
)
}

func testPhoneAuthProviderFakeConstructor() throws {
let fakePhoneAuthProvider = PhoneAuthProviderFake()
let fakePhoneAuthProvider = PhoneAuthProviderFake(auth: auth)
XCTAssertNotNil(fakePhoneAuthProvider)
XCTAssertTrue(fakePhoneAuthProvider.isKind(of: PhoneAuthProvider.self))
}

func testVerifyPhoneNumberHandler() {
let fakePhoneAuthProvider = PhoneAuthProviderFake()
let fakePhoneAuthProvider = PhoneAuthProviderFake(auth: auth)

let handlerExpectation = expectation(description: "Handler called")
fakePhoneAuthProvider.verifyPhoneNumberHandler = { completion in
handlerExpectation.fulfill()

completion(nil, nil)
completion("test-id", nil)
}

let completionExpectation = expectation(description: "Completion called")
fakePhoneAuthProvider.verifyPhoneNumber("", uiDelegate: nil) { verficationID, error in
fakePhoneAuthProvider.verifyPhoneNumber("", uiDelegate: nil) { verificationID, error in
completionExpectation.fulfill()
XCTAssertNil(verficationID)
XCTAssertEqual(verificationID, "test-id")
XCTAssertNil(error)
}

Expand Down
Loading