Skip to content

Commit

Permalink
update logic; update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxdesmarais committed Aug 5, 2024
1 parent 7d21b2c commit fbd98a8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Sources/BraintreePayPal/BTPayPalVaultRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import BraintreeCore
/// - Warning: This property is currently in beta and may change or be removed in future releases.
var enablePayPalAppSwitch: Bool = false

/// exposed for mocking not installed tests
/// exposed for mocking in tests
var application: URLOpener = UIApplication.shared

// MARK: - Initializers
Expand All @@ -37,7 +37,7 @@ import BraintreeCore
offerCredit: Bool = false
) {
self.init(offerCredit: offerCredit, userAuthenticationEmail: userAuthenticationEmail)
self.enablePayPalAppSwitch = !application.isPayPalAppInstalled() ? false : enablePayPalAppSwitch
self.enablePayPalAppSwitch = enablePayPalAppSwitch
}

/// Initializes a PayPal Vault request
Expand All @@ -56,7 +56,7 @@ import BraintreeCore
baseParameters["payer_email"] = userAuthenticationEmail
}

if enablePayPalAppSwitch, let universalLink {
if enablePayPalAppSwitch, application.isPayPalAppInstalled(), let universalLink {
let appSwitchParameters: [String: Any] = [
"launch_paypal_app": enablePayPalAppSwitch,
"os_version": UIDevice.current.systemVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class FPTIBatchData_Tests: XCTestCase {
eventName: "fake-event-1",
isConfigFromCache: false,
isVaultRequest: false,
linkType: .universal,
linkType: LinkType.universal.rawValue,
payPalContextID: "fake-order-id",
requestStartTime: 456,
startTime: 999888777666
Expand Down
5 changes: 2 additions & 3 deletions UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ class BTPayPalClient_Tests: XCTestCase {
enablePayPalAppSwitch: true
)

vaultRequest.application.payPalAppInstalled = true

mockAPIClient.cannedResponseBody = BTJSON(value: [
"agreementSetup": [
"paypalAppApprovalUrl": "https://www.paypal.com?ba_token=BA-Random-Value"
Expand Down Expand Up @@ -932,14 +930,15 @@ class BTPayPalClient_Tests: XCTestCase {

func testIsiOSAppSwitchAvailable_whenApplicationCanOpenPayPalInAppURL_returnsTrueAndSendsAnalytics() {
let fakeApplication = FakeApplication()
fakeApplication.cannedCanOpenURL = true
payPalClient.application = fakeApplication

let vaultRequest = BTPayPalVaultRequest(
userAuthenticationEmail: "[email protected]",
enablePayPalAppSwitch: true
)

vaultRequest.application.payPalAppInstalled = true
vaultRequest.application = fakeApplication

mockAPIClient.cannedResponseBody = BTJSON(value: [
"agreementSetup": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import XCTest
@testable import BraintreeCore
@testable import BraintreePayPal
@testable import BraintreeTestShared

class BTPayPalVaultRequest_Tests: XCTestCase {

Expand Down Expand Up @@ -76,6 +77,10 @@ class BTPayPalVaultRequest_Tests: XCTestCase {
enablePayPalAppSwitch: true
)

let fakeApplication = FakeApplication()
fakeApplication.cannedCanOpenURL = true
request.application = fakeApplication

let parameters = request.parameters(with: configuration, universalLink: URL(string: "some-url")!)

XCTAssertEqual(parameters["launch_paypal_app"] as? Bool, true)
Expand Down

0 comments on commit fbd98a8

Please sign in to comment.