Skip to content

Commit bf08946

Browse files
committed
Update tests to include site in database
1 parent 0a61ec4 commit bf08946

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,23 @@ struct POSCatalogSyncCoordinatorTests {
7777

7878
// MARK: - Should Sync Decision Tests
7979

80-
@Test func shouldPerformFullSync_returns_true_when_no_previous_sync() {
81-
// Given - no previous sync date stored
80+
@Test func shouldPerformFullSync_site_not_in_database_with_no_sync_history() {
81+
// Given - site doesn't exist in database AND has no sync history
8282
mockSettingsStore.storedDates = [:]
83+
// Note: NOT creating site in database
84+
85+
// When
86+
let shouldSync = sut.shouldPerformFullSync(for: sampleSiteID, maxAge: 60 * 60)
87+
88+
// Then - should sync because site doesn't exist in database
89+
#expect(shouldSync == true)
90+
}
91+
92+
@Test func shouldPerformFullSync_returns_true_when_no_previous_sync() throws {
93+
// Given - no previous sync date stored, but site exists in database
94+
// This is much less likely to happen, but could help at a migration point
95+
mockSettingsStore.storedDates = [:]
96+
try createSiteInDatabase(siteID: sampleSiteID)
8397

8498
// When
8599
let shouldSync = sut.shouldPerformFullSync(for: sampleSiteID, maxAge: 3600)
@@ -89,10 +103,11 @@ struct POSCatalogSyncCoordinatorTests {
89103
#expect(mockSettingsStore.getPOSLastFullSyncDateCallCount == 1)
90104
}
91105

92-
@Test func shouldPerformFullSync_returns_true_when_sync_is_stale() {
93-
// Given - previous sync was 2 hours ago
106+
@Test func shouldPerformFullSync_returns_true_when_sync_is_stale() throws {
107+
// Given - previous sync was 2 hours ago, and site exists in database
94108
let twoHoursAgo = Date().addingTimeInterval(-2 * 60 * 60)
95109
mockSettingsStore.storedDates[sampleSiteID] = twoHoursAgo
110+
try createSiteInDatabase(siteID: sampleSiteID)
96111

97112
// When - max age is 1 hour
98113
let shouldSync = sut.shouldPerformFullSync(for: sampleSiteID, maxAge: 60 * 60)
@@ -101,10 +116,11 @@ struct POSCatalogSyncCoordinatorTests {
101116
#expect(shouldSync == true)
102117
}
103118

104-
@Test func shouldPerformFullSync_returns_false_when_sync_is_fresh() {
105-
// Given - previous sync was 30 minutes ago
119+
@Test func shouldPerformFullSync_returns_false_when_sync_is_fresh() throws {
120+
// Given - previous sync was 30 minutes ago, and site exists in database
106121
let thirtyMinutesAgo = Date().addingTimeInterval(-30 * 60)
107122
mockSettingsStore.storedDates[sampleSiteID] = thirtyMinutesAgo
123+
try createSiteInDatabase(siteID: sampleSiteID)
108124

109125
// When - max age is 1 hour
110126
let shouldSync = sut.shouldPerformFullSync(for: sampleSiteID, maxAge: 60 * 60)
@@ -113,7 +129,7 @@ struct POSCatalogSyncCoordinatorTests {
113129
#expect(shouldSync == false)
114130
}
115131

116-
@Test func shouldPerformFullSync_handles_different_sites_independently() {
132+
@Test func shouldPerformFullSync_handles_different_sites_independently() throws {
117133
// Given
118134
let siteA: Int64 = 123
119135
let siteB: Int64 = 456
@@ -122,6 +138,10 @@ struct POSCatalogSyncCoordinatorTests {
122138
mockSettingsStore.storedDates[siteA] = oneHourAgo // Has previous sync
123139
// siteB has no previous sync
124140

141+
// Create both sites in database to test timing logic
142+
try createSiteInDatabase(siteID: siteA)
143+
try createSiteInDatabase(siteID: siteB)
144+
125145
// When
126146
let shouldSyncA = sut.shouldPerformFullSync(for: siteA, maxAge: 2 * 60 * 60) // 2 hours
127147
let shouldSyncB = sut.shouldPerformFullSync(for: siteB, maxAge: 2 * 60 * 60) // 2 hours
@@ -132,7 +152,7 @@ struct POSCatalogSyncCoordinatorTests {
132152
}
133153

134154
@Test func shouldPerformFullSync_with_zero_maxAge_always_returns_true() throws {
135-
// Given - previous sync was just now
155+
// Given - previous sync was just now, and site exists in database
136156
let justNow = Date()
137157
mockSettingsStore.storedDates[sampleSiteID] = justNow
138158
try createSiteInDatabase(siteID: sampleSiteID)

0 commit comments

Comments
 (0)