From 582abec9688ab6bea6e8dc16ffd92a2a9a207a27 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Fri, 6 Dec 2024 15:15:02 +0300 Subject: [PATCH] =?UTF-8?q?Fix=20build=20=F0=9F=92=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfigurationRegistryTest.kt | 38 +++++++++---- .../ui/appsetting/AppSettingViewModel.kt | 5 +- .../ui/appsetting/AppSettingViewModelTest.kt | 53 +++++++++---------- 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistryTest.kt b/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistryTest.kt index 6d2a0debdba..b08d672b4c1 100644 --- a/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistryTest.kt +++ b/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistryTest.kt @@ -275,7 +275,9 @@ class ConfigurationRegistryTest : RobolectricTest() { val appId = "theAppId" configRegistry.sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, appId) coEvery { - fhirResourceDataSource.getResource("Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") + fhirResourceDataSource.getResource( + "Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) } returns Bundle().apply { addEntry().resource = Composition() } runTest { configRegistry.fetchNonWorkflowConfigResources() } @@ -298,7 +300,9 @@ class ConfigurationRegistryTest : RobolectricTest() { ) configRegistry.sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, appId) coEvery { - fhirResourceDataSource.getResource("Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") + fhirResourceDataSource.getResource( + "Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) } returns Bundle().apply { addEntry().resource = composition } runTest { configRegistry.fetchNonWorkflowConfigResources() } @@ -327,7 +331,9 @@ class ConfigurationRegistryTest : RobolectricTest() { ) coEvery { fhirResourceDataSource.post(any(), any()) } returns Bundle() coEvery { - fhirResourceDataSource.getResource("Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") + fhirResourceDataSource.getResource( + "Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) } returns Bundle().apply { addEntry().resource = composition } runTest { @@ -407,11 +413,15 @@ class ConfigurationRegistryTest : RobolectricTest() { bundle coEvery { - fhirResourceDataSource.getResource("$resourceKey?_id=$resourceId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") + fhirResourceDataSource.getResource( + "$resourceKey?_id=$resourceId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) } returns bundle coEvery { fhirResourceDataSource.getResource(any()) } returns bundle coEvery { - fhirResourceDataSource.getResource("Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") + fhirResourceDataSource.getResource( + "Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) } returns Bundle().apply { addEntry().resource = composition } configRegistry.fhirEngine.create(composition) @@ -425,7 +435,11 @@ class ConfigurationRegistryTest : RobolectricTest() { "test-list-id", createdResourceArgumentSlot.filterIsInstance().first().id, ) - coVerify { fhirResourceDataSource.getResource("$resourceKey?_id=$resourceId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") } + coVerify { + fhirResourceDataSource.getResource( + "$resourceKey?_id=$resourceId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) + } coEvery { fhirResourceDataSource.getResource("$focusReference?_id=$focusReference") } } @@ -814,7 +828,9 @@ class ConfigurationRegistryTest : RobolectricTest() { runBlocking { fhirEngine.create(composition) } coEvery { - fhirResourceDataSource.getResource("Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") + fhirResourceDataSource.getResource( + "Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) } returns Bundle().apply { addEntry().resource = composition } coEvery { @@ -869,7 +885,9 @@ class ConfigurationRegistryTest : RobolectricTest() { fhirEngine.create(composition) coEvery { - fhirResourceDataSource.getResource("Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") + fhirResourceDataSource.getResource( + "Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) } returns Bundle().apply { addEntry().resource = composition } coEvery { @@ -961,7 +979,9 @@ class ConfigurationRegistryTest : RobolectricTest() { fhirEngine.create(composition) coEvery { - fhirResourceDataSource.getResource("Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}") + fhirResourceDataSource.getResource( + "Composition?identifier=theAppId&_count=${ConfigurationRegistry.DEFAULT_COUNT}", + ) } returns Bundle().apply { addEntry().resource = composition } coEvery { diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/appsetting/AppSettingViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/appsetting/AppSettingViewModel.kt index 74f2f62ae0b..ed8fb9f6246 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/appsetting/AppSettingViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/appsetting/AppSettingViewModel.kt @@ -150,6 +150,9 @@ constructor( return@launch } + // Save composition + defaultRepository.createRemote(false, compositionResource) + compositionResource .retrieveCompositionSections() .asSequence() @@ -192,8 +195,6 @@ constructor( } } - // Save composition after fetching all the referenced section resources - defaultRepository.createRemote(false, compositionResource) Timber.d("Done fetching application configurations remotely") loadConfigurations(context) } catch (unknownHostException: UnknownHostException) { diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/appsetting/AppSettingViewModelTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/appsetting/AppSettingViewModelTest.kt index 069e9c75430..9f7be91cfa7 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/appsetting/AppSettingViewModelTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/appsetting/AppSettingViewModelTest.kt @@ -34,9 +34,7 @@ import io.mockk.verify import java.net.UnknownHostException import java.nio.charset.StandardCharsets import javax.inject.Inject -import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody @@ -130,39 +128,38 @@ class AppSettingViewModelTest : RobolectricTest() { } @Test - fun testFetchConfigurations() = - runTest(timeout = 90.seconds, context = UnconfinedTestDispatcher()) { - val appId = "test_app_id" - appSettingViewModel.onApplicationIdChanged(appId) + fun testFetchConfigurations() = runBlocking { + val appId = "test_app_id" + appSettingViewModel.onApplicationIdChanged(appId) - coEvery { - appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any()) - } returns - Composition().apply { - addSection().apply { this.focus = Reference().apply { reference = "Binary/123" } } - } + coEvery { + appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any()) + } returns + Composition().apply { + addSection().apply { this.focus = Reference().apply { reference = "Binary/123" } } + } - coEvery { - appSettingViewModel.configurationRegistry.loadConfigurations(any(), any(), any()) - } just runs + coEvery { + appSettingViewModel.configurationRegistry.loadConfigurations(any(), any(), any()) + } just runs - coEvery { appSettingViewModel.fhirResourceDataSource.post(requestBody = any()) } returns - Bundle() + coEvery { appSettingViewModel.fhirResourceDataSource.post(requestBody = any()) } returns + Bundle() - coEvery { appSettingViewModel.defaultRepository.createRemote(any(), any()) } just runs + coEvery { appSettingViewModel.defaultRepository.createRemote(any(), any()) } just runs - coEvery { - appSettingViewModel.configurationRegistry.fetchRemoteImplementationGuideByAppId( - appId, - QuestBuildConfig.VERSION_CODE, - ) - } returns null + coEvery { + appSettingViewModel.configurationRegistry.fetchRemoteImplementationGuideByAppId( + appId, + QuestBuildConfig.VERSION_CODE, + ) + } returns null - appSettingViewModel.fetchConfigurations(context) + appSettingViewModel.fetchConfigurations(context) - coVerify { appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any()) } - coVerify { appSettingViewModel.defaultRepository.createRemote(any(), any()) } - } + coVerify { appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any()) } + coVerify { appSettingViewModel.defaultRepository.createRemote(any(), any()) } + } @Test(expected = HttpException::class) fun testFetchConfigurationsThrowsHttpExceptionWithStatusCodeBetween400And503() = runTest {