Skip to content

Commit 37af6a1

Browse files
authored
[PM-23710] Fixed logic to getServerConfig and added new test on Authenticator (#5518)
1 parent 557c5b4 commit 37af6a1

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

data/src/main/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryImpl.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff 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

data/src/test/kotlin/com/bitwarden/data/repository/ServerConfigRepositoryTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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

124148
private val SERVER_CONFIG = ServerConfig(

0 commit comments

Comments
 (0)