Skip to content

Commit ffe3aeb

Browse files
committed
PR suggestion changes
1 parent dfd3601 commit ffe3aeb

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

Modules/Sources/Yosemite/Tools/POS/POSCatalogSyncCoordinator.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import Storage
44
public protocol POSCatalogSyncCoordinatorProtocol {
55
/// Performs a full catalog sync for the specified site
66
/// - Parameter siteID: The site ID to sync catalog for
7-
/// - Returns: The synced catalog containing products and variations
8-
func performFullSync(for siteID: Int64) async throws -> POSCatalog
7+
func performFullSync(for siteID: Int64) async throws
98

109
/// Determines if a full sync should be performed based on the age of the last sync
1110
/// - Parameters:
@@ -16,25 +15,24 @@ public protocol POSCatalogSyncCoordinatorProtocol {
1615
}
1716

1817
public final class POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
19-
private let syncService: POSCatalogFullSyncServiceProtocol
18+
private let fullSyncService: POSCatalogFullSyncServiceProtocol
2019
private let settingsStore: SiteSpecificAppSettingsStoreMethodsProtocol
2120

22-
public init(syncService: POSCatalogFullSyncServiceProtocol,
21+
public init(fullSyncService: POSCatalogFullSyncServiceProtocol,
2322
settingsStore: SiteSpecificAppSettingsStoreMethodsProtocol? = nil) {
24-
self.syncService = syncService
23+
self.fullSyncService = fullSyncService
2524
self.settingsStore = settingsStore ?? SiteSpecificAppSettingsStoreMethods(fileStorage: PListFileStorage())
2625
}
2726

28-
public func performFullSync(for siteID: Int64) async throws -> POSCatalog {
27+
public func performFullSync(for siteID: Int64) async throws {
2928
DDLogInfo("🔄 POSCatalogSyncCoordinator starting full sync for site \(siteID)")
3029

31-
let catalog = try await syncService.startFullSync(for: siteID)
30+
let catalog = try await fullSyncService.startFullSync(for: siteID)
3231

3332
// Record the sync timestamp
3433
settingsStore.setPOSLastFullSyncDate(Date(), for: siteID)
3534

3635
DDLogInfo("✅ POSCatalogSyncCoordinator completed full sync for site \(siteID)")
37-
return catalog
3836
}
3937

4038
public func shouldPerformFullSync(for siteID: Int64, maxAge: TimeInterval) -> Bool {

Modules/Tests/YosemiteTests/Stores/Helpers/SiteSpecificAppSettingsStoreMethodsTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ struct SiteSpecificAppSettingsStoreMethodsTests {
230230
#expect(retrievedCouponTerms == couponTerms)
231231
}
232232

233-
234-
235233
// MARK: - POS Last Full Sync Date Tests
236234

237235
@Test func getPOSLastFullSyncDate_returns_nil_when_no_date_exists() {

Modules/Tests/YosemiteTests/Tools/POS/POSCatalogSyncCoordinatorTests.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct POSCatalogSyncCoordinatorTests {
1313
self.mockSyncService = MockPOSCatalogFullSyncService()
1414
self.mockSettingsStore = MockSiteSpecificAppSettingsStoreMethods()
1515
self.sut = POSCatalogSyncCoordinator(
16-
syncService: mockSyncService,
16+
fullSyncService: mockSyncService,
1717
settingsStore: mockSettingsStore
1818
)
1919
}
@@ -26,14 +26,12 @@ struct POSCatalogSyncCoordinatorTests {
2626
products: [POSProduct.fake()],
2727
variations: [POSProductVariation.fake()]
2828
)
29-
mockSyncService.startFullSyncResult = expectedCatalog
29+
mockSyncService.startFullSyncResult = .success(expectedCatalog)
3030

3131
// When
32-
let result = try await sut.performFullSync(for: sampleSiteID)
32+
try await sut.performFullSync(for: sampleSiteID)
3333

3434
// Then
35-
#expect(result.products.count == expectedCatalog.products.count)
36-
#expect(result.variations.count == expectedCatalog.variations.count)
3735
#expect(mockSyncService.startFullSyncCallCount == 1)
3836
#expect(mockSyncService.lastSyncSiteID == sampleSiteID)
3937
}
@@ -42,7 +40,7 @@ struct POSCatalogSyncCoordinatorTests {
4240
// Given
4341
let beforeSync = Date()
4442
let expectedCatalog = POSCatalog(products: [], variations: [])
45-
mockSyncService.startFullSyncResult = expectedCatalog
43+
mockSyncService.startFullSyncResult = .success(expectedCatalog)
4644

4745
// When
4846
_ = try await sut.performFullSync(for: sampleSiteID)
@@ -61,7 +59,7 @@ struct POSCatalogSyncCoordinatorTests {
6159
@Test func performFullSync_propagates_errors() async throws {
6260
// Given
6361
let expectedError = NSError(domain: "sync", code: 500, userInfo: [NSLocalizedDescriptionKey: "Sync failed"])
64-
mockSyncService.startFullSyncError = expectedError
62+
mockSyncService.startFullSyncResult = .failure(expectedError)
6563

6664
// When/Then
6765
await #expect(throws: expectedError) {
@@ -144,8 +142,7 @@ struct POSCatalogSyncCoordinatorTests {
144142
// MARK: - Mock Services
145143

146144
final class MockPOSCatalogFullSyncService: POSCatalogFullSyncServiceProtocol {
147-
var startFullSyncResult: POSCatalog = POSCatalog(products: [], variations: [])
148-
var startFullSyncError: Error?
145+
var startFullSyncResult: Result<POSCatalog, Error> = .success(POSCatalog(products: [], variations: []))
149146

150147
private(set) var startFullSyncCallCount = 0
151148
private(set) var lastSyncSiteID: Int64?
@@ -154,10 +151,11 @@ final class MockPOSCatalogFullSyncService: POSCatalogFullSyncServiceProtocol {
154151
startFullSyncCallCount += 1
155152
lastSyncSiteID = siteID
156153

157-
if let error = startFullSyncError {
154+
switch startFullSyncResult {
155+
case .success(let catalog):
156+
return catalog
157+
case .failure(let error):
158158
throw error
159159
}
160-
161-
return startFullSyncResult
162160
}
163161
}

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,12 @@ private extension MainTabBarController {
794794

795795
func createPOSCatalogSyncCoordinator() -> POSCatalogSyncCoordinatorProtocol? {
796796
guard let credentials = ServiceLocator.stores.sessionManager.defaultCredentials,
797-
let syncService = POSCatalogFullSyncService(credentials: credentials, grdbManager: ServiceLocator.grdbManager)
797+
let fullSyncService = POSCatalogFullSyncService(credentials: credentials, grdbManager: ServiceLocator.grdbManager)
798798
else {
799799
return nil
800800
}
801801

802-
return POSCatalogSyncCoordinator(syncService: syncService)
802+
return POSCatalogSyncCoordinator(fullSyncService: fullSyncService)
803803
}
804804

805805
func triggerPOSCatalogSyncIfNeeded(for siteID: Int64) async {

0 commit comments

Comments
 (0)