diff --git a/Modules/Tests/PointOfSaleTests/Models/PointOfSaleAggregateModelTests.swift b/Modules/Tests/PointOfSaleTests/Models/PointOfSaleAggregateModelTests.swift index ef136688f59..ed179e65638 100644 --- a/Modules/Tests/PointOfSaleTests/Models/PointOfSaleAggregateModelTests.swift +++ b/Modules/Tests/PointOfSaleTests/Models/PointOfSaleAggregateModelTests.swift @@ -605,21 +605,21 @@ struct PointOfSaleAggregateModelTests { cardPresentPaymentService.connectedReader = nil orderController.orderStateToReturn = makeLoadedOrderState(orderTotal: "$1.00", orderTotalDecimal: 1) - await sut.checkOut() - cardPresentPaymentService.collectPaymentWasCalled = false - // When - // `await confirmation` callback only waits until this completes, not until some timeout. - // Since this is synchonous but triggers async combine behaviour, we can't use that approach. - cardPresentPaymentService.connectedReader = .init(name: "Test reader", batteryLevel: 0.7) + await sut.checkOut() + #expect(cardPresentPaymentService.collectPaymentWasCalled == false) - // Then - let timeout = ContinuousClock.now + .seconds(2) + await withCheckedContinuation { continuation in + cardPresentPaymentService.onCollectPaymentCalled = { + continuation.resume() + } - while cardPresentPaymentService.collectPaymentWasCalled != true { - try await Task.sleep(for: .milliseconds(1)) - try #require(.now < timeout) + // When: the card reader connects + cardPresentPaymentService.connectedReader = .init(name: "Test reader", batteryLevel: 0.7) } + + // Then + #expect(cardPresentPaymentService.collectPaymentWasCalled == true) } @Test func checkOut_when_reader_is_already_connected_and_order_more_than_zero_collectPayment_called() async throws { @@ -667,21 +667,21 @@ struct PointOfSaleAggregateModelTests { orderController.orderStateToReturn = makeLoadedOrderState(orderTotal: "$1.00", orderTotalDecimal: 1) await sut.checkOut() + #expect(cardPresentPaymentService.collectPaymentWasCalled == true) await cardPresentPaymentService.disconnectReader() cardPresentPaymentService.collectPaymentWasCalled = false - // When - // `await confirmation` callback only waits until this completes, not until some timeout. - // Since this is synchonous but triggers async combine behaviour, we can't use that approach. - cardPresentPaymentService.connectedReader = .init(name: "Test reader", batteryLevel: 0.7) - - // Then - let timeout = ContinuousClock.now + .seconds(1) + await withCheckedContinuation { continuation in + cardPresentPaymentService.onCollectPaymentCalled = { + continuation.resume() + } - while cardPresentPaymentService.collectPaymentWasCalled != true { - try await Task.sleep(for: .milliseconds(1)) - try #require(.now < timeout) + // When: the card reader is reconnected + cardPresentPaymentService.connectedReader = .init(name: "Test reader", batteryLevel: 0.7) } + + // Then + #expect(cardPresentPaymentService.collectPaymentWasCalled == true) } @Test(.disabled()) func cancelThenCollectPayment_still_collects_payment_when_cancellation_fails() async throws {