Skip to content

Commit 9c2104f

Browse files
committed
Merge branch 'woomob-1252-top-level-catalog-sync-coordinator' into woomob-1252-always-full-sync-if-site-not-in-database
2 parents bf08946 + ffe3aeb commit 9c2104f

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
@@ -5,8 +5,7 @@ import GRDB
55
public protocol POSCatalogSyncCoordinatorProtocol {
66
/// Performs a full catalog sync for the specified site
77
/// - Parameter siteID: The site ID to sync catalog for
8-
/// - Returns: The synced catalog containing products and variations
9-
func performFullSync(for siteID: Int64) async throws -> POSCatalog
8+
func performFullSync(for siteID: Int64) async throws
109

1110
/// Determines if a full sync should be performed based on the age of the last sync
1211
/// - Parameters:
@@ -17,28 +16,27 @@ public protocol POSCatalogSyncCoordinatorProtocol {
1716
}
1817

1918
public final class POSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
20-
private let syncService: POSCatalogFullSyncServiceProtocol
19+
private let fullSyncService: POSCatalogFullSyncServiceProtocol
2120
private let settingsStore: SiteSpecificAppSettingsStoreMethodsProtocol
2221
private let grdbManager: GRDBManagerProtocol
2322

24-
public init(syncService: POSCatalogFullSyncServiceProtocol,
23+
public init(fullSyncService: POSCatalogFullSyncServiceProtocol,
2524
settingsStore: SiteSpecificAppSettingsStoreMethodsProtocol? = nil,
2625
grdbManager: GRDBManagerProtocol) {
27-
self.syncService = syncService
26+
self.fullSyncService = fullSyncService
2827
self.settingsStore = settingsStore ?? SiteSpecificAppSettingsStoreMethods(fileStorage: PListFileStorage())
2928
self.grdbManager = grdbManager
3029
}
3130

32-
public func performFullSync(for siteID: Int64) async throws -> POSCatalog {
31+
public func performFullSync(for siteID: Int64) async throws {
3332
DDLogInfo("🔄 POSCatalogSyncCoordinator starting full sync for site \(siteID)")
3433

35-
let catalog = try await syncService.startFullSync(for: siteID)
34+
let catalog = try await fullSyncService.startFullSync(for: siteID)
3635

3736
// Record the sync timestamp
3837
settingsStore.setPOSLastFullSyncDate(Date(), for: siteID)
3938

4039
DDLogInfo("✅ POSCatalogSyncCoordinator completed full sync for site \(siteID)")
41-
return catalog
4240
}
4341

4442
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
@@ -15,7 +15,7 @@ struct POSCatalogSyncCoordinatorTests {
1515
self.mockSettingsStore = MockSiteSpecificAppSettingsStoreMethods()
1616
self.grdbManager = try GRDBManager()
1717
self.sut = POSCatalogSyncCoordinator(
18-
syncService: mockSyncService,
18+
fullSyncService: mockSyncService,
1919
settingsStore: mockSettingsStore,
2020
grdbManager: grdbManager
2121
)
@@ -29,14 +29,12 @@ struct POSCatalogSyncCoordinatorTests {
2929
products: [POSProduct.fake()],
3030
variations: [POSProductVariation.fake()]
3131
)
32-
mockSyncService.startFullSyncResult = expectedCatalog
32+
mockSyncService.startFullSyncResult = .success(expectedCatalog)
3333

3434
// When
35-
let result = try await sut.performFullSync(for: sampleSiteID)
35+
try await sut.performFullSync(for: sampleSiteID)
3636

3737
// Then
38-
#expect(result.products.count == expectedCatalog.products.count)
39-
#expect(result.variations.count == expectedCatalog.variations.count)
4038
#expect(mockSyncService.startFullSyncCallCount == 1)
4139
#expect(mockSyncService.lastSyncSiteID == sampleSiteID)
4240
}
@@ -45,7 +43,7 @@ struct POSCatalogSyncCoordinatorTests {
4543
// Given
4644
let beforeSync = Date()
4745
let expectedCatalog = POSCatalog(products: [], variations: [])
48-
mockSyncService.startFullSyncResult = expectedCatalog
46+
mockSyncService.startFullSyncResult = .success(expectedCatalog)
4947

5048
// When
5149
_ = try await sut.performFullSync(for: sampleSiteID)
@@ -64,7 +62,7 @@ struct POSCatalogSyncCoordinatorTests {
6462
@Test func performFullSync_propagates_errors() async throws {
6563
// Given
6664
let expectedError = NSError(domain: "sync", code: 500, userInfo: [NSLocalizedDescriptionKey: "Sync failed"])
67-
mockSyncService.startFullSyncError = expectedError
65+
mockSyncService.startFullSyncResult = .failure(expectedError)
6866

6967
// When/Then
7068
await #expect(throws: expectedError) {
@@ -205,8 +203,7 @@ struct POSCatalogSyncCoordinatorTests {
205203
// MARK: - Mock Services
206204

207205
final class MockPOSCatalogFullSyncService: POSCatalogFullSyncServiceProtocol {
208-
var startFullSyncResult: POSCatalog = POSCatalog(products: [], variations: [])
209-
var startFullSyncError: Error?
206+
var startFullSyncResult: Result<POSCatalog, Error> = .success(POSCatalog(products: [], variations: []))
210207

211208
private(set) var startFullSyncCallCount = 0
212209
private(set) var lastSyncSiteID: Int64?
@@ -215,10 +212,11 @@ final class MockPOSCatalogFullSyncService: POSCatalogFullSyncServiceProtocol {
215212
startFullSyncCallCount += 1
216213
lastSyncSiteID = siteID
217214

218-
if let error = startFullSyncError {
215+
switch startFullSyncResult {
216+
case .success(let catalog):
217+
return catalog
218+
case .failure(let error):
219219
throw error
220220
}
221-
222-
return startFullSyncResult
223221
}
224222
}

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, grdbManager: ServiceLocator.grdbManager)
802+
return POSCatalogSyncCoordinator(fullSyncService: fullSyncService, grdbManager: ServiceLocator.grdbManager)
803803
}
804804

805805
func triggerPOSCatalogSyncIfNeeded(for siteID: Int64) async {

0 commit comments

Comments
 (0)