Skip to content

Commit

Permalink
Change ApplicationLaunching method name
Browse files Browse the repository at this point in the history
  • Loading branch information
mohssenfathi committed Sep 12, 2024
1 parent 6dec2b6 commit b209c47
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,9 @@ public final class AuthorizationCodeAuthProvider: AuthProviding {
}

DispatchQueue.main.async {
self.applicationLauncher.open(
self.applicationLauncher.launch(
url,
options: [:],
completionHandler: { opened in
completion: { opened in
completion?(opened)
}
)
Expand Down
11 changes: 9 additions & 2 deletions Sources/UberCore/ApplicationLauncher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ import UIKit
/// @mockable
public protocol ApplicationLaunching {

func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler: ((Bool) -> Void)?)
func launch(_ url: URL, completion: ((Bool) -> ())?)
}

extension UIApplication: ApplicationLaunching {}
extension UIApplication: ApplicationLaunching {

public func launch(_ url: URL, completion: ((Bool) -> ())?) {
open(url, options: [:]) {
completion?($0)
}
}
}
12 changes: 6 additions & 6 deletions examples/UberSDK/UberSDKTests/Mocks/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public class ApplicationLaunchingMock: ApplicationLaunching {
public init() { }


public private(set) var openCallCount = 0
public var openHandler: ((URL, [UIApplication.OpenExternalURLOptionsKey: Any], ((Bool) -> Void)?) -> ())?
public func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler: ((Bool) -> Void)?) {
openCallCount += 1
if let openHandler = openHandler {
openHandler(url, options, completionHandler)
public private(set) var launchCallCount = 0
public var launchHandler: ((URL, ((Bool) -> ())?) -> ())?
public func launch(_ url: URL, completion: ((Bool) -> ())?) {
launchCallCount += 1
if let launchHandler = launchHandler {
launchHandler(url, completion)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
}

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { _, _, completion in
applicationLauncher.launchHandler = { _, completion in
completion?(true)
}

Expand Down Expand Up @@ -114,7 +114,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
}

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { _, _, completion in
applicationLauncher.launchHandler = { _, completion in
completion?(true)
}

Expand Down Expand Up @@ -156,7 +156,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
let promptString = prompt.stringValue.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { url, _, completion in
applicationLauncher.launchHandler = { url, completion in
XCTAssertTrue(url.query()!.contains("prompt=\(promptString)"))
expectation.fulfill()
completion?(true)
Expand Down Expand Up @@ -190,7 +190,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
let promptString = prompt.stringValue.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { url, _, completion in
applicationLauncher.launchHandler = { url, completion in
XCTAssertTrue(url.query()!.contains("prompt=\(promptString)"))
expectation.fulfill()
completion?(true)
Expand Down Expand Up @@ -334,7 +334,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
let expectation = XCTestExpectation()

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { _, _, completion in
applicationLauncher.launchHandler = { _, completion in
expectation.fulfill()
completion?(true)
}
Expand All @@ -360,7 +360,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
func test_executeNativeLogin_noDestinations_triggersInAppLogin() {

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { _, _, _ in }
applicationLauncher.launchHandler = { _, _ in }

configurationProvider.isInstalledHandler = { _, _ in
false
Expand All @@ -385,7 +385,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
func test_executeNativeLogin_noOpens_triggersInAppLogin() {

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { _, _, completion in
applicationLauncher.launchHandler = { _, completion in
completion?(false)
}

Expand Down Expand Up @@ -423,7 +423,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
func test_executeNativeLogin_noTokenExchange_doesNotIncludeCodeChallenge() {

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { url, _, completion in
applicationLauncher.launchHandler = { url, completion in
XCTAssertFalse(url.absoluteString.contains("code_challenge"))
XCTAssertFalse(url.absoluteString.contains("code_challenge_method"))
completion?(false)
Expand All @@ -448,7 +448,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
applicationLauncher: applicationLauncher
)

XCTAssertEqual(applicationLauncher.openCallCount, 0)
XCTAssertEqual(applicationLauncher.launchCallCount, 0)

provider.execute(
authDestination: .native(appPriority: [.eats]),
Expand All @@ -458,7 +458,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {

wait(for: [expectation], timeout: 0.2)

XCTAssertEqual(applicationLauncher.openCallCount, 1)
XCTAssertEqual(applicationLauncher.launchCallCount, 1)
}

func test_handleResponse_true_callsResponseParser() {
Expand Down Expand Up @@ -588,7 +588,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
}

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { _, _, completion in
applicationLauncher.launchHandler = { _, completion in
completion?(true)
}

Expand Down Expand Up @@ -626,7 +626,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
}

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { _, _, completion in
applicationLauncher.launchHandler = { _, completion in
completion?(true)
}

Expand Down Expand Up @@ -671,7 +671,7 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
}

let applicationLauncher = ApplicationLaunchingMock()
applicationLauncher.openHandler = { _, _, completion in
applicationLauncher.launchHandler = { _, completion in
completion?(true)
}

Expand Down

0 comments on commit b209c47

Please sign in to comment.