Skip to content

Commit b2c4583

Browse files
committed
Show sucess notices after completing payments
1 parent 3a8cf73 commit b2c4583

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

WooCommerce/Classes/ViewRelated/Orders/Simple Payments/Method/SimplePaymentsMethodsViewModel.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ final class SimplePaymentsMethodsViewModel: ObservableObject {
105105

106106
if error == nil {
107107
onSuccess()
108+
self.presentNoticeSubject.send(.completed)
108109
} else {
109110
self.presentNoticeSubject.send(.error(Localization.markAsPaidError))
110111
}
@@ -137,13 +138,14 @@ final class SimplePaymentsMethodsViewModel: ObservableObject {
137138
paymentGatewayAccount: paymentGateway,
138139
rootViewController: rootViewController)
139140
collectPaymentsUseCase?.collectPayment(onCollect: { _ in
140-
print("On collect does nothing for now...")
141+
/* No op. */
141142
}, onCompleted: { [weak self] in
142-
// TODO: Show success notice
143-
144143
// Inform success to consumer
145144
onSuccess()
146145

146+
// Sent notice request
147+
self?.presentNoticeSubject.send(.completed)
148+
147149
// Make sure we free all the resources
148150
self?.collectPaymentsUseCase = nil
149151
})

WooCommerce/WooCommerceTests/ViewRelated/Orders/Simple Payments/SimplePaymentsAmountViewModelTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ final class SimplePaymentsAmountViewModelTests: XCTestCase {
300300
switch intent {
301301
case .error:
302302
promise(true)
303+
case .completed:
304+
promise(false)
303305
}
304306
}
305307
.store(in: &self.subscriptions)

WooCommerce/WooCommerceTests/ViewRelated/Orders/Simple Payments/SimplePaymentsMethodsViewModelTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@ final class SimplePaymentsMethodsViewModelTests: XCTestCase {
8888
XCTAssertTrue(onSuccessInvoked)
8989
}
9090

91+
func test_view_model_attempts_completed_notice_presentation_when_marking_an_order_as_paid() {
92+
// Given
93+
let stores = MockStoresManager(sessionManager: .testingInstance)
94+
let noticeSubject = PassthroughSubject<SimplePaymentsNotice, Never>()
95+
let viewModel = SimplePaymentsMethodsViewModel(formattedTotal: "$12.00", presentNoticeSubject: noticeSubject, stores: stores)
96+
stores.whenReceivingAction(ofType: OrderAction.self) { action in
97+
switch action {
98+
case let .updateOrderStatus(_, _, _, onCompletion):
99+
onCompletion(nil)
100+
default:
101+
XCTFail("Unexpected action: \(action)")
102+
}
103+
}
104+
105+
// When
106+
let receivedCompleted: Bool = waitFor { promise in
107+
noticeSubject.sink { intent in
108+
switch intent {
109+
case .error:
110+
promise(false)
111+
case .completed:
112+
promise(true)
113+
}
114+
}
115+
.store(in: &self.subscriptions)
116+
viewModel.markOrderAsPaid(onSuccess: {})
117+
}
118+
119+
// Then
120+
XCTAssertTrue(receivedCompleted)
121+
}
122+
91123
func test_view_model_attempts_error_notice_presentation_when_failing_to_mark_order_as_paid() {
92124
// Given
93125
let stores = MockStoresManager(sessionManager: .testingInstance)
@@ -108,6 +140,8 @@ final class SimplePaymentsMethodsViewModelTests: XCTestCase {
108140
switch intent {
109141
case .error:
110142
promise(true)
143+
case .completed:
144+
promise(false)
111145
}
112146
}
113147
.store(in: &self.subscriptions)

WooCommerce/WooCommerceTests/ViewRelated/Orders/Simple Payments/SimplePaymentsSummaryViewModelTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ final class SimplePaymentsSummaryViewModelTests: XCTestCase {
133133
switch intent {
134134
case .error:
135135
promise(true)
136+
case .completed:
137+
promise(false)
136138
}
137139
}
138140
.store(in: &self.subscriptions)

0 commit comments

Comments
 (0)