Skip to content

Commit 903e6d4

Browse files
committed
Add tests for onboarding fixes
1 parent 8878969 commit 903e6d4

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

WooCommerce/WooCommerceTests/ViewRelated/CardPresentPayments/CardPresentPaymentsOnboardingUseCaseTests.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import XCTest
22
import Fakes
33
import Yosemite
4+
import enum Alamofire.AFError
45
@testable import WooCommerce
56

67
class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
@@ -1226,6 +1227,62 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
12261227
XCTAssertEqual(CardPresentPaymentsPlugin.stripe.plugin, .stripe)
12271228
XCTAssertEqual(CardPresentPaymentsPlugin.stripe.fileNameWithPathExtension, "woocommerce-gateway-stripe/woocommerce-gateway-stripe")
12281229
}
1230+
1231+
// MARK: - loadAccounts error handling tests
1232+
1233+
func test_onboarding_handles_network_error_when_loading_accounts() {
1234+
// Given
1235+
setupCountry(country: .us)
1236+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
1237+
1238+
// Use AFError.sessionTaskFailed which is what Alamofire returns for network errors
1239+
let urlError = URLError(.notConnectedToInternet)
1240+
let networkError = AFError.sessionTaskFailed(error: urlError)
1241+
stores.whenReceivingAction(ofType: CardPresentPaymentAction.self) { action in
1242+
switch action {
1243+
case let .loadAccounts(_, onCompletion):
1244+
onCompletion(.failure(networkError))
1245+
default:
1246+
break
1247+
}
1248+
}
1249+
1250+
// When
1251+
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager,
1252+
stores: stores,
1253+
cardPresentPaymentOnboardingStateCache: onboardingStateCache)
1254+
useCase.updateAccounts()
1255+
1256+
// Then - Should show no connection error
1257+
XCTAssertEqual(useCase.state, .noConnectionError)
1258+
}
1259+
1260+
func test_onboarding_handles_generic_error_when_both_accounts_fail_to_load() {
1261+
// Given
1262+
setupCountry(country: .us)
1263+
setupWCPayPlugin(status: .active, version: WCPayPluginVersion.minimumSupportedVersion)
1264+
setupStripePlugin(status: .active, version: StripePluginVersion.minimumSupportedVersion)
1265+
1266+
let genericError = NSError(domain: "test.error", code: 500, userInfo: nil)
1267+
stores.whenReceivingAction(ofType: CardPresentPaymentAction.self) { action in
1268+
switch action {
1269+
case let .loadAccounts(_, onCompletion):
1270+
// Both accounts fail to load
1271+
onCompletion(.failure(genericError))
1272+
default:
1273+
break
1274+
}
1275+
}
1276+
1277+
// When
1278+
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager,
1279+
stores: stores,
1280+
cardPresentPaymentOnboardingStateCache: onboardingStateCache)
1281+
useCase.updateAccounts()
1282+
1283+
// Then - Should show generic error
1284+
XCTAssertEqual(useCase.state, .genericError)
1285+
}
12291286
}
12301287

12311288
// MARK: - Settings helpers

0 commit comments

Comments
 (0)