Skip to content

Commit

Permalink
Fix build 💚
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Dec 6, 2024
1 parent fe7297e commit 582abec
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand All @@ -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() }
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -425,7 +435,11 @@ class ConfigurationRegistryTest : RobolectricTest() {
"test-list-id",
createdResourceArgumentSlot.filterIsInstance<ListResource>().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") }
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ constructor(
return@launch
}

// Save composition
defaultRepository.createRemote(false, compositionResource)

compositionResource
.retrieveCompositionSections()
.asSequence()
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 582abec

Please sign in to comment.