@@ -605,21 +605,20 @@ 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+ // Collect payment should only be called once the card reader is connect
618+ cardPresentPaymentService. connectedReader = . init( name: " Test reader " , batteryLevel: 0.7 )
622619 }
620+
621+ #expect( cardPresentPaymentService. collectPaymentWasCalled == true )
623622 }
624623
625624 @Test func checkOut_when_reader_is_already_connected_and_order_more_than_zero_collectPayment_called( ) async throws {
@@ -667,21 +666,20 @@ struct PointOfSaleAggregateModelTests {
667666
668667 orderController. orderStateToReturn = makeLoadedOrderState ( orderTotal: " $1.00 " , orderTotalDecimal: 1 )
669668 await sut. checkOut ( )
669+ #expect( cardPresentPaymentService. collectPaymentWasCalled == true )
670670 await cardPresentPaymentService. disconnectReader ( )
671671 cardPresentPaymentService. collectPaymentWasCalled = false
672672
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 )
673+ await withCheckedContinuation { continuation in
674+ cardPresentPaymentService. onCollectPaymentCalled = {
675+ continuation. resume ( )
676+ }
680677
681- while cardPresentPaymentService. collectPaymentWasCalled != true {
682- try await Task . sleep ( for: . milliseconds( 1 ) )
683- try #require( . now < timeout)
678+ // Collect payment should be called once the card reader is reconnected
679+ cardPresentPaymentService. connectedReader = . init( name: " Test reader " , batteryLevel: 0.7 )
684680 }
681+
682+ #expect( cardPresentPaymentService. collectPaymentWasCalled == true )
685683 }
686684
687685 @Test ( . disabled( ) ) func cancelThenCollectPayment_still_collects_payment_when_cancellation_fails( ) async throws {
0 commit comments