mirror of
https://github.com/bitwarden/android.git
synced 2026-03-24 07:11:53 -05:00
[PM-23710] Fixed logic to getServerConfig and added new test on Authenticator (#5518)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user