@@ -4,6 +4,7 @@ import XCTest
44
55@testable import Yosemite
66@testable import Networking
7+ @testable import WooFoundation
78
89final class OrderCardPresentPaymentEligibilityStoreTests : XCTestCase {
910
@@ -28,6 +29,7 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
2829 private var store : OrderCardPresentPaymentEligibilityStore !
2930
3031 private var currentSite : Site ?
32+ private var isCIABSupported = true
3133
3234 override func setUp( ) {
3335 super. setUp ( )
@@ -38,6 +40,10 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
3840 dispatcher: dispatcher,
3941 storageManager: storageManager,
4042 network: network,
43+ crashLogger: MockCrashLogger ( ) ,
44+ isCIABEnvironmentSupported: { [ weak self] in
45+ return self ? . isCIABSupported ?? false
46+ } ,
4147 currentSite: { [ weak self] in
4248 return self ? . currentSite
4349 }
@@ -46,6 +52,7 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
4652
4753 override func tearDown( ) {
4854 currentSite = nil
55+ isCIABSupported = true
4956 super. tearDown ( )
5057 }
5158
@@ -98,6 +105,53 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
98105 XCTAssertTrue ( eligibility)
99106 }
100107
108+ func test_orderIsEligibleForCardPresentPayment_returns_true_for_eligible_order_and_none_stored_site( ) throws {
109+ // Given
110+ let orderItem = OrderItem . fake ( ) . copy ( itemID: 1234 ,
111+ name: " Chocolate cake " ,
112+ productID: 678 ,
113+ quantity: 1.0 )
114+ let cppEligibleOrder = Order . fake ( ) . copy ( siteID: sampleSiteID,
115+ orderID: 111 ,
116+ status: . pending,
117+ currency: " USD " ,
118+ datePaid: nil ,
119+ total: " 5.00 " ,
120+ paymentMethodID: " woocommerce_payments " ,
121+ items: [ orderItem] )
122+ let nonSubscriptionProduct = Product . fake ( ) . copy ( siteID: sampleSiteID,
123+ productID: 678 ,
124+ name: " Chocolate cake " ,
125+ productTypeKey: " simple " )
126+
127+ let regularSite = Site . fake ( ) . copy (
128+ siteID: sampleSiteID,
129+ isGarden: false ,
130+ gardenName: nil
131+ )
132+ self . currentSite = regularSite
133+
134+ storageManager. insertSampleProduct ( readOnlyProduct: nonSubscriptionProduct)
135+ storageManager. insertSampleOrder ( readOnlyOrder: cppEligibleOrder)
136+
137+ let configuration = CardPresentPaymentsConfiguration ( country: . US)
138+
139+ // When
140+ let result = waitFor { promise in
141+ let action = OrderCardPresentPaymentEligibilityAction
142+ . orderIsEligibleForCardPresentPayment ( orderID: 111 ,
143+ siteID: self . sampleSiteID,
144+ cardPresentPaymentsConfiguration: configuration) { result in
145+ promise ( result)
146+ }
147+ self . store. onAction ( action)
148+ }
149+
150+ // Then
151+ let eligibility = try XCTUnwrap ( result. get ( ) )
152+ XCTAssertTrue ( eligibility)
153+ }
154+
101155 func test_orderIsEligibleForCardPresentPayment_returns_failure_for_CIAB_sites( ) throws {
102156 // Given
103157 let orderItem = OrderItem . fake ( ) . copy ( itemID: 1234 ,
@@ -147,4 +201,96 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
147201 . cardReaderPaymentOptionIsNotSupportedForCIABSites)
148202 }
149203 }
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+ }
256+
257+ func test_orderIsEligibleForCardPresentPayment_returns_success_when_site_is_not_obtained_and_CIAB_supported( ) throws {
258+ // Given
259+ let orderItem = OrderItem . fake ( ) . copy ( itemID: 1234 ,
260+ name: " Chocolate cake " ,
261+ productID: 678 ,
262+ quantity: 1.0 )
263+ let cppEligibleOrder = Order . fake ( ) . copy ( siteID: sampleSiteID,
264+ orderID: 111 ,
265+ status: . pending,
266+ currency: " USD " ,
267+ datePaid: nil ,
268+ total: " 5.00 " ,
269+ paymentMethodID: " woocommerce_payments " ,
270+ items: [ orderItem] )
271+ let nonSubscriptionProduct = Product . fake ( ) . copy ( siteID: sampleSiteID,
272+ productID: 678 ,
273+ name: " Chocolate cake " ,
274+ productTypeKey: " simple " )
275+
276+ storageManager. insertSampleProduct ( readOnlyProduct: nonSubscriptionProduct)
277+ storageManager. insertSampleOrder ( readOnlyOrder: cppEligibleOrder)
278+
279+ let configuration = CardPresentPaymentsConfiguration ( country: . US)
280+
281+ // When
282+ let result = waitFor { promise in
283+ let action = OrderCardPresentPaymentEligibilityAction
284+ . orderIsEligibleForCardPresentPayment ( orderID: 111 ,
285+ siteID: self . sampleSiteID,
286+ cardPresentPaymentsConfiguration: configuration) { result in
287+ promise ( result)
288+ }
289+ self . store. onAction ( action)
290+ }
291+
292+ // Then
293+ let eligibility = try XCTUnwrap ( result. get ( ) )
294+ XCTAssertTrue ( eligibility)
295+ }
150296}
0 commit comments