Skip to content

Commit 1166f87

Browse files
committed
Add a test case for regenerateCatalog parameter being passed to the catalog remote.
1 parent 4f183c1 commit 1166f87

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Modules/Tests/YosemiteTests/Mocks/MockPOSCatalogSyncRemote.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class MockPOSCatalogSyncRemote: POSCatalogSyncRemoteProtocol {
1818

1919
private(set) var lastIncrementalProductsModifiedAfter: Date?
2020
private(set) var lastIncrementalVariationsModifiedAfter: Date?
21+
private(set) var lastCatalogRequestForceGeneration: Bool?
2122

2223
// Fallback result when no specific page result is configured
2324
private let fallbackResult = PagedItems(items: [] as [POSProduct], hasMorePages: false, totalItems: 0)
@@ -132,6 +133,7 @@ final class MockPOSCatalogSyncRemote: POSCatalogSyncRemoteProtocol {
132133
// MARK: - Protocol Methods - Catalog API
133134

134135
func requestCatalogGeneration(for siteID: Int64, forceGeneration: Bool) async throws -> POSCatalogRequestResponse {
136+
lastCatalogRequestForceGeneration = forceGeneration
135137
switch catalogRequestResult {
136138
case .success(let response):
137139
return response

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,24 @@ struct POSCatalogFullSyncServiceTests {
265265
_ = try await sut.startFullSync(for: sampleSiteID)
266266
}
267267
}
268+
269+
@Test(arguments: [true, false])
270+
func startFullSync_with_catalog_API_passes_regenerateCatalog_to_remote(regenerateCatalog: Bool) async throws {
271+
// Given
272+
mockSyncRemote.catalogRequestResult = .success(.init(status: .complete, downloadURL: "https://example.com/catalog.json"))
273+
mockSyncRemote.catalogDownloadResult = .success(.init(products: [], variations: []))
274+
275+
let sut = POSCatalogFullSyncService(
276+
syncRemote: mockSyncRemote,
277+
batchSize: 2,
278+
persistenceService: mockPersistenceService,
279+
usesCatalogAPI: true
280+
)
281+
282+
// When
283+
_ = try await sut.startFullSync(for: sampleSiteID, regenerateCatalog: regenerateCatalog)
284+
285+
// Then
286+
#expect(mockSyncRemote.lastCatalogRequestForceGeneration == regenerateCatalog)
287+
}
268288
}

0 commit comments

Comments
 (0)