From 3372f4664c042bb3f3b47f20c9d21796cee8ac7e Mon Sep 17 00:00:00 2001 From: Sergejs Luhmirins Date: Mon, 2 Sep 2024 13:12:10 +0300 Subject: [PATCH 1/2] MS-617 Align intent filters across integrations --- feature/orchestrator/src/main/AndroidManifest.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/feature/orchestrator/src/main/AndroidManifest.xml b/feature/orchestrator/src/main/AndroidManifest.xml index 44391637c7..0ca104e3c0 100644 --- a/feature/orchestrator/src/main/AndroidManifest.xml +++ b/feature/orchestrator/src/main/AndroidManifest.xml @@ -12,7 +12,6 @@ - @@ -23,9 +22,9 @@ - + @@ -47,9 +46,9 @@ - + @@ -61,9 +60,9 @@ - + @@ -71,9 +70,9 @@ - + From 10d63a179fc307b32f7d9398ef139da4999b01b5 Mon Sep 17 00:00:00 2001 From: Sergejs Luhmirins Date: Mon, 2 Sep 2024 13:17:29 +0300 Subject: [PATCH 2/2] MS-617 Inject last known session ID into intent extras if CommCare does not have one --- .../mappers/request/IntentToActionMapper.kt | 31 ++++++++++++------- .../request/IntentToActionMapperTest.kt | 18 +++++++++++ 2 files changed, 38 insertions(+), 11 deletions(-) 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 95e594d595..4c20c9cfc4 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 @@ -31,6 +31,7 @@ import com.simprints.infra.config.store.models.Project import com.simprints.infra.config.store.tokenization.TokenizationProcessor import com.simprints.infra.orchestration.data.ActionRequest import com.simprints.infra.orchestration.data.ActionRequestIdentifier +import com.simprints.libsimprints.Constants import javax.inject.Inject internal class IntentToActionMapper @Inject constructor( @@ -125,24 +126,32 @@ internal class IntentToActionMapper @Inject constructor( extractor = IdentifyRequestExtractor(extras), project = project ) + ActionConstants.ACTION_ENROL_LAST_BIOMETRICS -> ensureExtrasHaveSessionId(extras).let { + enrolLastBiometricsBuilder( + actionIdentifier = actionIdentifier, + extractor = EnrolLastBiometricsRequestExtractor(it), + project = project + ) + } - ActionConstants.ACTION_ENROL_LAST_BIOMETRICS -> enrolLastBiometricsBuilder( - actionIdentifier = actionIdentifier, - extractor = EnrolLastBiometricsRequestExtractor(extras), - project = project - ) - - ActionConstants.ACTION_CONFIRM_IDENTITY -> confirmIdentifyBuilder( - actionIdentifier = actionIdentifier, - extractor = ConfirmIdentityRequestExtractor(extras), - project = project - ) + ActionConstants.ACTION_CONFIRM_IDENTITY -> ensureExtrasHaveSessionId(extras).let { + confirmIdentifyBuilder( + actionIdentifier = actionIdentifier, + extractor = ConfirmIdentityRequestExtractor(it), + project = project + ) + } else -> throw InvalidRequestException( "Invalid CommCare action", ClientApiError.INVALID_STATE_FOR_INTENT_ACTION ) }.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 mapLibSimprintsAction( actionIdentifier: ActionRequestIdentifier, extras: Map, 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 536e7cab37..ed3338e9c3 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 @@ -93,6 +93,16 @@ class IntentToActionMapperTest { } } + @Test + fun `correctly handles CommCare intent without 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, noSessionExtras, any())).isInstanceOf(expectedClass.java) + } + } + @Test fun `throws exception for invalid CommCare intent actions`() = runTest { assertThrows { @@ -146,6 +156,14 @@ class IntentToActionMapperTest { SIMPRINTS_SELECTED_GUID to SESSION_ID, SIMPRINTS_VERIFY_GUID to SESSION_ID, ) + + private val noSessionExtras = mapOf( + SIMPRINTS_PROJECT_ID to "projectId-1111111111", + SIMPRINTS_USER_ID to "userId", + SIMPRINTS_MODULE_ID to "moduleId", + SIMPRINTS_SELECTED_GUID to SESSION_ID, + SIMPRINTS_VERIFY_GUID to SESSION_ID, + ) } }