Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ keystore.properties
gradle.properties

/sentry.properties
.kotlin/
quest/echis/
quest/echisSupervisor/
4 changes: 2 additions & 2 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ allprojects {
mavenLocal()
google()
mavenCentral()
maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots")
// Old OSSRH repos removed - service was sunset June 30, 2025
// See: https://central.sonatype.org/pages/ossrh-eol/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested publishing some artifacts and make sure this url works?

maven(url = "https://repository.liferay.com/nexus/content/repositories/public")
maven(url = "https://central.sonatype.com/repository/maven-snapshots")
apply(plugin = "org.owasp.dependencycheck")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ constructor(
*/
@Throws(UnknownHostException::class, HttpException::class)
suspend fun fetchNonWorkflowConfigResources() {
// Skip remote fetch when using /debug mode - resources are loaded from assets
// Check directly for /debug suffix in app ID, regardless of build variant
val appId = sharedPreferencesHelper.retrieveApplicationId()?.trim()
if (appId?.endsWith(DEBUG_SUFFIX, ignoreCase = true) == true) {
Timber.d("Skipping remote config fetch - app ID '$appId' has /debug suffix, using local assets")
return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this optional/configurable?

Comment on lines +444 to +447
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality is unnecessary.

  1. The current functionality already allows overriding of resources from the /resources folder/assets without the need to bypass remote configs.
  2. Introducing this feature means you'll have to provide all resources, as opposed to the current optional requirement.

}
Timber.d("Triggered fetching application configurations remotely")
configCacheMap.clear()
sharedPreferencesHelper.read(SharedPreferenceKey.APP_ID.name, null)?.let { appId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1305,4 +1305,106 @@ class ConfigurationRegistryTest : RobolectricTest() {
val savedTimestamp = configRegistry.sharedPreferencesHelper.read(expectedKey, "")
assertFalse(savedTimestamp.isNullOrEmpty())
}

@Test
fun `fetchNonWorkflowConfigResources() should skip remote fetch when appId has debug suffix`() =
runTest {
// Given: App ID with /debug suffix
val appId = "echis/debug"
sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, appId)

// When: fetchNonWorkflowConfigResources is called
configRegistry.fetchNonWorkflowConfigResources()

// Then: Should NOT fetch from remote (no calls to fetchRemoteCompositionByAppId)
coVerify(exactly = 0) { configRegistry.fetchRemoteCompositionByAppId(any()) }
// And configCacheMap should remain empty (no remote configs loaded)
assertTrue(configRegistry.configCacheMap.isEmpty())
}

@Test
fun `fetchNonWorkflowConfigResources() should skip remote fetch when appId has DEBUG suffix uppercase`() =
runTest {
// Given: App ID with /DEBUG suffix (uppercase)
val appId = "echis/DEBUG"
sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, appId)

// When: fetchNonWorkflowConfigResources is called
configRegistry.fetchNonWorkflowConfigResources()

// Then: Should NOT fetch from remote (case-insensitive check)
coVerify(exactly = 0) { configRegistry.fetchRemoteCompositionByAppId(any()) }
}

@Test
fun `fetchNonWorkflowConfigResources() should fetch from remote when appId has no debug suffix`() =
runTest {
// Given: App ID without /debug suffix
val appId = "echis"
sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, appId)

val composition =
Composition().apply {
identifier = Identifier().setValue(appId)
addSection().apply {
focus =
Reference().apply {
reference = "Binary/test-config"
identifier = Identifier().setValue("application")
}
}
}

coEvery { configRegistry.fetchRemoteCompositionByAppId(appId) } returns composition
coEvery { fhirResourceDataSource.getResource(any()) } returns Bundle()
coEvery { fhirEngine.get<Binary>(any()) } returns
Binary().apply {
id = "test-config"
content = """{"appId":"echis"}""".toByteArray()
}

// When: fetchNonWorkflowConfigResources is called
configRegistry.fetchNonWorkflowConfigResources()

// Then: Should fetch from remote
coVerify { configRegistry.fetchRemoteCompositionByAppId(appId) }
}

@Test
fun `fetchNonWorkflowConfigResources() should skip when appId is null`() = runTest {
// Given: No App ID set
sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, null)

// When: fetchNonWorkflowConfigResources is called
configRegistry.fetchNonWorkflowConfigResources()

// Then: Should NOT fetch from remote
coVerify(exactly = 0) { configRegistry.fetchRemoteCompositionByAppId(any()) }
}

@Test
fun `fetchNonWorkflowConfigResources() should skip when appId is empty`() = runTest {
// Given: Empty App ID
sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, "")

// When: fetchNonWorkflowConfigResources is called
configRegistry.fetchNonWorkflowConfigResources()

// Then: Should NOT fetch from remote
coVerify(exactly = 0) { configRegistry.fetchRemoteCompositionByAppId(any()) }
}

@Test
fun `fetchNonWorkflowConfigResources() should handle appId with whitespace and debug suffix`() =
runTest {
// Given: App ID with whitespace and /debug suffix
val appId = " echis/debug "
sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, appId)

// When: fetchNonWorkflowConfigResources is called
configRegistry.fetchNonWorkflowConfigResources()

