File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed
main/kotlin/com/bitwarden/data/repository
test/kotlin/com/bitwarden/data/repository Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -35,11 +35,11 @@ internal class ServerConfigRepositoryImpl(
3535 override suspend fun getServerConfig (forceRefresh : Boolean ): ServerConfig ? {
3636 val localConfig = configDiskSource.serverConfig
3737 val needsRefresh = localConfig == null ||
38- Instant
39- .ofEpochMilli(localConfig.lastSync)
40- .isAfter(
41- clock.instant() .plusSeconds(MINIMUM_CONFIG_SYNC_INTERVAL_SEC ),
42- )
38+ clock.instant().isAfter(
39+ Instant
40+ .ofEpochMilli(localConfig.lastSync)
41+ .plusSeconds(MINIMUM_CONFIG_SYNC_INTERVAL_SEC ),
42+ )
4343
4444 if (needsRefresh || forceRefresh) {
4545 configService
Original file line number Diff line number Diff line change @@ -119,6 +119,30 @@ class ServerConfigRepositoryTest {
119119 assertEquals(fakeConfigDiskSource.serverConfig, awaitItem())
120120 }
121121 }
122+
123+ @Suppress(" MaxLineLength" )
124+ @Test
125+ fun `serverConfigStateFlow should fetch new server configurations when minimum config sync interval is reached ` () =
126+ runTest {
127+
128+ val testConfig = SERVER_CONFIG .copy(
129+ lastSync = fixedClock.instant().minusSeconds(60 * 60 + 1 ).toEpochMilli(),
130+ serverData = CONFIG_RESPONSE_JSON .copy(
131+ version = " old version!!" ,
132+ ),
133+ )
134+ fakeConfigDiskSource.serverConfig = testConfig
135+
136+ coEvery {
137+ configService.getConfig()
138+ } returns CONFIG_RESPONSE_JSON .asSuccess()
139+
140+ repository.getServerConfig(forceRefresh = false )
141+
142+ repository.serverConfigStateFlow.test {
143+ assertNotEquals(testConfig, awaitItem())
144+ }
145+ }
122146}
123147
124148private val SERVER_CONFIG = ServerConfig (
You can’t perform that action at this time.
0 commit comments