From 38c2379c171095e9238d2034264fa280e5062e6d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:57:25 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20update=20api=20version=20on=20startup=20?= =?UTF-8?q?[WPB-14730]=20=F0=9F=8D=92=20(#3701)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Żerko Co-authored-by: Yamil Medina --- .../wire/android/ui/WireActivityViewModel.kt | 2 +- .../wire/android/ui/home/AppSyncViewModel.kt | 5 ++++- .../android/ui/home/AppSyncViewModelTest.kt | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt index 624b6aa74a5..359291c8f48 100644 --- a/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt @@ -122,7 +122,7 @@ class WireActivityViewModel @Inject constructor( private val observeScreenshotCensoringConfigUseCaseProviderFactory: ObserveScreenshotCensoringConfigUseCaseProvider.Factory, private val globalDataStore: Lazy, private val observeIfE2EIRequiredDuringLoginUseCaseProviderFactory: ObserveIfE2EIRequiredDuringLoginUseCaseProvider.Factory, - private val workManager: Lazy + private val workManager: Lazy, ) : ViewModel() { var globalAppState: GlobalAppState by mutableStateOf(GlobalAppState()) diff --git a/app/src/main/kotlin/com/wire/android/ui/home/AppSyncViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/AppSyncViewModel.kt index 7988a39e302..cf9839278b4 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/AppSyncViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/AppSyncViewModel.kt @@ -23,6 +23,7 @@ import com.wire.android.appLogger import com.wire.kalium.logic.feature.e2ei.SyncCertificateRevocationListUseCase import com.wire.kalium.logic.feature.e2ei.usecase.ObserveCertificateRevocationForSelfClientUseCase import com.wire.kalium.logic.feature.featureConfig.FeatureFlagsSyncWorker +import com.wire.kalium.logic.feature.server.UpdateApiVersionsUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Job import kotlinx.coroutines.joinAll @@ -38,6 +39,7 @@ class AppSyncViewModel @Inject constructor( private val syncCertificateRevocationListUseCase: SyncCertificateRevocationListUseCase, private val observeCertificateRevocationForSelfClient: ObserveCertificateRevocationForSelfClientUseCase, private val featureFlagsSyncWorker: FeatureFlagsSyncWorker, + private val updateApiVersions: UpdateApiVersionsUseCase ) : ViewModel() { private val minIntervalBetweenPulls: Duration = MIN_INTERVAL_BETWEEN_PULLS @@ -73,7 +75,8 @@ class AppSyncViewModel @Inject constructor( listOf( viewModelScope.launch { syncCertificateRevocationListUseCase() }, viewModelScope.launch { featureFlagsSyncWorker.execute() }, - viewModelScope.launch { observeCertificateRevocationForSelfClient.invoke() } + viewModelScope.launch { observeCertificateRevocationForSelfClient.invoke() }, + viewModelScope.launch { updateApiVersions() }, ).joinAll() } catch (e: Exception) { appLogger.e("Error while syncing app config", e) diff --git a/app/src/test/kotlin/com/wire/android/ui/home/AppSyncViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/AppSyncViewModelTest.kt index 0d0e5e20ffc..531731fc301 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/AppSyncViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/AppSyncViewModelTest.kt @@ -21,6 +21,7 @@ import com.wire.android.config.CoroutineTestExtension import com.wire.kalium.logic.feature.e2ei.SyncCertificateRevocationListUseCase import com.wire.kalium.logic.feature.e2ei.usecase.ObserveCertificateRevocationForSelfClientUseCase import com.wire.kalium.logic.feature.featureConfig.FeatureFlagsSyncWorker +import com.wire.kalium.logic.feature.server.UpdateApiVersionsUseCase import io.mockk.MockKAnnotations import io.mockk.coEvery import io.mockk.coVerify @@ -40,6 +41,7 @@ class AppSyncViewModelTest { withObserveCertificateRevocationForSelfClient() withFeatureFlagsSyncWorker() withSyncCertificateRevocationListUseCase() + withUpdateApiVersions() } viewModel.startSyncingAppConfig() @@ -48,6 +50,7 @@ class AppSyncViewModelTest { coVerify { arrangement.observeCertificateRevocationForSelfClient.invoke() } coVerify { arrangement.syncCertificateRevocationListUseCase.invoke() } coVerify { arrangement.featureFlagsSyncWorker.execute() } + coVerify { arrangement.updateApiVersions() } } @Test @@ -56,6 +59,7 @@ class AppSyncViewModelTest { withObserveCertificateRevocationForSelfClient(1000) withFeatureFlagsSyncWorker(1000) withSyncCertificateRevocationListUseCase(1000) + withUpdateApiVersions(1000) } viewModel.startSyncingAppConfig() @@ -66,6 +70,7 @@ class AppSyncViewModelTest { coVerify(exactly = 1) { arrangement.observeCertificateRevocationForSelfClient.invoke() } coVerify(exactly = 1) { arrangement.syncCertificateRevocationListUseCase.invoke() } coVerify(exactly = 1) { arrangement.featureFlagsSyncWorker.execute() } + coVerify(exactly = 1) { arrangement.updateApiVersions() } } private class Arrangement { @@ -79,6 +84,9 @@ class AppSyncViewModelTest { @MockK lateinit var featureFlagsSyncWorker: FeatureFlagsSyncWorker + @MockK + lateinit var updateApiVersions: UpdateApiVersionsUseCase + init { MockKAnnotations.init(this) } @@ -86,7 +94,8 @@ class AppSyncViewModelTest { private val viewModel = AppSyncViewModel( syncCertificateRevocationListUseCase, observeCertificateRevocationForSelfClient, - featureFlagsSyncWorker + featureFlagsSyncWorker, + updateApiVersions ) @OptIn(InternalCoroutinesApi::class) @@ -108,6 +117,12 @@ class AppSyncViewModelTest { } } + fun withUpdateApiVersions(delayMs: Long = 0) { + coEvery { updateApiVersions() } coAnswers { + delay(delayMs) + } + } + fun arrange(block: Arrangement.() -> Unit) = apply(block).let { this to viewModel }