diff --git a/feature/client-api/src/main/java/com/simprints/feature/clientapi/mappers/request/IntentToActionMapper.kt b/feature/client-api/src/main/java/com/simprints/feature/clientapi/mappers/request/IntentToActionMapper.kt index 4c20c9cfc4..c719083f43 100644 --- a/feature/client-api/src/main/java/com/simprints/feature/clientapi/mappers/request/IntentToActionMapper.kt +++ b/feature/client-api/src/main/java/com/simprints/feature/clientapi/mappers/request/IntentToActionMapper.kt @@ -148,9 +148,10 @@ internal class IntentToActionMapper @Inject constructor( }.build() // CommCare is not able to provide session ID so we assume that the last available session ID is correct - private suspend fun ensureExtrasHaveSessionId(map: Map) = - if (map.containsKey(Constants.SIMPRINTS_SESSION_ID)) map - else map.toMutableMap().also { it.put(Constants.SIMPRINTS_SESSION_ID, getCurrentSessionId()) } + private suspend fun ensureExtrasHaveSessionId(map: Map): Map = + if (map[Constants.SIMPRINTS_SESSION_ID].let { it as? String }.isNullOrBlank()) { + map.toMutableMap().also { it.put(Constants.SIMPRINTS_SESSION_ID, getCurrentSessionId()) } + } else map private suspend fun mapLibSimprintsAction( actionIdentifier: ActionRequestIdentifier, diff --git a/feature/client-api/src/test/java/com/simprints/feature/clientapi/mappers/request/IntentToActionMapperTest.kt b/feature/client-api/src/test/java/com/simprints/feature/clientapi/mappers/request/IntentToActionMapperTest.kt index ed3338e9c3..ea3ba1d129 100644 --- a/feature/client-api/src/test/java/com/simprints/feature/clientapi/mappers/request/IntentToActionMapperTest.kt +++ b/feature/client-api/src/test/java/com/simprints/feature/clientapi/mappers/request/IntentToActionMapperTest.kt @@ -103,6 +103,16 @@ class IntentToActionMapperTest { } } + @Test + fun `correctly handles CommCare intent with blank session ID`() = runTest { + mapOf( + "com.simprints.commcare.CONFIRM_IDENTITY" to ActionRequest.ConfirmIdentityActionRequest::class, + "com.simprints.commcare.REGISTER_LAST_BIOMETRICS" to ActionRequest.EnrolLastBiometricActionRequest::class, + ).forEach { (action, expectedClass) -> + assertThat(mapper(action, blankSessionExtras, any())).isInstanceOf(expectedClass.java) + } + } + @Test fun `throws exception for invalid CommCare intent actions`() = runTest { assertThrows { @@ -164,6 +174,15 @@ class IntentToActionMapperTest { SIMPRINTS_SELECTED_GUID to SESSION_ID, SIMPRINTS_VERIFY_GUID to SESSION_ID, ) + + private val blankSessionExtras = mapOf( + SIMPRINTS_PROJECT_ID to "projectId-1111111111", + SIMPRINTS_USER_ID to "userId", + SIMPRINTS_MODULE_ID to "moduleId", + SIMPRINTS_SESSION_ID to "", + SIMPRINTS_SELECTED_GUID to SESSION_ID, + SIMPRINTS_VERIFY_GUID to SESSION_ID, + ) } }