Skip to content
Snippets Groups Projects
Unverified Commit cba9aed0 authored by Kolya Opahle's avatar Kolya Opahle Committed by GitHub
Browse files

Merge branch 'release/1.8.x' into fix/3770-warn-others-app-reset

parents 5b2187df 1b9e37c9
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ interface CWAConfig { ...@@ -11,7 +11,7 @@ interface CWAConfig {
val supportedCountries: List<String> val supportedCountries: List<String>
val appFeatures: AppFeaturesOuterClass.AppFeatures val appFeatures: List<AppFeaturesOuterClass.AppFeature>
interface Mapper : ConfigMapper<CWAConfig> interface Mapper : ConfigMapper<CWAConfig>
} }
package de.rki.coronawarnapp.appconfig.mapping package de.rki.coronawarnapp.appconfig.mapping
import androidx.annotation.VisibleForTesting
import dagger.Reusable import dagger.Reusable
import de.rki.coronawarnapp.appconfig.CWAConfig import de.rki.coronawarnapp.appconfig.CWAConfig
import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid.ApplicationConfigurationAndroid
import de.rki.coronawarnapp.server.protocols.internal.v2.AppFeaturesOuterClass import de.rki.coronawarnapp.server.protocols.internal.v2.AppFeaturesOuterClass
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@Reusable @Reusable
class CWAConfigMapper @Inject constructor() : CWAConfig.Mapper { class CWAConfigMapper @Inject constructor() : CWAConfig.Mapper {
override fun map(rawConfig: AppConfigAndroid.ApplicationConfigurationAndroid): CWAConfig { override fun map(rawConfig: ApplicationConfigurationAndroid): CWAConfig {
return CWAConfigContainer( return CWAConfigContainer(
latestVersionCode = rawConfig.latestVersionCode, latestVersionCode = rawConfig.latestVersionCode,
minVersionCode = rawConfig.minVersionCode, minVersionCode = rawConfig.minVersionCode,
supportedCountries = rawConfig.getMappedSupportedCountries(), supportedCountries = rawConfig.getMappedSupportedCountries(),
appFeatures = rawConfig.appFeatures appFeatures = rawConfig.mapAppFeatures()
) )
} }
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) private fun ApplicationConfigurationAndroid.getMappedSupportedCountries(): List<String> =
internal fun AppConfigAndroid.ApplicationConfigurationAndroid.getMappedSupportedCountries(): List<String> =
when { when {
supportedCountriesList == null -> emptyList() supportedCountriesList == null -> emptyList()
supportedCountriesList.size == 1 && !VALID_CC.matches(supportedCountriesList.single()) -> { supportedCountriesList.size == 1 && !VALID_CC.matches(supportedCountriesList.single()) -> {
...@@ -30,11 +28,22 @@ class CWAConfigMapper @Inject constructor() : CWAConfig.Mapper { ...@@ -30,11 +28,22 @@ class CWAConfigMapper @Inject constructor() : CWAConfig.Mapper {
else -> supportedCountriesList else -> supportedCountriesList
} }
private fun ApplicationConfigurationAndroid.mapAppFeatures(): List<AppFeaturesOuterClass.AppFeature> =
if (hasAppFeatures()) {
val parsedFeatures = mutableListOf<AppFeaturesOuterClass.AppFeature>()
for (index in 0 until appFeatures.appFeaturesCount) {
parsedFeatures.add(appFeatures.getAppFeatures(index))
}
parsedFeatures
} else {
emptyList()
}
data class CWAConfigContainer( data class CWAConfigContainer(
override val latestVersionCode: Long, override val latestVersionCode: Long,
override val minVersionCode: Long, override val minVersionCode: Long,
override val supportedCountries: List<String>, override val supportedCountries: List<String>,
override val appFeatures: AppFeaturesOuterClass.AppFeatures override val appFeatures: List<AppFeaturesOuterClass.AppFeature>
) : CWAConfig ) : CWAConfig
companion object { companion object {
......
package de.rki.coronawarnapp.appconfig.mapping package de.rki.coronawarnapp.appconfig.mapping
import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid
import de.rki.coronawarnapp.server.protocols.internal.v2.AppFeaturesOuterClass
import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import testhelpers.BaseTest import testhelpers.BaseTest
...@@ -45,4 +46,27 @@ class CWAConfigMapperTest : BaseTest() { ...@@ -45,4 +46,27 @@ class CWAConfigMapperTest : BaseTest() {
this.supportedCountries shouldBe emptyList() this.supportedCountries shouldBe emptyList()
} }
} }
@Test
fun `app features are mapped`() {
val rawConfig = AppConfigAndroid.ApplicationConfigurationAndroid.newBuilder()
.setAppFeatures(
AppFeaturesOuterClass.AppFeatures.newBuilder().apply {
addAppFeatures(AppFeaturesOuterClass.AppFeature.newBuilder().apply { }.build())
}
)
.build()
createInstance().map(rawConfig).apply {
appFeatures.size shouldBe 1
}
}
@Test
fun `app features being empty are handled`() {
val rawConfig = AppConfigAndroid.ApplicationConfigurationAndroid.newBuilder()
.build()
createInstance().map(rawConfig).apply {
appFeatures shouldBe emptyList()
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment