BIT-2080: Sync time updated when sync is not needed (#1144)

This commit is contained in:
David Perez 2024-03-14 11:17:50 -05:00 committed by Álison Fernandes
parent 226b62a1cd
commit 1a41fcb5c8
2 changed files with 13 additions and 5 deletions

View file

@ -331,6 +331,10 @@ class VaultRepositoryImpl(
if (serverRevisionDate < lastSyncInstant) {
// We can skip the actual sync call if there is no new data
vaultDiskSource.resyncVaultData(userId)
settingsDiskSource.storeLastSyncTime(
userId = userId,
lastSyncTime = clock.instant(),
)
return@launch
}
},
@ -369,7 +373,10 @@ class VaultRepositoryImpl(
userId = userId,
policies = syncResponse.policies,
)
settingsDiskSource.storeLastSyncTime(userId = userId, clock.instant())
settingsDiskSource.storeLastSyncTime(
userId = userId,
lastSyncTime = clock.instant(),
)
vaultDiskSource.replaceVaultData(userId = userId, vault = syncResponse)
},
onFailure = { throwable ->

View file

@ -159,9 +159,8 @@ class VaultRepositoryTest {
private val fileManager: FileManager = mockk()
private val fakeAuthDiskSource = FakeAuthDiskSource()
private val settingsDiskSource = mockk<SettingsDiskSource> {
every {
getLastSyncTime(userId = any())
} returns clock.instant()
every { getLastSyncTime(userId = any()) } returns clock.instant()
every { storeLastSyncTime(userId = any(), lastSyncTime = any()) } just runs
}
private val syncService: SyncService = mockk {
coEvery {
@ -965,13 +964,15 @@ class VaultRepositoryTest {
fun `sync when the last sync time is more recent than the revision date should not sync `() {
val userId = "mockId-1"
fakeAuthDiskSource.userState = MOCK_USER_STATE
coEvery { syncService.sync() } just awaits
every {
settingsDiskSource.getLastSyncTime(userId = userId)
} returns clock.instant().plus(2, ChronoUnit.MINUTES)
vaultRepository.sync()
verify(exactly = 1) {
settingsDiskSource.storeLastSyncTime(userId = userId, lastSyncTime = clock.instant())
}
coVerify(exactly = 0) { syncService.sync() }
}