Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<String, Any>) =
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<String, Any>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvalidRequestException> {
Expand Down Expand Up @@ -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,
)
}
}

9 changes: 4 additions & 5 deletions feature/orchestrator/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<intent-filter>
<action android:name="com.simprints.simodkadapter.REGISTER" />
<action android:name="com.simprints.simodkadapter.IDENTIFY" />
<action android:name="com.simprints.simodkadapter.UPDATE" />
<action android:name="com.simprints.simodkadapter.VERIFY" />
<action android:name="com.simprints.simodkadapter.CONFIRM_IDENTITY" />
<action android:name="com.simprints.simodkadapter.REGISTER_LAST_BIOMETRICS" />
Expand All @@ -23,9 +22,9 @@
<intent-filter>
<action android:name="com.simprints.simodkadapter.REGISTER" />
<action android:name="com.simprints.simodkadapter.IDENTIFY" />
<action android:name="com.simprints.simodkadapter.UPDATE" />
<action android:name="com.simprints.simodkadapter.VERIFY" />
<action android:name="com.simprints.simodkadapter.CONFIRM_IDENTITY" />
<action android:name="com.simprints.simodkadapter.REGISTER_LAST_BIOMETRICS" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -47,9 +46,9 @@
<intent-filter>
<action android:name="com.simprints.id.REGISTER" />
<action android:name="com.simprints.id.IDENTIFY" />
<action android:name="com.simprints.id.UPDATE" />
<action android:name="com.simprints.id.VERIFY" />
<action android:name="com.simprints.id.CONFIRM_IDENTITY" />
<action android:name="com.simprints.id.REGISTER_LAST_BIOMETRICS" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -61,19 +60,19 @@
<intent-filter>
<action android:name="com.simprints.commcare.REGISTER" />
<action android:name="com.simprints.commcare.IDENTIFY" />
<action android:name="com.simprints.commcare.UPDATE" />
<action android:name="com.simprints.commcare.VERIFY" />
<action android:name="com.simprints.commcare.CONFIRM_IDENTITY" />
<action android:name="com.simprints.commcare.REGISTER_LAST_BIOMETRICS" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.simprints.commcare.REGISTER" />
<action android:name="com.simprints.commcare.IDENTIFY" />
<action android:name="com.simprints.commcare.UPDATE" />
<action android:name="com.simprints.commcare.VERIFY" />
<action android:name="com.simprints.commcare.CONFIRM_IDENTITY" />
<action android:name="com.simprints.commcare.REGISTER_LAST_BIOMETRICS" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down