mirror of
https://github.com/bitwarden/android.git
synced 2026-04-28 20:08:27 -05:00
[PM-19831] Migrate ConfigService to network module (#4971)
This commit is contained in:
@@ -58,6 +58,7 @@ dependencies {
|
||||
testRuntimeOnly(libs.junit.platform.launcher)
|
||||
testImplementation(libs.junit.junit5)
|
||||
testImplementation(libs.junit.vintage)
|
||||
testImplementation(libs.kotlinx.coroutines.test)
|
||||
testImplementation(libs.mockk.mockk)
|
||||
testImplementation(libs.square.okhttp.mockwebserver)
|
||||
testImplementation(libs.square.turbine)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.bitwarden.network.service
|
||||
|
||||
import com.bitwarden.network.model.ConfigResponseJson
|
||||
|
||||
/**
|
||||
* Provides an API for querying config endpoints.
|
||||
*/
|
||||
interface ConfigService {
|
||||
|
||||
/**
|
||||
* Fetch app configuration.
|
||||
*/
|
||||
suspend fun getConfig(): Result<ConfigResponseJson>
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.bitwarden.network.service
|
||||
|
||||
import com.bitwarden.network.api.ConfigApi
|
||||
import com.bitwarden.network.model.ConfigResponseJson
|
||||
import com.bitwarden.network.util.toResult
|
||||
|
||||
/**
|
||||
* Default implementation of [ConfigService] for querying app configurations.
|
||||
*/
|
||||
// TODO [PM-19846] Make internal when dependents are migrated.
|
||||
class ConfigServiceImpl(private val configApi: ConfigApi) : ConfigService {
|
||||
override suspend fun getConfig(): Result<ConfigResponseJson> = configApi.getConfig().toResult()
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.bitwarden.network.service
|
||||
|
||||
import com.bitwarden.core.data.util.asSuccess
|
||||
import com.bitwarden.network.api.ConfigApi
|
||||
import com.bitwarden.network.base.BaseServiceTest
|
||||
import com.bitwarden.network.model.ConfigResponseJson
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import retrofit2.create
|
||||
|
||||
class ConfigServiceTest : BaseServiceTest() {
|
||||
|
||||
private val api: ConfigApi = retrofit.create()
|
||||
private val service = ConfigServiceImpl(api)
|
||||
|
||||
@Test
|
||||
fun `getConfig should call ConfigApi`() = runTest {
|
||||
server.enqueue(MockResponse().setBody(CONFIG_RESPONSE_JSON))
|
||||
assertEquals(CONFIG_RESPONSE.asSuccess(), service.getConfig())
|
||||
}
|
||||
}
|
||||
|
||||
private const val CONFIG_RESPONSE_JSON = """
|
||||
{
|
||||
"object": "config",
|
||||
"version": "1",
|
||||
"gitHash": "gitHash",
|
||||
"server": {
|
||||
"name": "default",
|
||||
"url": "url"
|
||||
},
|
||||
"environment": {
|
||||
"cloudRegion": "US",
|
||||
"vault": "vaultUrl",
|
||||
"api": "apiUrl",
|
||||
"identity": "identityUrl",
|
||||
"notifications": "notificationsUrl",
|
||||
"sso": "ssoUrl"
|
||||
},
|
||||
"featureStates": {
|
||||
"feature one": false
|
||||
}
|
||||
}
|
||||
"""
|
||||
private val CONFIG_RESPONSE = ConfigResponseJson(
|
||||
type = "config",
|
||||
version = "1",
|
||||
gitHash = "gitHash",
|
||||
server = ConfigResponseJson.ServerJson(
|
||||
name = "default",
|
||||
url = "url",
|
||||
),
|
||||
environment = ConfigResponseJson.EnvironmentJson(
|
||||
cloudRegion = "US",
|
||||
vaultUrl = "vaultUrl",
|
||||
apiUrl = "apiUrl",
|
||||
notificationsUrl = "notificationsUrl",
|
||||
identityUrl = "identityUrl",
|
||||
ssoUrl = "ssoUrl",
|
||||
),
|
||||
featureStates = mapOf(
|
||||
"feature one" to JsonPrimitive(false),
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user