Skip to content

Commit 8f779e3

Browse files
committed
6180 Test fetching charge for Refund Confirmation
1 parent 0a44507 commit 8f779e3

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Issue Refunds/IssueRefundViewModel.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,15 @@ final class IssueRefundViewModel {
106106

107107
private let analytics: Analytics
108108

109-
init(order: Order, refunds: [Refund], currencySettings: CurrencySettings, analytics: Analytics = ServiceLocator.analytics) {
109+
private let stores: StoresManager
110+
111+
init(order: Order,
112+
refunds: [Refund],
113+
currencySettings: CurrencySettings,
114+
analytics: Analytics = ServiceLocator.analytics,
115+
stores: StoresManager = ServiceLocator.stores) {
110116
self.analytics = analytics
117+
self.stores = stores
111118
let items = Self.filterItems(from: order, with: refunds)
112119
state = State(order: order, refunds: refunds, itemsToRefund: items, currencySettings: currencySettings)
113120
sections = createSections()
@@ -246,7 +253,7 @@ private extension IssueRefundViewModel {
246253
return
247254
}
248255
let action = CardPresentPaymentAction.fetchWCPayCharge(siteID: state.order.siteID, chargeID: chargeID, onCompletion: { _ in })
249-
ServiceLocator.stores.dispatch(action)
256+
stores.dispatch(action)
250257
}
251258
}
252259

WooCommerce/WooCommerceTests/ViewRelated/Orders/Issue Refund/IssueRefundViewModelTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,26 @@ final class IssueRefundViewModelTests: XCTestCase {
581581
// Then
582582
XCTAssertFalse(viewModel.isSelectAllButtonVisible)
583583
}
584+
585+
func test_viewModel_fetches_charge_before_creating_refundConfirmationViewModel() throws {
586+
// Given
587+
// The order has a chargeID
588+
let order = MockOrders().sampleOrder().copy(chargeID: "ch_id")
589+
let stores = MockStoresManager(sessionManager: .makeForTesting(authenticated: true))
590+
591+
// When
592+
let chargeFetched: Bool = waitFor { promise in
593+
stores.whenReceivingAction(ofType: CardPresentPaymentAction.self) { action in
594+
guard case .fetchWCPayCharge(siteID: _, chargeID: "ch_id", onCompletion: _) = action else {
595+
return
596+
}
597+
promise(true)
598+
}
599+
600+
_ = IssueRefundViewModel(order: order, refunds: [], currencySettings: CurrencySettings(), stores: stores)
601+
}
602+
603+
// Then
604+
XCTAssertTrue(chargeFetched)
605+
}
584606
}

0 commit comments

Comments
 (0)