Skip to content

Commit b259f51

Browse files
committed
handle clear order being async in tests
1 parent f1ed6e5 commit b259f51

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleOrderController.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,21 @@ final class MockPointOfSaleOrderController: PointOfSaleOrderControllerProtocol {
3333
}
3434

3535
var clearOrderWasCalled: Bool = false
36+
private var clearOrderContinuation: CheckedContinuation<Void, Never>?
37+
3638
func clearOrder() async {
3739
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+
}
3851
}
3952

4053
var sendReceiptErrorToThrow: Error?

WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ struct PointOfSaleAggregateModelTests {
220220
sut.startNewCart()
221221

222222
// Then
223+
await orderController.waitForClearOrder()
223224
#expect(orderController.clearOrderWasCalled == true)
224225
}
225226

@@ -329,6 +330,7 @@ struct PointOfSaleAggregateModelTests {
329330
sut.pointOfSaleClosed()
330331

331332
// Then
333+
await orderController.waitForClearOrder()
332334
#expect(orderController.clearOrderWasCalled == true)
333335
#expect(cardPresentPaymentService.cancelPaymentCalled == true)
334336
}

0 commit comments

Comments
 (0)