@@ -605,21 +605,21 @@ struct PointOfSaleAggregateModelTests {
605605 cardPresentPaymentService. connectedReader = nil
606606
607607 orderController. orderStateToReturn = makeLoadedOrderState ( orderTotal: " $1.00 " , orderTotalDecimal: 1 )
608- await sut. checkOut ( )
609- cardPresentPaymentService. collectPaymentWasCalled = false
610608
611- // When
612- // `await confirmation` callback only waits until this completes, not until some timeout.
613- // Since this is synchonous but triggers async combine behaviour, we can't use that approach.
614- cardPresentPaymentService. connectedReader = . init( name: " Test reader " , batteryLevel: 0.7 )
609+ await sut. checkOut ( )
610+ #expect( cardPresentPaymentService. collectPaymentWasCalled == false )
615611
616- // Then
617- let timeout = ContinuousClock . now + . seconds( 2 )
612+ await withCheckedContinuation { continuation in
613+ cardPresentPaymentService. onCollectPaymentCalled = {
614+ continuation. resume ( )
615+ }
618616
619- while cardPresentPaymentService. collectPaymentWasCalled != true {
620- try await Task . sleep ( for: . milliseconds( 1 ) )
621- try #require( . now < timeout)
617+ // When: the card reader connects
618+ cardPresentPaymentService. connectedReader = . init( name: " Test reader " , batteryLevel: 0.7 )
622619 }
620+
621+ // Then
622+ #expect( cardPresentPaymentService. collectPaymentWasCalled == true )
623623 }
624624
625625 @Test func checkOut_when_reader_is_already_connected_and_order_more_than_zero_collectPayment_called( ) async throws {
@@ -667,21 +667,21 @@ struct PointOfSaleAggregateModelTests {
667667
668668 orderController. orderStateToReturn = makeLoadedOrderState ( orderTotal: " $1.00 " , orderTotalDecimal: 1 )
669669 await sut. checkOut ( )
670+ #expect( cardPresentPaymentService. collectPaymentWasCalled == true )
670671 await cardPresentPaymentService. disconnectReader ( )
671672 cardPresentPaymentService. collectPaymentWasCalled = false
672673
673- // When
674- // `await confirmation` callback only waits until this completes, not until some timeout.
675- // Since this is synchonous but triggers async combine behaviour, we can't use that approach.
676- cardPresentPaymentService. connectedReader = . init( name: " Test reader " , batteryLevel: 0.7 )
677-
678- // Then
679- let timeout = ContinuousClock . now + . seconds( 1 )
674+ await withCheckedContinuation { continuation in
675+ cardPresentPaymentService. onCollectPaymentCalled = {
676+ continuation. resume ( )
677+ }
680678
681- while cardPresentPaymentService. collectPaymentWasCalled != true {
682- try await Task . sleep ( for: . milliseconds( 1 ) )
683- try #require( . now < timeout)
679+ // When: the card reader is reconnected
680+ cardPresentPaymentService. connectedReader = . init( name: " Test reader " , batteryLevel: 0.7 )
684681 }
682+
683+ // Then
684+ #expect( cardPresentPaymentService. collectPaymentWasCalled == true )
685685 }
686686
687687 @Test ( . disabled( ) ) func cancelThenCollectPayment_still_collects_payment_when_cancellation_fails( ) async throws {
0 commit comments