Skip to content

Commit dd32b83

Browse files
committed
Add test for site assessment skip when CIAB is not supported
1 parent f15876a commit dd32b83

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

Modules/Tests/PointOfSaleTests/Mocks/MockFeatureFlagService.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class MockFeatureFlagService: POSFeatureFlagProviding {
2525
var isProductImageOptimizedHandlingEnabled: Bool
2626
var isFeatureFlagEnabledReturnValue: [FeatureFlag: Bool] = [:]
2727
var isCIABBookingsEnabled: Bool
28+
var isCIABEnabled: Bool
2829

2930
init(isInboxOn: Bool = false,
3031
isShowInboxCTAEnabled: Bool = false,
@@ -47,7 +48,8 @@ final class MockFeatureFlagService: POSFeatureFlagProviding {
4748
notificationSettings: Bool = false,
4849
allowMerchantAIAPIKey: Bool = false,
4950
isProductImageOptimizedHandlingEnabled: Bool = false,
50-
isCIABBookingsEnabled: Bool = false) {
51+
isCIABBookingsEnabled: Bool = false,
52+
isCIABEnabled: Bool = false) {
5153
self.isInboxOn = isInboxOn
5254
self.isShowInboxCTAEnabled = isShowInboxCTAEnabled
5355
self.isUpdateOrderOptimisticallyOn = isUpdateOrderOptimisticallyOn
@@ -70,6 +72,7 @@ final class MockFeatureFlagService: POSFeatureFlagProviding {
7072
self.allowMerchantAIAPIKey = allowMerchantAIAPIKey
7173
self.isProductImageOptimizedHandlingEnabled = isProductImageOptimizedHandlingEnabled
7274
self.isCIABBookingsEnabled = isCIABBookingsEnabled
75+
self.isCIABEnabled = isCIABEnabled
7376
}
7477

7578
func isFeatureFlagEnabled(_ featureFlag: FeatureFlag) -> Bool {
@@ -124,6 +127,8 @@ final class MockFeatureFlagService: POSFeatureFlagProviding {
124127
return isProductImageOptimizedHandlingEnabled
125128
case .ciabBookings:
126129
return isCIABBookingsEnabled
130+
case .ciab:
131+
return isCIABEnabled
127132
default:
128133
return false
129134
}

Modules/Tests/YosemiteTests/Stores/OrderCardPresentPaymentEligibilityStoreTests.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
2929
private var store: OrderCardPresentPaymentEligibilityStore!
3030

3131
private var currentSite: Site?
32+
private var isCIABSupported = true
3233

3334
override func setUp() {
3435
super.setUp()
@@ -40,6 +41,9 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
4041
storageManager: storageManager,
4142
network: network,
4243
crashLogger: MockCrashLogger(),
44+
isCIABEnvironmentSupported: { [weak self] in
45+
return self?.isCIABSupported ?? false
46+
},
4347
currentSite: { [weak self] in
4448
return self?.currentSite
4549
}
@@ -48,6 +52,7 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
4852

4953
override func tearDown() {
5054
currentSite = nil
55+
isCIABSupported = true
5156
super.tearDown()
5257
}
5358

@@ -196,4 +201,56 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
196201
.cardReaderPaymentOptionIsNotSupportedForCIABSites)
197202
}
198203
}
204+
205+
func test_orderIsEligibleForCardPresentPayment_returns_success_when_site_is_CIAB_and_CIAB_not_supported() throws {
206+
// Given
207+
208+
/// Simulate that the CIAB environment support is not yet rolled out
209+
isCIABSupported = false
210+
211+
let orderItem = OrderItem.fake().copy(itemID: 1234,
212+
name: "Chocolate cake",
213+
productID: 678,
214+
quantity: 1.0)
215+
let cppEligibleOrder = Order.fake().copy(siteID: sampleSiteID,
216+
orderID: 111,
217+
status: .pending,
218+
currency: "USD",
219+
datePaid: nil,
220+
total: "5.00",
221+
paymentMethodID: "woocommerce_payments",
222+
items: [orderItem])
223+
let nonSubscriptionProduct = Product.fake().copy(siteID: sampleSiteID,
224+
productID: 678,
225+
name: "Chocolate cake",
226+
productTypeKey: "simple")
227+
228+
let ciabSite = Site.fake().copy(
229+
siteID: sampleSiteID,
230+
isGarden: true,
231+
gardenName: "commerce"
232+
)
233+
self.currentSite = ciabSite
234+
235+
storageManager.insertSampleSite(readOnlySite: ciabSite)
236+
storageManager.insertSampleProduct(readOnlyProduct: nonSubscriptionProduct)
237+
storageManager.insertSampleOrder(readOnlyOrder: cppEligibleOrder)
238+
239+
let configuration = CardPresentPaymentsConfiguration(country: .US)
240+
241+
// When
242+
let result = waitFor { promise in
243+
let action = OrderCardPresentPaymentEligibilityAction
244+
.orderIsEligibleForCardPresentPayment(orderID: 111,
245+
siteID: self.sampleSiteID,
246+
cardPresentPaymentsConfiguration: configuration) { result in
247+
promise(result)
248+
}
249+
self.store.onAction(action)
250+
}
251+
252+
// Then
253+
let eligibility = try XCTUnwrap(result.get())
254+
XCTAssertTrue(eligibility)
255+
}
199256
}

WooCommerce/WooCommerceTests/ViewRelated/Orders/Payment Methods/PaymentMethodsViewModelTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ final class PaymentMethodsViewModelTests: XCTestCase {
808808
storageManager: storage,
809809
network: MockNetwork(),
810810
crashLogger: MockCrashLogger(),
811+
isCIABEnvironmentSupported: { true },
811812
currentSite: { ciabSite }
812813
)
813814

0 commit comments

Comments
 (0)