From c15c012d62da0d993a2800164e7c713465bf3429 Mon Sep 17 00:00:00 2001 From: pld Date: Fri, 20 Dec 2024 21:39:19 -0500 Subject: [PATCH] add test and guard for entry item with missing elements --- .../configuration/ConfigurationRegistry.kt | 10 ++++--- .../ConfigurationRegistryTest.kt | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt index 337a818cf5..6113cda40b 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt @@ -348,10 +348,12 @@ constructor( } if (sectionComponent.hasEntry() && sectionComponent.entry.isNotEmpty()) { sectionComponent.entry.forEach { entryReference -> - addBinaryToConfigsJsonMap( - entryReference, - configsLoadedCallback, - ) + if (entryReference.hasReferenceElement() && entryReference.hasIdentifier()) { + addBinaryToConfigsJsonMap( + entryReference, + configsLoadedCallback, + ) + } } } } 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 4a6b7e9b78..14469a3695 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 @@ -1158,6 +1158,33 @@ class ConfigurationRegistryTest : RobolectricTest() { assertTrue(configRegistry.configsJsonMap.containsKey("resource2")) } + @Test + fun testPopulateConfigurationsMapWithEntryMissingId() = runTest { + val composition = + Composition().apply { + section = + listOf( + SectionComponent().apply { + entry = + listOf( + Reference().apply { + reference = "Binary/1" + }, + Reference().apply { + reference = "Binary/2" + identifier = Identifier().apply { value = "resource2" } + }, + ) + }, + ) + } + + coEvery { fhirEngine.get(any()) } returns Binary().apply { content = ByteArray(0) } + configRegistry.populateConfigurationsMap(context, composition, false, "app-id") {} + assertEquals(1, configRegistry.configsJsonMap.size) + assertTrue(configRegistry.configsJsonMap.containsKey("resource2")) + } + @Test fun testPopulateConfigurationsMapWithFocusAndEntry() = runTest { val composition =