-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -745,7 +745,7 @@ class BTPayPalClient_Tests: XCTestCase { | |
XCTAssertNil(BTPayPalClient.payPalClient) | ||
} | ||
|
||
// MARK: - App Switch - tokenize | ||
// MARK: - App Switch - Tokenize | ||
|
||
func testTokenizeVaultAccount_whenPayPalAppApprovalURLPresent_attemptsAppSwitchWithParameters() async { | ||
let fakeApplication = FakeApplication() | ||
|
@@ -858,6 +858,73 @@ class BTPayPalClient_Tests: XCTestCase { | |
|
||
waitForExpectations(timeout: 1) | ||
} | ||
|
||
func testTokenizeCheckoutAccount_whenPayPalAppApprovalURLPresent_attemptsAppSwitchWithParameters() async { | ||
let fakeApplication = FakeApplication() | ||
payPalClient.application = fakeApplication | ||
|
||
mockAPIClient.cannedResponseBody = BTJSON(value: [ | ||
"paymentResource": [ | ||
"redirectUrl": "https://www.some-url.com/some-path?token=value1", | ||
"launchPayPalApp": true | ||
] | ||
]) | ||
|
||
let checkoutRequest = BTPayPalCheckoutRequest( | ||
userAuthenticationEmail: "[email protected]", | ||
enablePayPalAppSwitch: true, | ||
amount: "10.00" | ||
) | ||
payPalClient.tokenize(checkoutRequest) { _, _ in } | ||
|
||
XCTAssertTrue(fakeApplication.openURLWasCalled) | ||
|
||
let urlComponents = URLComponents(url: fakeApplication.lastOpenURL!, resolvingAgainstBaseURL: true) | ||
XCTAssertEqual(urlComponents?.host, "www.some-url.com") | ||
XCTAssertEqual(urlComponents?.path, "/some-path") | ||
|
||
XCTAssertEqual(urlComponents?.queryItems?[0].name, "token") | ||
XCTAssertEqual(urlComponents?.queryItems?[0].value, "value1") | ||
XCTAssertEqual(urlComponents?.queryItems?[1].name, "source") | ||
XCTAssertEqual(urlComponents?.queryItems?[1].value, "braintree_sdk") | ||
XCTAssertEqual(urlComponents?.queryItems?[2].name, "switch_initiated_time") | ||
if let urlTimestamp = urlComponents?.queryItems?[2].value { | ||
XCTAssertNotNil(urlTimestamp) | ||
} else { | ||
XCTFail("Expected integer value for query param `switch_initiated_time`") | ||
} | ||
} | ||
|
||
func testTokenizeCheckoutAccount_whenPayPalAppApprovalURLMissingECToken_returnsError() { | ||
let fakeApplication = FakeApplication() | ||
payPalClient.application = fakeApplication | ||
|
||
mockAPIClient.cannedResponseBody = BTJSON(value: [ | ||
"paymentResource": [ | ||
"redirectUrl": "https://www.some-url.com/some-path", | ||
"launchPayPalApp": true | ||
] | ||
]) | ||
|
||
let checkoutRequest = BTPayPalCheckoutRequest( | ||
userAuthenticationEmail: "[email protected]", | ||
enablePayPalAppSwitch: true, | ||
amount: "10.00" | ||
) | ||
|
||
let expectation = expectation(description: "completion block called") | ||
payPalClient.tokenize(checkoutRequest) { nonce, error in | ||
XCTAssertNil(nonce) | ||
|
||
guard let error = error as NSError? else { XCTFail(); return } | ||
XCTAssertEqual(error.code, 14) | ||
XCTAssertEqual(error.localizedDescription, "Missing EC Token for PayPal App Switch.") | ||
XCTAssertEqual(error.domain, "com.braintreepayments.BTPayPalErrorDomain") | ||
expectation.fulfill() | ||
} | ||
|
||
waitForExpectations(timeout: 1) | ||
} | ||
|
||
func testHandleReturn_whenURLIsUnknown_returnsError() { | ||
let request = BTPayPalVaultRequest( | ||
|