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

Adds a new public protocol to back UberAuth static methods #326

Merged
merged 1 commit into from
Oct 4, 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
30 changes: 29 additions & 1 deletion Sources/UberAuth/UberAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ import Foundation

public typealias AuthCompletion = (Result<Client, UberAuthError>) -> ()

/// @mockable
public protocol UberAuthInterface {

/// Executes a single login session using the provided context
///
/// - Parameters:
/// - context: An `AuthContext` instance providing all information needed to execute authentication
/// - completion: A closure to be called upon completion
static func login(context: AuthContext, completion: @escaping AuthCompletion)


/// Clears any saved auth information from the keychain
/// If `currentAuthContext` exists, logs out using the stored auth context
/// Otherwise, attempts to delete the saved auth token directly using the internal TokenManager
static func logout()

/// Attempts to extract auth information from the provided URL.
/// This method should be called from the implemeting application's openURL function.
///
/// - Parameter url: The URL that was passed into the implementing app
/// - Returns: A boolean indicating if the URL was handled or not
static func handle(_ url: URL) -> Bool
}


///
/// An internal protocol that translates the class -> instance methods for UberAuth
///
/// @mockable
protocol AuthManaging {

Expand All @@ -40,7 +68,7 @@ protocol AuthManaging {
}

/// Public interface for the uber-auth-ios library
public final class UberAuth: AuthManaging {
public final class UberAuth: UberAuthInterface, AuthManaging {

// MARK: Public

Expand Down
35 changes: 35 additions & 0 deletions examples/UberSDK/UberSDKTests/Mocks/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,41 @@ public class AuthProvidingMock: AuthProviding {
public var isLoggedIn: Bool = false { didSet { isLoggedInSetCallCount += 1 } }
}

public class UberAuthInterfaceMock: UberAuthInterface {
public init() { }


public static private(set) var loginCallCount = 0
public static var loginHandler: ((AuthContext, @escaping AuthCompletion) -> ())?
public static func login(context: AuthContext, completion: @escaping AuthCompletion) {
loginCallCount += 1
if let loginHandler = loginHandler {
loginHandler(context, completion)
}

}

public static private(set) var logoutCallCount = 0
public static var logoutHandler: (() -> ())?
public static func logout() {
logoutCallCount += 1
if let logoutHandler = logoutHandler {
logoutHandler()
}

}

public static private(set) var handleCallCount = 0
public static var handleHandler: ((URL) -> (Bool))?
public static func handle(_ url: URL) -> Bool {
handleCallCount += 1
if let handleHandler = handleHandler {
return handleHandler(url)
}
return false
}
}

class AuthManagingMock: AuthManaging {
init() { }
init(isLoggedIn: Bool = false) {
Expand Down
Loading