forked from hideokamoto/stripe-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and add tests for dashboard params (stripe#2984)
## Summary - Refactors the Dashboard hack so it is only applied to deferred PaymentIntents - Adds unit tests ## Motivation https://jira.corp.stripe.com/browse/RUN_MOBILESDK-2650 https://jira.corp.stripe.com/browse/RUN_MOBILESDK-2653 ## Testing - New unit tests ## Changelog N/A
- Loading branch information
1 parent
b917726
commit efeb1ac
Showing
5 changed files
with
173 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// IntentConfirmParamsTest.swift | ||
// StripeiOSTests | ||
// | ||
// Created by Nick Porter on 10/11/23. | ||
// | ||
|
||
import XCTest | ||
|
||
@testable@_spi(STP) import Stripe | ||
@testable@_spi(STP) import StripeCore | ||
@testable@_spi(STP) import StripePayments | ||
@testable@_spi(STP) import StripePaymentSheet | ||
@testable@_spi(STP) import StripePaymentsUI | ||
|
||
final class IntentConfirmParamsTest: XCTestCase { | ||
|
||
func testMakeDashboardParams() { | ||
let params = IntentConfirmParams.makeDashboardParams(paymentIntentClientSecret: "test_client_secret", | ||
paymentMethodID: "test_payment_method_id", | ||
shouldSave: true, | ||
paymentMethodType: .card, | ||
customer: .init(id: "test_id", | ||
ephemeralKeySecret: "test_key")) | ||
|
||
XCTAssertEqual(params.clientSecret, "test_client_secret") | ||
XCTAssertEqual(params.paymentMethodId, "test_payment_method_id") | ||
XCTAssertEqual(params.paymentMethodOptions?.cardOptions?.additionalAPIParameters["setup_future_usage"] as? String, "off_session") | ||
XCTAssertTrue(params.paymentMethodOptions?.cardOptions?.additionalAPIParameters["moto"] as? Bool ?? false) | ||
} | ||
|
||
} |
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
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
81 changes: 81 additions & 0 deletions
81
StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheet+DeferredAPITest.swift
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// PaymentSheet+DeferredAPITest.swift | ||
// StripePaymentSheetTests | ||
// | ||
// Created by Nick Porter on 10/11/23. | ||
// | ||
|
||
@testable@_spi(STP) import StripeCore | ||
@testable@_spi(STP) import StripeCoreTestUtils | ||
@testable@_spi(STP) import StripePayments | ||
@testable@_spi(STP) import StripePaymentSheet | ||
@testable@_spi(STP) import StripePaymentsTestUtils | ||
@testable@_spi(STP) import StripeUICore | ||
import XCTest | ||
|
||
final class PaymentSheet_DeferredAPITest: XCTestCase { | ||
let apiClient = STPAPIClient(publishableKey: STPTestingDefaultPublishableKey) | ||
|
||
lazy var configuration: PaymentSheet.Configuration = { | ||
var config = PaymentSheet.Configuration() | ||
config.apiClient = apiClient | ||
config.allowsDelayedPaymentMethods = true | ||
config.shippingDetails = { | ||
return .init( | ||
address: .init( | ||
country: "US", | ||
line1: "Line 1" | ||
), | ||
name: "Jane Doe", | ||
phone: "5551234567" | ||
) | ||
} | ||
return config | ||
}() | ||
|
||
// MARK: setParamsForDashboardApp tests | ||
func testSetParamsForDashboardApp_saved() { | ||
let examplePaymentMethodParams = STPPaymentMethodParams(card: STPFixtures.paymentMethodCardParams(), billingDetails: nil, metadata: nil) | ||
let paymentOptions = STPConfirmPaymentMethodOptions() | ||
let examplePaymentMethod = STPFixtures.paymentMethod() | ||
var configurationWithCustomer = configuration | ||
configurationWithCustomer.customer = .init(id: "id", ephemeralKeySecret: "ek") | ||
let params = PaymentSheet.setParamsForDashboardApp(confirmType: .new(params: examplePaymentMethodParams, | ||
paymentOptions: paymentOptions, | ||
paymentMethod: examplePaymentMethod, | ||
shouldSave: true), | ||
paymentIntentParams: .init(), | ||
paymentIntent: STPFixtures.makePaymentIntent(), | ||
configuration: configurationWithCustomer) | ||
|
||
// moto should be set to true and sfu = off_session | ||
XCTAssertTrue(params.paymentMethodOptions?.cardOptions?.additionalAPIParameters["moto"] as? Bool ?? false) | ||
XCTAssertEqual(params.paymentMethodOptions?.cardOptions?.additionalAPIParameters["setup_future_usage"] as? String, "off_session") | ||
} | ||
|
||
func testSetParamsForDashboardApp_new() { | ||
let params = PaymentSheet.setParamsForDashboardApp(confirmType: .saved(createValidSavedPaymentMethod()), | ||
paymentIntentParams: .init(), | ||
paymentIntent: STPFixtures.makePaymentIntent(), | ||
configuration: configuration) | ||
|
||
// moto should be set to true | ||
XCTAssertTrue(params.paymentMethodOptions?.cardOptions?.additionalAPIParameters["moto"] as? Bool ?? false) | ||
} | ||
|
||
// MARK: Helpers | ||
func createValidSavedPaymentMethod() -> STPPaymentMethod { | ||
var validSavedPM: STPPaymentMethod? | ||
let createPMExpectation = expectation(description: "Create PM") | ||
apiClient.createPaymentMethod(with: ._testValidCardValue()) { paymentMethod, error in | ||
guard let paymentMethod = paymentMethod else { | ||
XCTFail(String(describing: error)) | ||
return | ||
} | ||
validSavedPM = paymentMethod | ||
createPMExpectation.fulfill() | ||
} | ||
waitForExpectations(timeout: 10) | ||
return validSavedPM! | ||
} | ||
} |