Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
warmkesselj committed Feb 12, 2025
1 parent 3844f89 commit 82b5a4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/BraintreePayPal/PayPalAccountPostEncodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct PayPalAccountPostEncodable: Encodable {

let paypalAccount: PayPalAccount
let meta: Meta
let merchantAccountID: String?

init(
request: BTPayPalRequest,
Expand All @@ -26,11 +27,14 @@ struct PayPalAccountPostEncodable: Encodable {
)

self.meta = Meta(meta: client.metadata)

self.merchantAccountID = request.merchantAccountID
}

enum CodingKeys: String, CodingKey {
case paypalAccount = "paypal_account"
case meta = "_meta"
case merchantAccountID = "merchant_account_id"
}
}

Expand Down
20 changes: 19 additions & 1 deletion UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ class BTPayPalClient_Tests: XCTestCase {

func testHandleBrowserSwitchReturn_whenBrowserSwitchSucceeds_tokenizesPayPalCheckout() {
let returnURL = URL(string: "bar://onetouch/v1/success?token=hermes_token")!

let payPalRequest = BTPayPalVaultRequest()
payPalClient.payPalRequest = payPalRequest

payPalClient.handleReturn(returnURL, paymentType: .checkout) { _, _ in }

XCTAssertEqual(mockAPIClient.lastPOSTPath, "/v1/payment_methods/paypal_accounts")
Expand Down Expand Up @@ -430,6 +434,8 @@ class BTPayPalClient_Tests: XCTestCase {
func testHandleBrowserSwitchReturn_whenBrowserSwitchSucceeds_intentShouldBeNilForVaultRequests() {
let payPalRequest = BTPayPalVaultRequest()
let returnURL = URL(string: "bar://onetouch/v1/success?ec-token=ec_token")!

payPalClient.payPalRequest = payPalRequest
payPalClient.handleReturn(returnURL, paymentType: payPalRequest.paymentType) { _, _ in }

XCTAssertEqual(mockAPIClient.lastPOSTPath, "/v1/payment_methods/paypal_accounts")
Expand All @@ -441,8 +447,12 @@ class BTPayPalClient_Tests: XCTestCase {

func testHandleBrowserSwitchReturn_whenBrowserSwitchSucceeds_merchantAccountIdIsSet() {
let merchantAccountID = "alternate-merchant-account-id"

let payPalRequest = BTPayPalVaultRequest()
payPalClient.payPalRequest = payPalRequest

payPalClient.payPalRequest = BTPayPalCheckoutRequest(amount: "1.34", merchantAccountID: merchantAccountID)

let returnURL = URL(string: "bar://onetouch/v1/success?token=hermes_token")!
payPalClient.handleReturn(returnURL, paymentType: .checkout) { _, _ in }

Expand Down Expand Up @@ -520,6 +530,10 @@ class BTPayPalClient_Tests: XCTestCase {

func testHandleBrowserSwitchReturn_whenBrowserSwitchSucceeds_sendsCorrectParametersForTokenization() {
let returnURL = URL(string: "bar://onetouch/v1/success?token=hermes_token")!

let payPalRequest = BTPayPalVaultRequest()
payPalClient.payPalRequest = payPalRequest

payPalClient.handleReturn(returnURL, paymentType: .vault) { _, _ in }

XCTAssertEqual(mockAPIClient.lastPOSTPath, "/v1/payment_methods/paypal_accounts")
Expand Down Expand Up @@ -696,6 +710,10 @@ class BTPayPalClient_Tests: XCTestCase {

func testMetadata_whenCheckoutBrowserSwitchIsSuccessful_isPOSTedToServer() {
let returnURL = URL(string: "bar://onetouch/v1/success?token=hermes_token")!

let payPalRequest = BTPayPalVaultRequest()
payPalClient.payPalRequest = payPalRequest

payPalClient.handleReturn(returnURL, paymentType: .checkout) { _, _ in }

XCTAssertEqual(mockAPIClient.lastPOSTPath, "/v1/payment_methods/paypal_accounts")
Expand Down

0 comments on commit 82b5a4c

Please sign in to comment.