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 @@ -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<String, Any>) =
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<String, Any>): Map<String, Any> =
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ class IntentToActionMapperTest {
}
}

@Test
fun `correctly handles CommCare intent with blank session ID`() = runTest {
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.

Maybe add another test for missing sessionId as it's the real world scenario currently.

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.

It was added in the initial fix. One test case above this one.

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<InvalidRequestException> {
Expand Down Expand Up @@ -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,
)
}
}