// Then: Should trim and detect debug suffix, skipping remote fetch
coVerify(exactly = 0) { configRegistry.fetchRemoteCompositionByAppId(any()) }
}
}
2 changes: 1 addition & 1 deletion android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ kotlinx-coroutines = "1.9.0"
kotlinx-serialization-json = "1.6.3"
kt3k-coveralls-ver="2.12.0"
ktlint = "0.50.0"
kujaku-library = "0.10.8-SNAPSHOT"
kujaku-library = "0.9.0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how big are the differences between 0.10.8 with 0.9.0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but 0.10.8 is not working.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a downgrade. Are we able to trace where 0.10.8 was published from? We could republish an update from that

kujaku-mapbox-sdk-turf = "7.2.0"
leakcanary-android = "2.10"
lifecycle= "2.8.7"
Expand Down
10 changes: 2 additions & 8 deletions android/quest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ sonar {

android {
compileSdk = BuildConfigs.compileSdk
ndkVersion = "27.2.12479018"

val buildDate = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(Date())

Expand Down Expand Up @@ -269,14 +270,7 @@ android {
dimension = "apps"
applicationId = "ug.go.health.echis"
versionNameSuffix = "-echis"
manifestPlaceholders["appLabel"] = "MOH UG eCHIS"
}

create("echisSupervisor") {
dimension = "apps"
applicationId = "ug.go.health.echisSupervisor"
versionNameSuffix = "-echis-supervisor"
manifestPlaceholders["appLabel"] = "MOH UG eCHIS Supervisor"
manifestPlaceholders["appLabel"] = "eCHIS"
}

create("sidBunda") {
Expand Down
4 changes: 4 additions & 0 deletions android/quest/src/echis/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="fhir_core_app" translatable="false">MoH eCHIS</string>
</resources>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ constructor(
val appId = appId.value?.trim()
if (!appId.isNullOrEmpty()) {
when {
sharedPreferencesHelper.hasDebugSuffix() -> loadConfigurations(context)
// Check directly for /debug suffix, regardless of build variant
appId.endsWith(ConfigurationRegistry.DEBUG_SUFFIX, ignoreCase = true) ->
loadConfigurations(context)
Comment on lines +101 to +103
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this optional?

else -> fetchRemoteConfigurations(appId, context)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,114 @@ class AppSettingViewModelTest : RobolectricTest() {
coVerify { appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any()) }
}
}

@Test
fun `fetchConfigurations() with debug suffix should call loadConfigurations() not fetchRemoteConfigurations()`() {
runTest {
// Given: App ID with /debug suffix
val appId = "echis/debug"
appSettingViewModel.onApplicationIdChanged(appId)

coEvery { appSettingViewModel.loadConfigurations(any()) } just runs

// When: fetchConfigurations is called
appSettingViewModel.fetchConfigurations(context)

// Then: Should call loadConfigurations (local assets)
coVerify { appSettingViewModel.loadConfigurations(context) }
// And should NOT fetch from remote
coVerify(exactly = 0) {
appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any())
}
coVerify(exactly = 0) {
appSettingViewModel.configurationRegistry.fetchRemoteImplementationGuideByAppId(any(), any())
}
}
}

@Test
fun `fetchConfigurations() with DEBUG suffix in uppercase should call loadConfigurations()`() {
runTest {
// Given: App ID with /DEBUG suffix (uppercase)
val appId = "echis/DEBUG"
appSettingViewModel.onApplicationIdChanged(appId)

coEvery { appSettingViewModel.loadConfigurations(any()) } just runs

// When: fetchConfigurations is called
appSettingViewModel.fetchConfigurations(context)

// Then: Should call loadConfigurations (case-insensitive check)
coVerify { appSettingViewModel.loadConfigurations(context) }
coVerify(exactly = 0) {
appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any())
}
}
}

@Test
fun `fetchConfigurations() without debug suffix should call fetchRemoteConfigurations()`() {
runTest {
// Given: App ID without /debug suffix
val appId = "echis"
appSettingViewModel.onApplicationIdChanged(appId)

val composition =
Composition().apply {
addSection().apply { this.focus = Reference().apply { reference = "Binary/123" } }
}

coEvery {
appSettingViewModel.configurationRegistry.fetchRemoteImplementationGuideByAppId(any(), any())
} returns null
coEvery {
appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any())
} returns composition
coEvery { appSettingViewModel.defaultRepository.createRemote(any(), any()) } just runs
coEvery { appSettingViewModel.fhirResourceDataSource.post(requestBody = any()) } returns
Bundle()

// When: fetchConfigurations is called
appSettingViewModel.fetchConfigurations(context)

// Then: Should fetch from remote
coVerify { appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any()) }
// And should NOT call loadConfigurations
coVerify(exactly = 0) { appSettingViewModel.loadConfigurations(any()) }
}
}

@Test
fun `fetchConfigurations() with empty appId should not proceed`() {
runTest {
// Given: Empty App ID
appSettingViewModel.onApplicationIdChanged("")

// When: fetchConfigurations is called
appSettingViewModel.fetchConfigurations(context)

// Then: Should not fetch anything
coVerify(exactly = 0) {
appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any())
}
coVerify(exactly = 0) { appSettingViewModel.loadConfigurations(any()) }
}
}

@Test
fun `fetchConfigurations() with null appId should not proceed`() {
runTest {
// Given: Null App ID (not set)
appSettingViewModel.appId.value = null

// When: fetchConfigurations is called
appSettingViewModel.fetchConfigurations(context)

// Then: Should not fetch anything
coVerify(exactly = 0) {
appSettingViewModel.configurationRegistry.fetchRemoteCompositionByAppId(any())
}
coVerify(exactly = 0) { appSettingViewModel.loadConfigurations(any()) }
}
}
}
Loading