Skip to content

Commit

Permalink
adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
mpbw2 committed Oct 3, 2024
1 parent 95dfe5e commit ecf6407
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FeatureFlagManagerImpl(
get() = mapOf(
CIPHER_KEY_ENCRYPTION_KEY to
isServerVersionAtLeast(
serverConfigRepository.getLocalServerConfig(),
serverConfigRepository.serverConfigStateFlow.value,
CIPHER_KEY_ENC_MIN_SERVER_VERSION,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,4 @@ interface ServerConfigRepository {
* updates the values using server side data.
*/
suspend fun getServerConfig(forceRefresh: Boolean): ServerConfig?

/**
* Gets the state [ServerConfig] synchronously from local storage only.
*/
fun getLocalServerConfig(): ServerConfig?
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ class ServerConfigRepositoryImpl(
return localConfig
}

override fun getLocalServerConfig(): ServerConfig? {
return configDiskSource.serverConfig
}

private companion object {
private const val MINIMUM_CONFIG_SYNC_INTERVAL_SEC: Long = 60 * 60
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ private const val SUFFIX_SEPARATOR = "-"
/**
* Checks if the server version is greater than another provided version, returns true if it is.
*/
fun isServerVersionAtLeast(serverConfig: ServerConfig?, version: String): Boolean {
fun isServerVersionAtLeast(serverConfig: ServerConfig?, version: String?): Boolean {
val serverVersion = serverConfig
?.serverData
?.version

if (serverVersion.isNullOrEmpty() || version.isNullOrEmpty()) {
return false
}

val serverVersionParts = getVersionComponents(serverVersion)
val otherVersionParts = getVersionComponents(version)

if (serverVersionParts == null || otherVersionParts == null) {
if (serverVersionParts.isNullOrEmpty() || otherVersionParts.isNullOrEmpty()) {
return false
}

Expand All @@ -33,7 +37,9 @@ private const val SUFFIX_SEPARATOR = "-"
}
}

return true // Versions are equal

// Versions are equal
return true
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FeatureFlagManagerTest {
fun `server version is at least supplied version`() {
val result =
isServerVersionAtLeast(
fakeServerConfigRepository.getLocalServerConfig(),
fakeServerConfigRepository.serverConfigStateFlow.value,
"2024.2.0",
)

Expand All @@ -50,14 +50,37 @@ class FeatureFlagManagerTest {
fun `server version is not at least supplied version`() {
val result =
isServerVersionAtLeast(
fakeServerConfigRepository.getLocalServerConfig(),
fakeServerConfigRepository.serverConfigStateFlow.value,
"2024.12.0-suffix",
)

// This relies on the fake server version being "2024.7.0"
assertFalse(result)
}

@Test
fun `server version is the same as supplied version`() {
val result =
isServerVersionAtLeast(
fakeServerConfigRepository.serverConfigStateFlow.value,
"2024.7.0",
)

// This relies on the fake server version being "2024.7.0"
assertTrue(result)
}

@Test
fun `server version is not the same as blank supplied version`() {
val result =
isServerVersionAtLeast(
fakeServerConfigRepository.serverConfigStateFlow.value,
"",
)

assertFalse(result)
}

@Test
fun `ServerConfigRepository flow with value should trigger new flags`() = runTest {
fakeServerConfigRepository.serverConfigValue = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class FakeServerConfigRepository : ServerConfigRepository {
return serverConfigValue
}

override fun getLocalServerConfig(): ServerConfig? {
return SERVER_CONFIG
}

override val serverConfigStateFlow: StateFlow<ServerConfig?>
get() = mutableServerConfigFlow
}
Expand Down

0 comments on commit ecf6407

Please sign in to comment.