Skip to content

Commit 92f6427

Browse files
committed
Update unit tests to test stripe and wcpay plugin versions separately
1 parent 94aaad6 commit 92f6427

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

WooCommerce/WooCommerceTests/ViewRelated/CardPresentPayments/CardPresentPaymentsOnboardingUseCaseTests.swift

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
8080
func test_onboarding_returns_wcpay_plugin_not_activated_when_wcpay_installed_but_not_active() {
8181
// Given
8282
setupCountry(country: .us)
83-
setupWCPayPlugin(status: .inactive, version: .minimumSupportedVersion)
83+
setupWCPayPlugin(status: .inactive, version: WCPayPluginVersion.minimumSupportedVersion)
8484

8585
// When
8686
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager, stores: stores)
@@ -93,21 +93,21 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
9393
func test_onboarding_returns_stripe_plugin_not_activated_when_stripe_installed_but_not_active() {
9494
// Given
9595
setupCountry(country: .us)
96-
setupStripePlugin(status: .inactive, version: .minimumSupportedVersion)
96+
setupStripePlugin(status: .inactive, version: StripePluginVersion.minimumSupportedVersion)
9797

9898
// When
9999
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager, stores: stores)
100100
let state = useCase.state
101101

102102
// Then
103-
XCTAssertEqual(state, .pluginNotActivated(plugin: .wcPay))
103+
XCTAssertEqual(state, .pluginNotActivated(plugin: .stripe))
104104
}
105105

106106
func test_onboarding_returns_select_plugin_when_both_stripe_and_wcpay_plugins_are_active() {
107107
// Given
108108
setupCountry(country: .us)
109-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
110-
setupStripePlugin(status: .active, version: .minimumSupportedVersion)
109+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
110+
setupStripePlugin(status: .active, version: StripePluginVersion.minimumSupportedVersion)
111111

112112
// When
113113
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager, stores: stores)
@@ -120,7 +120,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
120120
func test_onboarding_returns_wcpay_plugin_unsupported_version_when_unpatched_wcpay_outdated() {
121121
// Given
122122
setupCountry(country: .us)
123-
setupWCPayPlugin(status: .active, version: .unsupportedVersionWithoutPatch)
123+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.unsupportedVersionWithoutPatch)
124124

