Skip to content

Commit f54b9eb

Browse files
Add iOS unit tests (#2234)
* Add iOS unit tests * wip * wip * wip
1 parent c17ab60 commit f54b9eb

10 files changed

Lines changed: 2390 additions & 199 deletions

example/ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ PODS:
16911691
- StripePayments (= 25.0.1)
16921692
- StripePaymentsUI (= 25.0.1)
16931693
- StripeUICore (= 25.0.1)
1694-
- stripe-react-native (0.56.0):
1694+
- stripe-react-native (0.57.0):
16951695
- DoubleConversion
16961696
- glog
16971697
- hermes-engine
@@ -1712,14 +1712,14 @@ PODS:
17121712
- ReactCommon/turbomodule/bridging
17131713
- ReactCommon/turbomodule/core
17141714
- Stripe (~> 25.0.1)
1715-
- stripe-react-native/NewArch (= 0.56.0)
1715+
- stripe-react-native/NewArch (= 0.57.0)
17161716
- StripeApplePay (~> 25.0.1)
17171717
- StripeFinancialConnections (~> 25.0.1)
17181718
- StripePayments (~> 25.0.1)
17191719
- StripePaymentSheet (~> 25.0.1)
17201720
- StripePaymentsUI (~> 25.0.1)
17211721
- Yoga
1722-
- stripe-react-native/NewArch (0.56.0):
1722+
- stripe-react-native/NewArch (0.57.0):
17231723
- DoubleConversion
17241724
- glog
17251725
- hermes-engine
@@ -1746,7 +1746,7 @@ PODS:
17461746
- StripePaymentSheet (~> 25.0.1)
17471747
- StripePaymentsUI (~> 25.0.1)
17481748
- Yoga
1749-
- stripe-react-native/Tests (0.56.0):
1749+
- stripe-react-native/Tests (0.57.0):
17501750
- DoubleConversion
17511751
- glog
17521752
- hermes-engine
@@ -2110,7 +2110,7 @@ SPEC CHECKSUMS:
21102110
RNScreens: 0d4cb9afe052607ad0aa71f645a88bb7c7f2e64c
21112111
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
21122112
Stripe: 4728e3e0dd8df134e4a420ab504e929a93a815f0
2113-
stripe-react-native: e2dac3be3c2668207a7b7700663b852646a0e7d8
2113+
stripe-react-native: 92258f76847ff71a090d4665204226af84564fd3
21142114
StripeApplePay: 43997281ace138a1c75a8f2d7be11925ea28644c
21152115
StripeCore: 457c30e2fd3a7c4b274a5ad53d1ff03661eef2a0
21162116
StripeFinancialConnections: 8c2e326f767fb014b53174b3a5f8592c0a45fa56

ios/StripeSdkImpl+CustomerSheet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension StripeSdkImpl {
2424
defaultBillingDetails: params["defaultBillingDetails"] as? NSDictionary,
2525
preferredNetworks: params["preferredNetworks"] as? Array<Int>,
2626
allowsRemovalOfLastSavedPaymentMethod: params["allowsRemovalOfLastSavedPaymentMethod"] as? Bool,
27-
cardBrandAcceptance: computeCardBrandAcceptance(params: params)
27+
cardBrandAcceptance: StripeSdkImpl.computeCardBrandAcceptance(params: params)
2828
)
2929
} catch {
3030
resolve(

ios/StripeSdkImpl+Embedded.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension StripeSdkImpl {
3939
modeParams: modeParams,
4040
paymentMethodTypes: intentConfig["paymentMethodTypes"] as? [String],
4141
onBehalfOf: intentConfig["onBehalfOf"] as? String,
42-
captureMethod: mapCaptureMethod(captureMethodString),
42+
captureMethod: StripeSdkImpl.mapCaptureMethod(captureMethodString),
4343
useConfirmationTokenCallback: hasConfirmationTokenHandler
4444
)
4545

@@ -130,7 +130,7 @@ extension StripeSdkImpl {
130130
modeParams: modeParams,
131131
paymentMethodTypes: intentConfig["paymentMethodTypes"] as? [String],
132132
onBehalfOf: intentConfig["onBehalfOf"] as? String,
133-
captureMethod: mapCaptureMethod(captureMethodString),
133+
captureMethod: StripeSdkImpl.mapCaptureMethod(captureMethodString),
134134
useConfirmationTokenCallback: hasConfirmationTokenHandler
135135
)
136136

@@ -310,7 +310,7 @@ extension StripeSdkImpl {
310310
configuration.paymentMethodOrder = paymentMethodOrder
311311
}
312312

313-
configuration.cardBrandAcceptance = computeCardBrandAcceptance(params: params)
313+
configuration.cardBrandAcceptance = StripeSdkImpl.computeCardBrandAcceptance(params: params)
314314

315315
if let formSheetActionParams = params["formSheetAction"] as? NSDictionary,
316316
let actionType = formSheetActionParams["type"] as? String {

ios/StripeSdkImpl+PaymentSheet.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extension StripeSdkImpl {
136136
configuration.paymentMethodLayout = .automatic
137137
}
138138

139-
configuration.cardBrandAcceptance = computeCardBrandAcceptance(params: params)
139+
configuration.cardBrandAcceptance = StripeSdkImpl.computeCardBrandAcceptance(params: params)
140140

141141
// Parse custom payment method configuration
142142
if let customPaymentMethodConfig = params["customPaymentMethodConfiguration"] as? [String: Any] {
@@ -229,7 +229,7 @@ extension StripeSdkImpl {
229229
modeParams: modeParams,
230230
paymentMethodTypes: intentConfiguration["paymentMethodTypes"] as? [String],
231231
onBehalfOf: intentConfiguration["onBehalfOf"] as? String,
232-
captureMethod: mapCaptureMethod(captureMethodString),
232+
captureMethod: StripeSdkImpl.mapCaptureMethod(captureMethodString),
233233
useConfirmationTokenCallback: hasConfirmationTokenHandler
234234
)
235235

@@ -247,7 +247,7 @@ extension StripeSdkImpl {
247247
}
248248
}
249249

250-
internal func computeCardBrandAcceptance(params: NSDictionary) -> PaymentSheet.CardBrandAcceptance {
250+
internal static func computeCardBrandAcceptance(params: NSDictionary) -> PaymentSheet.CardBrandAcceptance {
251251
if let cardBrandAcceptanceParams = params["cardBrandAcceptance"] as? NSDictionary {
252252
if let filter = cardBrandAcceptanceParams["filter"] as? String {
253253
switch filter {
@@ -272,7 +272,7 @@ extension StripeSdkImpl {
272272
return .all
273273
}
274274

275-
private func mapToCardBrandCategory(brand: String) -> PaymentSheet.CardBrandAcceptance.BrandCategory? {
275+
private static func mapToCardBrandCategory(brand: String) -> PaymentSheet.CardBrandAcceptance.BrandCategory? {
276276
switch brand {
277277
case "visa":
278278
return .visa
@@ -287,7 +287,7 @@ extension StripeSdkImpl {
287287
}
288288
}
289289

290-
func mapCaptureMethod(_ captureMethod: String?) -> PaymentSheet.IntentConfiguration.CaptureMethod {
290+
static func mapCaptureMethod(_ captureMethod: String?) -> PaymentSheet.IntentConfiguration.CaptureMethod {
291291
if let captureMethod = captureMethod {
292292
switch captureMethod {
293293
case "Automatic": return PaymentSheet.IntentConfiguration.CaptureMethod.automatic
@@ -311,9 +311,9 @@ extension StripeSdkImpl {
311311
mode = PaymentSheet.IntentConfiguration.Mode.payment(
312312
amount: amount,
313313
currency: modeParams["currencyCode"] as? String ?? "",
314-
setupFutureUsage: setupFutureUsageFromString(from: modeParams["setupFutureUsage"] as? String ?? ""),
314+
setupFutureUsage: StripeSdkImpl.setupFutureUsageFromString(from: modeParams["setupFutureUsage"] as? String ?? ""),
315315
captureMethod: captureMethod,
316-
paymentMethodOptions: buildPaymentMethodOptions(paymentMethodOptionsParams: modeParams["paymentMethodOptions"] as? NSDictionary ?? [:])
316+
paymentMethodOptions: StripeSdkImpl.buildPaymentMethodOptions(paymentMethodOptionsParams: modeParams["paymentMethodOptions"] as? NSDictionary ?? [:])
317317
)
318318
} else {
319319
mode = PaymentSheet.IntentConfiguration.Mode.setup(
@@ -357,33 +357,33 @@ extension StripeSdkImpl {
357357
}
358358
}
359359

360-
func buildPaymentMethodOptions(paymentMethodOptionsParams: NSDictionary) -> PaymentSheet.IntentConfiguration.Mode.PaymentMethodOptions? {
360+
static func buildPaymentMethodOptions(paymentMethodOptionsParams: NSDictionary) -> PaymentSheet.IntentConfiguration.Mode.PaymentMethodOptions? {
361361
if let sfuDictionary = paymentMethodOptionsParams["setupFutureUsageValues"] as? NSDictionary {
362362
var setupFutureUsageValues: [STPPaymentMethodType: PaymentSheet.IntentConfiguration.SetupFutureUsage] = [:]
363-
363+
364364
for (paymentMethodCode, sfuValue) in sfuDictionary {
365365
if let paymentMethodCode = paymentMethodCode as? String,
366366
let sfuString = sfuValue as? String {
367367
let setupFutureUsage = setupFutureUsageFromString(from: sfuString)
368368
let paymentMethodType = STPPaymentMethodType.fromIdentifier(paymentMethodCode)
369-
369+
370370
if let setupFutureUsage = setupFutureUsage {
371371
if paymentMethodType != .unknown {
372372
setupFutureUsageValues[paymentMethodType] = setupFutureUsage
373373
}
374374
}
375375
}
376376
}
377-
377+
378378
if !setupFutureUsageValues.isEmpty {
379379
return PaymentSheet.IntentConfiguration.Mode.PaymentMethodOptions(setupFutureUsageValues: setupFutureUsageValues)
380380
}
381381
}
382382

383383
return nil
384384
}
385-
386-
func setupFutureUsageFromString(from string: String) -> PaymentSheet.IntentConfiguration.SetupFutureUsage? {
385+
386+
static func setupFutureUsageFromString(from string: String) -> PaymentSheet.IntentConfiguration.SetupFutureUsage? {
387387
switch string {
388388
case "OnSession":
389389
return PaymentSheet.IntentConfiguration.SetupFutureUsage.onSession

0 commit comments

Comments
 (0)