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 @@ -43,7 +43,11 @@ internal class CommCareResponseMapper @Inject constructor() {
CommCareConstants.VERIFICATION_GUID_KEY to response.matchResult.guid,
CommCareConstants.VERIFICATION_CONFIDENCE_KEY to response.matchResult.confidenceScore.toString(),
CommCareConstants.VERIFICATION_TIER_KEY to response.matchResult.tier.name,
).toCommCareBundle()
).also {
response.matchResult.verificationSuccess?.let { verificationSuccess ->
it.putString(CommCareConstants.VERIFICATION_SUCCESS_KEY, verificationSuccess.toString())
}
}.toCommCareBundle()

is ActionResponse.ExitFormActionResponse -> bundleOf(
CommCareConstants.SIMPRINTS_SESSION_ID to response.sessionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ internal class LibSimprintsResponseMapper @Inject constructor() {
Tier.valueOf(response.matchResult.tier.name),
response.matchResult.guid,
),
)
).also {
response.matchResult.verificationSuccess?.let { verificationSuccess ->
it.putBoolean(Constants.SIMPRINTS_VERIFICATION_SUCCESS, verificationSuccess)
}
}

is ActionResponse.ExitFormActionResponse -> bundleOf(
Constants.SIMPRINTS_SESSION_ID to response.sessionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ internal class OdkResponseMapper @Inject constructor() {
OdkConstants.ODK_GUIDS_KEY to response.matchResult.guid,
OdkConstants.ODK_CONFIDENCES_KEY to response.matchResult.confidenceScore.toString(),
OdkConstants.ODK_TIERS_KEY to response.matchResult.tier.name,
).addFlowCompletedCheckBasedOnAction(response.actionIdentifier, true)
).also {
response.matchResult.verificationSuccess?.let { verificationSuccess ->
it.putBoolean(OdkConstants.ODK_VERIFICATION_SUCCESS_KEY, verificationSuccess)
}
}.addFlowCompletedCheckBasedOnAction(response.actionIdentifier, true)

