@@ -336,75 +336,76 @@ final class SimplePaymentsMethodsViewModelTests: XCTestCase {
336336 assertEqual ( analytics. receivedProperties. last ? [ " payment_method " ] as? String , " card " )
337337 }
338338
339- func test_card_row_is_shown_for_eligible_order ( ) {
339+ func test_card_row_is_shown_for_eligible_order_and_country ( ) {
340340 // Given
341+ let stores = MockStoresManager ( sessionManager: . testingInstance)
341342 let storage = MockStorageManager ( )
342- let orderItem = OrderItem . fake ( ) . copy ( itemID: 1234 ,
343- name: " Chocolate cake " ,
344- productID: 678 ,
345- quantity: 1.0 )
346- let cppEligibleOrder = Order . fake ( ) . copy ( siteID: 1212 ,
347- orderID: 111 ,
348- status: . pending,
349- currency: " USD " ,
350- datePaid: nil ,
351- total: " 5.00 " ,
352- paymentMethodID: " woocommerce_payments " ,
353- items: [ orderItem] )
354- let nonSubscriptionProduct = Product . fake ( ) . copy ( siteID: 1212 ,
355- productID: 678 ,
356- name: " Chocolate cake " ,
357- productTypeKey: " simple " )
343+ let configuration = CardPresentPaymentsConfiguration . init ( country: " US " )
344+ stores. whenReceivingAction ( ofType: OrderCardPresentPaymentEligibilityAction . self) { action in
345+ switch action {
346+ case let . orderIsEligibleForCardPresentPayment( _, _, _, completion) :
347+ completion ( . success( true ) )
348+ }
349+ }
358350
359- storage. insertSampleProduct ( readOnlyProduct: nonSubscriptionProduct)
360- storage. insertSampleOrder ( readOnlyOrder: cppEligibleOrder)
351+ let dependencies = Dependencies ( stores: stores, storage: storage, cardPresentPaymentsConfiguration: configuration)
352+ let viewModel = SimplePaymentsMethodsViewModel ( siteID: 1212 , orderID: 111 , formattedTotal: " $5.00 " , dependencies: dependencies)
353+
354+ // Then
355+ XCTAssertTrue ( viewModel. showPayWithCardRow)
356+ }
361357
358+ func test_card_row_is_not_shown_when_there_is_an_error_checking_for_order_eligibility( ) {
359+ // Given
360+ let stores = MockStoresManager ( sessionManager: . testingInstance)
361+ let storage = MockStorageManager ( )
362362 let configuration = CardPresentPaymentsConfiguration . init ( country: " US " )
363+ stores. whenReceivingAction ( ofType: OrderCardPresentPaymentEligibilityAction . self) { action in
364+ switch action {
365+ case let . orderIsEligibleForCardPresentPayment( _, _, _, completion) :
366+ completion ( . failure( NSError ( domain: " Error " , code: 0 ) ) )
367+ }
368+ }
363369
364- let dependencies = Dependencies ( storage: storage, cardPresentPaymentsConfiguration: configuration)
370+ let dependencies = Dependencies ( stores : stores , storage: storage, cardPresentPaymentsConfiguration: configuration)
365371 let viewModel = SimplePaymentsMethodsViewModel ( siteID: 1212 , orderID: 111 , formattedTotal: " $5.00 " , dependencies: dependencies)
366372
367373 // Then
368- XCTAssertTrue ( viewModel. showPayWithCardRow)
374+ XCTAssertFalse ( viewModel. showPayWithCardRow)
369375 }
370376
371- func test_card_row_is_not_shown_for_eligible_order_but_ineligible_country ( ) {
377+ func test_card_row_is_not_shown_for_non_eligible_order ( ) {
372378 // Given
379+ let stores = MockStoresManager ( sessionManager: . testingInstance)
373380 let storage = MockStorageManager ( )
374- let orderItem = OrderItem . fake ( ) . copy ( itemID: 1234 ,
375- name: " Chocolate cake " ,
376- productID: 678 ,
377- quantity: 1.0 )
378- let cppEligibleOrder = Order . fake ( ) . copy ( siteID: 1212 ,
379- orderID: 111 ,
380- status: . pending,
381- currency: " USD " ,
382- datePaid: nil ,
383- total: " 5.00 " ,
384- paymentMethodID: " woocommerce_payments " ,
385- items: [ orderItem] )
386- let nonSubscriptionProduct = Product . fake ( ) . copy ( siteID: 1212 ,
387- productID: 678 ,
388- name: " Chocolate cake " ,
389- productTypeKey: " simple " )
381+ let configuration = CardPresentPaymentsConfiguration . init ( country: " US " )
382+ stores. whenReceivingAction ( ofType: OrderCardPresentPaymentEligibilityAction . self) { action in
383+ switch action {
384+ case let . orderIsEligibleForCardPresentPayment( _, _, _, completion) :
385+ completion ( . success( false ) )
386+ }
387+ }
390388
391- storage. insertSampleProduct ( readOnlyProduct: nonSubscriptionProduct)
392- storage. insertSampleOrder ( readOnlyOrder: cppEligibleOrder)
389+ let dependencies = Dependencies ( stores: stores, storage: storage, cardPresentPaymentsConfiguration: configuration)
390+ let viewModel = SimplePaymentsMethodsViewModel ( siteID: 1212 , orderID: 111 , formattedTotal: " $5.00 " , dependencies: dependencies)
391+
392+ // Then
393+ XCTAssertFalse ( viewModel. showPayWithCardRow)
394+ }
393395
394- // Antarctica 🤞 (it's actually based on the lack of the following 4 properties)
395- let configuration = CardPresentPaymentsConfiguration . init ( countryCode: " AQ " ,
396- paymentMethods: [ ] ,
397- currencies: [ ] ,
398- paymentGateways: [ ] ,
399- supportedReaders: [ ] ,
400- supportedPluginVersions: [
401- . init( plugin: . wcPay, minimumVersion: " 3.2.1 " ) ,
402- . init( plugin: . stripe, minimumVersion: " 6.2.0 " )
403- ] ,
404- minimumAllowedChargeAmount: NSDecimalNumber ( string: " 0.5 " ) ,
405- stripeSmallestCurrencyUnitMultiplier: 100 )
396+ func test_card_row_is_not_shown_for_eligible_order_but_ineligible_country( ) {
397+ // Given
398+ let stores = MockStoresManager ( sessionManager: . testingInstance)
399+ let storage = MockStorageManager ( )
400+ let configuration = CardPresentPaymentsConfiguration . init ( country: " AQ " )
401+ stores. whenReceivingAction ( ofType: OrderCardPresentPaymentEligibilityAction . self) { action in
402+ switch action {
403+ case let . orderIsEligibleForCardPresentPayment( _, _, _, completion) :
404+ completion ( . success( true ) )
405+ }
406+ }
406407
407- let dependencies = Dependencies ( storage: storage, cardPresentPaymentsConfiguration: configuration)
408+ let dependencies = Dependencies ( stores : stores , storage: storage, cardPresentPaymentsConfiguration: configuration)
408409 let viewModel = SimplePaymentsMethodsViewModel ( siteID: 1212 , orderID: 111 , formattedTotal: " $5.00 " , dependencies: dependencies)
409410
410411 // Then
0 commit comments