Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ where TapToPayAlertProvider.AlertDetails == AlertPresenter.AlertDetails,
alertProvider: paymentAlertProvider,
onCompleted: onCompleted)
}
onPaymentCompletion()
}
}
onPaymentCompletion()
})
case .canceled(let cancellationSource, _):
self.handlePaymentCancellation(from: cancellationSource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ final class MockReceiptEligibilityUseCase: ReceiptEligibilityUseCaseProtocol {
var isEligibleForFailedPaymentEmailReceipts: Bool = false
var isEligibleForReceipt: Bool = true

var mockIsEligibleForBackendReceiptsHandler: ((@escaping (Bool) -> Void) -> Void)?

func isEligibleForBackendReceipts(onCompletion: @escaping (Bool) -> Void) {
onCompletion(isEligibleForBackendReceipts)
if let handler = mockIsEligibleForBackendReceiptsHandler {
handler(onCompletion)
} else {
onCompletion(isEligibleForBackendReceipts)
}
}

func isEligibleForSuccessfulPaymentEmailReceipts(onCompletion: @escaping (Bool) -> Void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,55 @@ final class CollectOrderPaymentUseCaseTests: XCTestCase {
// Then
XCTAssertEqual(mockPaymentOrchestrator.spyChannel, .pos)
}

func test_completion_called_after_alert_presentation() throws {
receiptEligibilityUseCase.isEligibleForBackendReceipts = true
let paymentMethod = PaymentMethod.cardPresent(details: .fake())
let intent = PaymentIntent.fake().copy(charges: [.fake().copy(paymentMethod: paymentMethod)])
let capturedPaymentData = CardPresentCapturedPaymentData(paymentMethod: paymentMethod, receiptParameters: .fake())
mockSuccessfulCardPresentPaymentActions(intent: intent, capturedPaymentData: capturedPaymentData)
enum Event {
case receiptEligibilityCheck
case alertPresented
case paymentCompletion
}
var eventOrder: [Event] = []

receiptEligibilityUseCase.mockIsEligibleForBackendReceiptsHandler = { completion in
// Force receiptEligibilityCheck completion delay
DispatchQueue.main.async {
eventOrder.append(.receiptEligibilityCheck)
completion(true)
}
}

// Track when receipt alert is presented
alertsPresenter.onPresentCalled = { viewModel in
if viewModel is CardPresentModalSuccessWithoutEmail ||
viewModel is CardPresentModalSuccessEmailSent {
eventOrder.append(.alertPresented)
}
}

// When payment succeeds
waitFor { promise in
self.useCase.collectPayment(
using: .bluetoothScan,
channel: .storeManagement,
onFailure: { _ in },
onCancel: {},
onPaymentCompletion: {
eventOrder.append(.paymentCompletion)
promise(())
},
onCompleted: {}
)
self.mockPreflightController.completeConnection(reader: MockCardReader.wisePad3(), gatewayID: Mocks.paymentGatewayAccount)
}

// Then ensure payment completion happens after alert presentation to avoid CollectOrderPaymentUseCase deinit before alert presentation
XCTAssertEqual(eventOrder, [.receiptEligibilityCheck, .alertPresented, .paymentCompletion])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way of testing this 👍

}
}

private extension CollectOrderPaymentUseCaseTests {
Expand Down
Loading