is ActionResponse.ExitFormActionResponse -> bundleOf(
OdkConstants.ODK_SESSION_ID to response.sessionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal object OdkConstants {
const val ODK_BIOMETRICS_COMPLETE_CHECK_KEY = "odk-biometrics-complete"
const val ODK_CONFIDENCES_KEY = "odk-confidences"
const val ODK_TIERS_KEY = "odk-tiers"
const val ODK_VERIFICATION_SUCCESS_KEY = "odk-verification-success"
const val ODK_SESSION_ID = "odk-session-id"
const val ODK_EXIT_REASON = "odk-exit-reason"
const val ODK_EXIT_EXTRA = "odk-exit-extra"
Expand Down Expand Up @@ -58,6 +59,7 @@ internal object CommCareConstants {
const val VERIFICATION_CONFIDENCE_KEY = "confidence"
const val VERIFICATION_TIER_KEY = "tier"
const val VERIFICATION_GUID_KEY = "guid"
const val VERIFICATION_SUCCESS_KEY = "verificationSuccess"
const val EXIT_REASON = "exitReason"
const val EXIT_EXTRA = "exitExtra"
const val SIMPRINTS_SESSION_ID = "sessionId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CommCareResponseMapperTest {
}

@Test
fun `correctly maps verify response`() {
fun `correctly maps verify response with null verificationSuccess`() {
val extras = mapper(ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
sessionId = "sessionId",
Expand All @@ -94,6 +94,7 @@ class CommCareResponseMapperTest {
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = null,
),
)).getBundle(CommCareConstants.COMMCARE_BUNDLE_KEY) ?: bundleOf()

Expand All @@ -102,6 +103,51 @@ class CommCareResponseMapperTest {
assertThat(extras.getString(CommCareConstants.VERIFICATION_CONFIDENCE_KEY)).isEqualTo("50")
assertThat(extras.getString(CommCareConstants.VERIFICATION_TIER_KEY)).isEqualTo("TIER_2")
assertThat(extras.getString(CommCareConstants.BIOMETRICS_COMPLETE_CHECK_KEY)).isEqualTo("true")
assertThat(extras.getString(CommCareConstants.VERIFICATION_SUCCESS_KEY)).isNull()
}

@Test
fun `correctly maps verify response with verificationSuccess = false`() {
val extras = mapper(ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
sessionId = "sessionId",
matchResult = AppMatchResult(
guid = "guid",
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = false,
),
)).getBundle(CommCareConstants.COMMCARE_BUNDLE_KEY) ?: bundleOf()

assertThat(extras.getString(CommCareConstants.SIMPRINTS_SESSION_ID)).isEqualTo("sessionId")
assertThat(extras.getString(CommCareConstants.VERIFICATION_GUID_KEY)).isEqualTo("guid")
assertThat(extras.getString(CommCareConstants.VERIFICATION_CONFIDENCE_KEY)).isEqualTo("50")
assertThat(extras.getString(CommCareConstants.VERIFICATION_TIER_KEY)).isEqualTo("TIER_2")
assertThat(extras.getString(CommCareConstants.BIOMETRICS_COMPLETE_CHECK_KEY)).isEqualTo("true")
assertThat(extras.getString(CommCareConstants.VERIFICATION_SUCCESS_KEY)).isEqualTo("false")
}

@Test
fun `correctly maps verify response with verificationSuccess = true`() {
val extras = mapper(ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
sessionId = "sessionId",
matchResult = AppMatchResult(
guid = "guid",
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = true,
),
)).getBundle(CommCareConstants.COMMCARE_BUNDLE_KEY) ?: bundleOf()

assertThat(extras.getString(CommCareConstants.SIMPRINTS_SESSION_ID)).isEqualTo("sessionId")
assertThat(extras.getString(CommCareConstants.VERIFICATION_GUID_KEY)).isEqualTo("guid")
assertThat(extras.getString(CommCareConstants.VERIFICATION_CONFIDENCE_KEY)).isEqualTo("50")
assertThat(extras.getString(CommCareConstants.VERIFICATION_TIER_KEY)).isEqualTo("TIER_2")
assertThat(extras.getString(CommCareConstants.BIOMETRICS_COMPLETE_CHECK_KEY)).isEqualTo("true")
assertThat(extras.getString(CommCareConstants.VERIFICATION_SUCCESS_KEY)).isEqualTo("true")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LibSimprintsResponseMapperTest {
}

@Test
fun `correctly maps verify response`() {
fun `correctly maps verify response with null verificationSuccess`() {
val extras = mapper(
ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
Expand All @@ -99,6 +99,7 @@ class LibSimprintsResponseMapperTest {
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = null,
),
)
)
Expand All @@ -111,6 +112,61 @@ class LibSimprintsResponseMapperTest {
assertThat(extraVerification?.tier).isEqualTo(Tier.TIER_2)
assertThat(extraVerification?.confidence).isEqualTo(50)
assertThat(extras.getBoolean(Constants.SIMPRINTS_BIOMETRICS_COMPLETE_CHECK)).isEqualTo(true)
assertThat(extras.getBoolean(Constants.SIMPRINTS_VERIFICATION_SUCCESS)).isFalse() // Default value
}

@Test
fun `correctly maps verify response with verificationSuccess = false`() {
val extras = mapper(
ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
sessionId = "sessionId",
matchResult = AppMatchResult(
guid = "guid",
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = false,
),
)
)

// Verification does not implement equals, so we have to check each field individually
val extraVerification = extras.getParcelable<Verification>(Constants.SIMPRINTS_VERIFICATION)

assertThat(extras.getString(Constants.SIMPRINTS_SESSION_ID)).isEqualTo("sessionId")
assertThat(extraVerification?.guid).isEqualTo("guid")
assertThat(extraVerification?.tier).isEqualTo(Tier.TIER_2)
assertThat(extraVerification?.confidence).isEqualTo(50)
assertThat(extras.getBoolean(Constants.SIMPRINTS_BIOMETRICS_COMPLETE_CHECK)).isEqualTo(true)
assertThat(extras.getBoolean(Constants.SIMPRINTS_VERIFICATION_SUCCESS)).isEqualTo(false)
}

@Test
fun `correctly maps verify response with verificationSuccess = true`() {
val extras = mapper(
ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
sessionId = "sessionId",
matchResult = AppMatchResult(
guid = "guid",
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = true,
),
)
)

// Verification does not implement equals, so we have to check each field individually
val extraVerification = extras.getParcelable<Verification>(Constants.SIMPRINTS_VERIFICATION)

assertThat(extras.getString(Constants.SIMPRINTS_SESSION_ID)).isEqualTo("sessionId")
assertThat(extraVerification?.guid).isEqualTo("guid")
assertThat(extraVerification?.tier).isEqualTo(Tier.TIER_2)
assertThat(extraVerification?.confidence).isEqualTo(50)
assertThat(extras.getBoolean(Constants.SIMPRINTS_BIOMETRICS_COMPLETE_CHECK)).isEqualTo(true)
assertThat(extras.getBoolean(Constants.SIMPRINTS_VERIFICATION_SUCCESS)).isEqualTo(true)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class OdkResponseMapperTest {
}

@Test
fun `correctly maps verify response`() {
fun `correctly maps verify response with null verificationSuccess`() {
val extras = mapper(ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
sessionId = "sessionId",
Expand All @@ -98,6 +98,7 @@ class OdkResponseMapperTest {
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = null,
),
))

Expand All @@ -106,6 +107,51 @@ class OdkResponseMapperTest {
assertThat(extras.getString(OdkConstants.ODK_CONFIDENCES_KEY)).isEqualTo("50")
assertThat(extras.getString(OdkConstants.ODK_TIERS_KEY)).isEqualTo("TIER_2")
assertThat(extras.getBoolean(OdkConstants.ODK_VERIFY_BIOMETRICS_COMPLETE)).isEqualTo(true)
assertThat(extras.getBoolean(OdkConstants.ODK_VERIFICATION_SUCCESS_KEY)).isEqualTo(false) // default value
}

@Test
fun `correctly maps verify response with verificationSuccess = false`() {
val extras = mapper(ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
sessionId = "sessionId",
matchResult = AppMatchResult(
guid = "guid",
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = false,
),
))

assertThat(extras.getString(OdkConstants.ODK_SESSION_ID)).isEqualTo("sessionId")
assertThat(extras.getString(OdkConstants.ODK_GUIDS_KEY)).isEqualTo("guid")
assertThat(extras.getString(OdkConstants.ODK_CONFIDENCES_KEY)).isEqualTo("50")
assertThat(extras.getString(OdkConstants.ODK_TIERS_KEY)).isEqualTo("TIER_2")
assertThat(extras.getBoolean(OdkConstants.ODK_VERIFY_BIOMETRICS_COMPLETE)).isEqualTo(true)
assertThat(extras.getBoolean(OdkConstants.ODK_VERIFICATION_SUCCESS_KEY)).isEqualTo(false)
}

@Test
fun `correctly maps verify response with verificationSuccess = true`() {
val extras = mapper(ActionResponse.VerifyActionResponse(
actionIdentifier = VerifyActionFactory.getIdentifier(),
sessionId = "sessionId",
matchResult = AppMatchResult(
guid = "guid",
confidenceScore = 50,
tier = AppResponseTier.TIER_2,
matchConfidence = AppMatchConfidence.HIGH,
verificationSuccess = true,
),
))

assertThat(extras.getString(OdkConstants.ODK_SESSION_ID)).isEqualTo("sessionId")
assertThat(extras.getString(OdkConstants.ODK_GUIDS_KEY)).isEqualTo("guid")
assertThat(extras.getString(OdkConstants.ODK_CONFIDENCES_KEY)).isEqualTo("50")
assertThat(extras.getString(OdkConstants.ODK_TIERS_KEY)).isEqualTo("TIER_2")
assertThat(extras.getBoolean(OdkConstants.ODK_VERIFY_BIOMETRICS_COMPLETE)).isEqualTo(true)
assertThat(extras.getBoolean(OdkConstants.ODK_VERIFICATION_SUCCESS_KEY)).isEqualTo(true)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ internal class CreateVerifyResponseUseCase @Inject constructor() {
.lastOrNull()?.let { fingerprintMatchResult ->
projectConfiguration.fingerprint
?.getSdkConfiguration(fingerprintMatchResult.sdk)
?.decisionPolicy
?.let { decisionPolicy ->
?.let { sdkConfiguration ->
fingerprintMatchResult.results
.maxByOrNull { it.confidence }
?.let { AppMatchResult(it.subjectId, it.confidence, decisionPolicy) }
?.let {
AppMatchResult(
guid = it.subjectId,
confidenceScore = it.confidence,
decisionPolicy = sdkConfiguration.decisionPolicy,
verificationMatchThreshold = sdkConfiguration.verificationMatchThreshold
)
}
}
}

Expand All @@ -43,10 +49,17 @@ internal class CreateVerifyResponseUseCase @Inject constructor() {
results: List<Serializable>,
) = results.filterIsInstance<FaceMatchResult>()
.lastOrNull()?.let { faceMatchResult ->
projectConfiguration.face?.decisionPolicy?.let { decisionPolicy ->
projectConfiguration.face?.let { faceConfiguration ->
faceMatchResult.results
.maxByOrNull { it.confidence }
?.let { AppMatchResult(it.subjectId, it.confidence, decisionPolicy) }
?.let {
AppMatchResult(
guid = it.subjectId,
confidenceScore = it.confidence,
decisionPolicy = faceConfiguration.decisionPolicy,
verificationMatchThreshold = faceConfiguration.verificationMatchThreshold
)
}
}
}
}
Loading