File tree Expand file tree Collapse file tree 2 files changed +18
-20
lines changed
WooCommerce/WooCommerceTests/POS Expand file tree Collapse file tree 2 files changed +18
-20
lines changed Original file line number Diff line number Diff line change @@ -33,21 +33,11 @@ final class MockPointOfSaleOrderController: PointOfSaleOrderControllerProtocol {
3333 }
3434
3535 var clearOrderWasCalled : Bool = false
36- private var clearOrderContinuation : CheckedContinuation < Void , Never > ?
36+ var onClearOrderCalled : ( ) -> Void = { }
3737
3838 func clearOrder( ) async {
3939 clearOrderWasCalled = true
40- await withCheckedContinuation { continuation in
41- clearOrderContinuation = continuation
42- // Resume immediately to simulate completion
43- continuation. resume ( )
44- }
45- }
46-
47- func waitForClearOrder( ) async {
48- while !clearOrderWasCalled {
49- try ? await Task . sleep ( nanoseconds: 1_000_000 )
50- }
40+ onClearOrderCalled ( )
5141 }
5242
5343 var sendReceiptErrorToThrow : Error ?
Original file line number Diff line number Diff line change @@ -213,14 +213,18 @@ struct PointOfSaleAggregateModelTests {
213213 cardPresentPaymentService: cardPresentPaymentService,
214214 orderController: orderController,
215215 )
216-
217216 sut. addToCart ( makePurchasableItem ( ) )
218217
219- // When
220- sut. startNewCart ( )
218+ await withCheckedContinuation { continuation in
219+ orderController. onClearOrderCalled = {
220+ continuation. resume ( )
221+ }
222+
223+ // When
224+ sut. startNewCart ( )
225+ }
221226
222227 // Then
223- await orderController. waitForClearOrder ( )
224228 #expect( orderController. clearOrderWasCalled == true )
225229 }
226230
@@ -323,14 +327,18 @@ struct PointOfSaleAggregateModelTests {
323327 itemsController: itemsController,
324328 cardPresentPaymentService: cardPresentPaymentService,
325329 orderController: orderController)
326-
327330 sut. addToCart ( makePurchasableItem ( ) )
328331
329- // When
330- sut. pointOfSaleClosed ( )
332+ await withCheckedContinuation { continuation in
333+ orderController. onClearOrderCalled = {
334+ continuation. resume ( )
335+ }
336+
337+ // When
338+ sut. pointOfSaleClosed ( )
339+ }
331340
332341 // Then
333- await orderController. waitForClearOrder ( )
334342 #expect( orderController. clearOrderWasCalled == true )
335343 #expect( cardPresentPaymentService. cancelPaymentCalled == true )
336344 }
You can’t perform that action at this time.
0 commit comments