125125
// When
126126
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager, stores: stores)
@@ -133,7 +133,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
133133
func test_onboarding_returns_wcpay_in_test_mode_with_live_stripe_account_when_live_account_in_test_mode() {
134134
// Given
135135
setupCountry(country: .us)
136-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
136+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
137137
setupPaymentGatewayAccount(status: .complete, isLive: true, isInTestMode: true)
138138

139139
// When
@@ -147,7 +147,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
147147
func test_onboarding_returns_wcpay_unsupported_version_when_patched_wcpay_plugin_outdated() {
148148
// Given
149149
setupCountry(country: .us)
150-
setupWCPayPlugin(status: .active, version: .unsupportedVersionWithPatch)
150+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.unsupportedVersionWithPatch)
151151

152152
// When
153153
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager, stores: stores)
@@ -160,7 +160,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
160160
func test_onboarding_returns_complete_when_wcpay_plugin_version_matches_minimum_exactly() {
161161
// Given
162162
setupCountry(country: .us)
163-
setupWCPayPlugin(status: .networkActive, version: .minimumSupportedVersion)
163+
setupWCPayPlugin(status: .networkActive, version: WCPayPluginVersion.minimumSupportedVersion)
164164
setupPaymentGatewayAccount(status: .complete)
165165

166166
// When
@@ -174,7 +174,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
174174
func test_onboarding_returns_complete_when_wcpay_plugin_version_has_newer_patch_release() {
175175
// Given
176176
setupCountry(country: .us)
177-
setupWCPayPlugin(status: .networkActive, version: .supportedVersionWithPatch)
177+
setupWCPayPlugin(status: .networkActive, version: WCPayPluginVersion.minimumSupportedVersion)
178178
setupPaymentGatewayAccount(status: .complete)
179179

180180
// When
@@ -188,7 +188,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
188188
func test_onboarding_returns_complete_when_wcpay_plugin_version_has_newer_unpatched_release() {
189189
// Given
190190
setupCountry(country: .us)
191-
setupWCPayPlugin(status: .networkActive, version: .supportedVersionWithoutPatch)
191+
setupWCPayPlugin(status: .networkActive, version: WCPayPluginVersion.minimumSupportedVersion)
192192
setupPaymentGatewayAccount(status: .complete)
193193

194194
// When
@@ -202,7 +202,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
202202
func test_onboarding_returns_complete_when_wcpay_plugin_active() {
203203
// Given
204204
setupCountry(country: .us)
205-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
205+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
206206
setupPaymentGatewayAccount(status: .complete)
207207

208208
// When
@@ -216,7 +216,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
216216
func test_onboarding_returns_complete_when_wcpay_plugin_is_network_active() {
217217
// Given
218218
setupCountry(country: .us)
219-
setupWCPayPlugin(status: .networkActive, version: .minimumSupportedVersion)
219+
setupWCPayPlugin(status: .networkActive, version: WCPayPluginVersion.minimumSupportedVersion)
220220
setupPaymentGatewayAccount(status: .complete)
221221

222222
// When
@@ -232,7 +232,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
232232
func test_onboarding_returns_generic_error_with_no_account_for_wcplay_plugin() {
233233
// Given
234234
setupCountry(country: .us)
235-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
235+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
236236

237237
// When
238238
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager, stores: stores)
@@ -245,7 +245,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
245245
func test_onboarding_returns_generic_error_when_account_is_not_eligible_for_wcplay_plugin() {
246246
// Given
247247
setupCountry(country: .us)
248-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
248+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
249249
setupPaymentGatewayAccount(status: .complete, isCardPresentEligible: false)
250250

251251
// When
@@ -259,7 +259,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
259259
func test_onboarding_returns_not_completed_when_account_is_not_connected_for_wcplay_plugin() {
260260
// Given
261261
setupCountry(country: .us)
262-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
262+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
263263
setupPaymentGatewayAccount(status: .noAccount)
264264

265265
// When
@@ -273,7 +273,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
273273
func test_onboarding_returns_pending_requirements_when_account_is_restricted_with_pending_requirements_for_wcplay_plugin() {
274274
// Given
275275
setupCountry(country: .us)
276-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
276+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
277277
setupPaymentGatewayAccount(status: .restricted, hasPendingRequirements: true)
278278

279279
// When
@@ -287,7 +287,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
287287
func test_onboarding_returns_pending_requirements_when_account_is_restricted_soon_with_pending_requirements_for_wcplay_plugin() {
288288
// Given
289289
setupCountry(country: .us)
290-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
290+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
291291
setupPaymentGatewayAccount(status: .restrictedSoon, hasPendingRequirements: true)
292292

293293
// When
@@ -301,7 +301,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
301301
func test_onboarding_returns_overdue_requirements_when_account_is_restricted_with_overdue_requirements_for_wcplay_plugin() {
302302
// Given
303303
setupCountry(country: .us)
304-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
304+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
305305
setupPaymentGatewayAccount(status: .restricted, hasOverdueRequirements: true)
306306

307307
// When
@@ -315,7 +315,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
315315
func test_onboarding_returns_overdue_requirements_when_account_is_restricted_with_overdue_and_pending_requirements_for_wcplay_plugin() {
316316
// Given
317317
setupCountry(country: .us)
318-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
318+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
319319
setupPaymentGatewayAccount(status: .restricted, hasPendingRequirements: true, hasOverdueRequirements: true)
320320

321321
// When
@@ -329,7 +329,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
329329
func test_onboarding_returns_review_when_account_is_restricted_with_no_requirements_for_wcplay_plugin() {
330330
// Given
331331
setupCountry(country: .us)
332-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
332+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
333333
setupPaymentGatewayAccount(status: .restricted)
334334

335335
// When
@@ -344,7 +344,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
344344
func test_onboarding_returns_rejected_when_account_is_rejected_for_fraud_for_wcplay_plugin() {
345345
// Given
346346
setupCountry(country: .us)
347-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
347+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
348348
setupPaymentGatewayAccount(status: .rejectedFraud)
349349

350350
// When
@@ -358,7 +358,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
358358
func test_onboarding_returns_rejected_when_account_is_rejected_for_tos_for_wcplay_plugin() {
359359
// Given
360360
setupCountry(country: .us)
361-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
361+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
362362
setupPaymentGatewayAccount(status: .rejectedTermsOfService)
363363

364364
// When
@@ -372,7 +372,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
372372
func test_onboarding_returns_rejected_when_account_is_listed_for_wcplay_plugin() {
373373
// Given
374374
setupCountry(country: .us)
375-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
375+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
376376
setupPaymentGatewayAccount(status: .rejectedListed)
377377

378378
// When
@@ -386,7 +386,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
386386
func test_onboarding_returns_rejected_when_account_is_rejected_for_other_reasons_for_wcplay_plugin() {
387387
// Given
388388
setupCountry(country: .us)
389-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
389+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
390390
setupPaymentGatewayAccount(status: .rejectedOther)
391391

392392
// When
@@ -400,7 +400,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
400400
func test_onboarding_returns_generic_error_when_account_status_unknown_for_wcplay_plugin() {
401401
// Given
402402
setupCountry(country: .us)
403-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
403+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
404404
setupPaymentGatewayAccount(status: .unknown)
405405

406406
// When
@@ -414,7 +414,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
414414
func test_onboarding_returns_complete_when_account_is_setup_successfully_for_wcplay_plugin() {
415415
// Given
416416
setupCountry(country: .us)
417-
setupWCPayPlugin(status: .active, version: .minimumSupportedVersion)
417+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
418418
setupPaymentGatewayAccount(status: .complete)
419419

420420
// When
@@ -447,7 +447,7 @@ private extension CardPresentPaymentsOnboardingUseCaseTests {
447447

448448
// MARK: - Plugin helpers
449449
private extension CardPresentPaymentsOnboardingUseCaseTests {
450-
func setupWCPayPlugin(status: SitePluginStatusEnum, version: PluginVersion) {
450+
func setupWCPayPlugin(status: SitePluginStatusEnum, version: WCPayPluginVersion) {
451451
let active = status == .active || status == .networkActive
452452
let networkActivated = status == .networkActive
453453
let plugin = SystemPlugin
@@ -463,7 +463,7 @@ private extension CardPresentPaymentsOnboardingUseCaseTests {
463463
storageManager.insertSampleSystemPlugin(readOnlySystemPlugin: plugin)
464464
}
465465

466-
func setupStripePlugin(status: SitePluginStatusEnum, version: PluginVersion) {
466+
func setupStripePlugin(status: SitePluginStatusEnum, version: StripePluginVersion) {
467467
let active = status == .active || status == .networkActive
468468
let networkActivated = status == .networkActive
469469
let plugin = SystemPlugin
@@ -478,13 +478,19 @@ private extension CardPresentPaymentsOnboardingUseCaseTests {
478478
)
479479
storageManager.insertSampleSystemPlugin(readOnlySystemPlugin: plugin)
480480
}
481-
enum PluginVersion: String {
481+
482+
enum WCPayPluginVersion: String {
482483
case unsupportedVersionWithPatch = "2.4.2"
483484
case unsupportedVersionWithoutPatch = "3.2"
484-
case minimumSupportedVersion = "3.2.1" /// Should match `minimumSupportedWCPayVersion` in `CardPresentPaymentsOnboardingUseCase`
485+
case minimumSupportedVersion = "3.2.1" // Should match `CardPresentPaymentsOnboardingState` `minimumSupportedPluginVersion`
485486
case supportedVersionWithPatch = "3.2.5"
486487
case supportedVersionWithoutPatch = "3.3"
487488
}
489+
490+
enum StripePluginVersion: String {
491+
case minimumSupportedVersion = "5.9.0" // Should match `CardPresentPaymentsOnboardingState` `minimumSupportedPluginVersion`
492+
}
493+
488494
}
489495

490496
// MARK: - Account helpers

Yosemite/Yosemite/Model/Enums/CardPresentPaymentsOnboardingState.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public enum CardPresentPaymentsPlugins: Equatable {
114114
}
115115
}
116116

117+
/// Changing values here? You'll need to also update `CardPresentPaymentsOnboardingUseCaseTests`
118+
///
117119
public var minimumSupportedPluginVersion: String {
118120
switch self {
119121
case .wcPay:

0 commit comments

Comments
 (0)