diff --git a/StripePaymentSheet/Project.swift b/StripePaymentSheet/Project.swift index ce7432d8e45..e2f308f6e65 100644 --- a/StripePaymentSheet/Project.swift +++ b/StripePaymentSheet/Project.swift @@ -12,5 +12,5 @@ let project = Project.stripeFramework( .project(target: "StripePayments", path: "//StripePayments"), .project(target: "StripePaymentsUI", path: "//StripePaymentsUI"), ], - unitTestOptions: .testOptions() + unitTestOptions: .testOptions(usesPreconditionTesting: true) ) diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetConfiguration.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetConfiguration.swift index c37163592c0..6c7630cbe14 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetConfiguration.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetConfiguration.swift @@ -172,11 +172,13 @@ extension PaymentSheet { /// See https://stripe.com/docs/api/customers/object#customer_object-id public let id: String - /// A short-lived token that allows the SDK to access a Customer's payment methods + /// A short-lived token that allows the SDK to access a Customer's payment methods. Cannot be empty public let ephemeralKeySecret: String /// Initializes a CustomerConfiguration public init(id: String, ephemeralKeySecret: String) { + assert(!ephemeralKeySecret.isEmpty, "Ephemeral key secret cannot be empty") + self.id = id self.ephemeralKeySecret = ephemeralKeySecret } diff --git a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheetConfigurationTests.swift b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheetConfigurationTests.swift new file mode 100644 index 00000000000..dc8e9241899 --- /dev/null +++ b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheetConfigurationTests.swift @@ -0,0 +1,21 @@ +// +// PaymentSheetConfigurationTests.swift +// StripePaymentSheetTests +// +// Copyright © 2023 Stripe, Inc. All rights reserved. +// + +import CwlPreconditionTesting +import StripePaymentSheet +import XCTest + +final class PaymentSheetConfigurationTests: XCTestCase { + + func test_customerConfigurationInit_assertsWhenEphemeralKeyIsBlank() throws { + let exception = catchBadInstruction { + _ = PaymentSheet.CustomerConfiguration(id: "foo", ephemeralKeySecret: "") + } + + XCTAssertNotNil(exception) + } +}