diff --git a/data/src/main/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryImpl.kt b/data/src/main/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryImpl.kt index 20e0b689a0..535134c314 100644 --- a/data/src/main/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryImpl.kt +++ b/data/src/main/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryImpl.kt @@ -35,11 +35,11 @@ internal class ServerConfigRepositoryImpl( override suspend fun getServerConfig(forceRefresh: Boolean): ServerConfig? { val localConfig = configDiskSource.serverConfig val needsRefresh = localConfig == null || - Instant - .ofEpochMilli(localConfig.lastSync) - .isAfter( - clock.instant().plusSeconds(MINIMUM_CONFIG_SYNC_INTERVAL_SEC), - ) + clock.instant().isAfter( + Instant + .ofEpochMilli(localConfig.lastSync) + .plusSeconds(MINIMUM_CONFIG_SYNC_INTERVAL_SEC), + ) if (needsRefresh || forceRefresh) { configService diff --git a/data/src/test/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryTest.kt b/data/src/test/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryTest.kt index 8fb6e6306f..8b5252741e 100644 --- a/data/src/test/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryTest.kt +++ b/data/src/test/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryTest.kt @@ -119,6 +119,30 @@ class ServerConfigRepositoryTest { assertEquals(fakeConfigDiskSource.serverConfig, awaitItem()) } } + + @Suppress("MaxLineLength") + @Test + fun `serverConfigStateFlow should fetch new server configurations when minimum config sync interval is reached `() = + runTest { + + val testConfig = SERVER_CONFIG.copy( + lastSync = fixedClock.instant().minusSeconds(60 * 60 + 1).toEpochMilli(), + serverData = CONFIG_RESPONSE_JSON.copy( + version = "old version!!", + ), + ) + fakeConfigDiskSource.serverConfig = testConfig + + coEvery { + configService.getConfig() + } returns CONFIG_RESPONSE_JSON.asSuccess() + + repository.getServerConfig(forceRefresh = false) + + repository.serverConfigStateFlow.test { + assertNotEquals(testConfig, awaitItem()) + } + } } private val SERVER_CONFIG = ServerConfig(