Skip to content

Commit 9ac149e

Browse files
committed
Use confirmation instead of withCheckedContinuation
1 parent 970a015 commit 9ac149e

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

WooCommerce/WooCommerceTests/POS/Mocks/MockPOSCatalogSettingsService.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ final class MockPOSCatalogSettingsService: POSCatalogSettingsServiceProtocol {
44
var catalogInfoResult: Result<POSCatalogInfo, Error> = .success(
55
.init(productCount: 0, variationCount: 0, lastFullSyncDate: nil, lastIncrementalSyncDate: nil)
66
)
7-
var onLoadCatalogInfoCalled: ((_ continuation: CheckedContinuation<Void, Never>) -> Void)? = nil
7+
var onLoadCatalogInfoCalled: (() -> Void)?
88

99
func loadCatalogInfo(for siteID: Int64) async throws -> POSCatalogInfo {
10-
if let onLoadCatalogInfoCalled {
11-
await withCheckedContinuation { continuation in
12-
onLoadCatalogInfoCalled(continuation)
13-
}
14-
}
10+
onLoadCatalogInfoCalled?()
1511

1612
switch catalogInfoResult {
1713
case .success(let info):

WooCommerce/WooCommerceTests/POS/Mocks/MockPOSCatalogSyncCoordinator.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ final class MockPOSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
1010
true
1111
}
1212

13-
var onPerformFullSyncCalled: ((_ continuation: CheckedContinuation<Void, Never>) -> Void)? = nil
13+
var onPerformFullSyncCalled: (() -> Void)?
1414

1515
func performFullSync(for siteID: Int64) async throws {
16-
if let onPerformFullSyncCalled {
17-
await withCheckedContinuation { continuation in
18-
onPerformFullSyncCalled(continuation)
19-
}
20-
}
16+
onPerformFullSyncCalled?()
2117

2218
performFullSyncInvocationCount += 1
2319
performFullSyncSiteID = siteID

WooCommerce/WooCommerceTests/POS/Presentation/Settings/POSSettingsLocalCatalogViewModelTests.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ struct POSSettingsLocalCatalogViewModelTests {
9292
lastIncrementalSyncDate: nil
9393
))
9494

95-
catalogSettingsService.onLoadCatalogInfoCalled = { continuation in
96-
// When loadCatalogInfo is called, loading is set to true
97-
#expect(sut.isLoading == true)
98-
99-
// Finsh loadCatalogInfo
100-
continuation.resume()
95+
await confirmation() { confirmation in
96+
catalogSettingsService.onLoadCatalogInfoCalled = {
97+
// At the time loadCatalogInfo is called, loading is set to true
98+
#expect(sut.isLoading == true)
99+
confirmation()
100+
}
101+
102+
// When
103+
await sut.loadCatalogData()
101104
}
102105

103-
// When
104-
await sut.loadCatalogData()
105-
106106
// Then
107107
#expect(sut.isLoading == false)
108108
}
@@ -137,17 +137,17 @@ struct POSSettingsLocalCatalogViewModelTests {
137137
lastIncrementalSyncDate: nil
138138
))
139139

140-
catalogSyncCoordinator.onPerformFullSyncCalled = { continuation in
141-
// When performFullSyncCalled is called, isRefreshingCatalog is set to true
142-
#expect(sut.isRefreshingCatalog == true)
140+
await confirmation() { confirmation in
141+
catalogSyncCoordinator.onPerformFullSyncCalled = {
142+
// At the time performFullSyncCalled is called, isRefreshingCatalog is set to true
143+
#expect(sut.isRefreshingCatalog == true)
144+
confirmation()
145+
}
143146

144-
// Finsh performFullSync
145-
continuation.resume()
147+
// When
148+
await sut.refreshCatalog()
146149
}
147150

148-
// When
149-
await sut.refreshCatalog()
150-
151151
// Then
152152
#expect(sut.isRefreshingCatalog == false)
153153
}

0 commit comments

Comments
 (0)