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 @@ -82,8 +82,11 @@ internal class OrchestratorViewModel @Inject constructor(
actionRequest = action

try {
steps = stepsBuilder.build(action, projectConfiguration)
} catch (e: SubjectAgeNotSupportedException) {
// In case of a follow-up action, we should restore completed steps from cache
// and add new ones to the list. This way all session steps are available throughout
// the app for reference (i.e. have we already captured face in this session?)
steps = cache.steps + stepsBuilder.build(action, projectConfiguration)
} catch (_: SubjectAgeNotSupportedException) {
handleErrorResponse(AppErrorResponse(AppErrorReason.AGE_GROUP_NOT_SUPPORTED))
return@launch
}
Expand Down Expand Up @@ -176,8 +179,7 @@ internal class OrchestratorViewModel @Inject constructor(
if (step.id == StepId.ENROL_LAST_BIOMETRIC) {
step.payload.getParcelable<EnrolLastBiometricParams>("params")?.let { params ->
val updatedParams = params.copy(
//TODO: don't forget to update this when MS-790 is merged
steps = params.steps + mapStepsForLastBiometrics(steps.mapNotNull { it.result })
steps = mapStepsForLastBiometrics(steps.mapNotNull { it.result })
)
step.payload = EnrolLastBiometricContract.getArgs(
projectId = updatedParams.projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.simprints.infra.orchestration.data.responses.AppErrorResponse
import com.simprints.matcher.MatchParams
import com.simprints.testtools.common.coroutines.TestCoroutineRule
import io.mockk.MockKAnnotations
import io.mockk.clearMocks
import io.mockk.coEvery
import io.mockk.coJustRun
import io.mockk.coVerify
Expand Down Expand Up @@ -340,14 +341,12 @@ internal class OrchestratorViewModelTest {

@Test
fun `Restores steps if empty`() = runTest {
every { stepsBuilder.build(any(), any()) } returns emptyList()
val savedSteps = listOf(
createMockStep(StepId.SETUP),
createMockStep(StepId.CONSENT),
)
every { cache.steps } returns savedSteps

viewModel.handleAction(mockk())
viewModel.restoreStepsIfNeeded()

verify { cache.steps }
Expand All @@ -366,6 +365,8 @@ internal class OrchestratorViewModelTest {
every { cache.steps } returns savedSteps

viewModel.handleAction(mockk())
// Clear previous interactions with cache resulting from handleAction()
clearMocks(cache, answers = false)
viewModel.restoreStepsIfNeeded()

verify(exactly = 0) { cache.steps }
Expand Down Expand Up @@ -412,7 +413,7 @@ internal class OrchestratorViewModelTest {
"projectId",
TokenizableString.Tokenized("userId"),
TokenizableString.Tokenized("moduleId"),
emptyList()
listOf(mockk<EnrolLastBiometricStepResult>())
))
every { stepsBuilder.build(any(), any()) } returns listOf(
captureStep,
Expand All @@ -428,7 +429,7 @@ internal class OrchestratorViewModelTest {

viewModel.currentStep.test().value().peekContent()?.let { step ->
assertThat(step.payload.getParcelable<EnrolLastBiometricParams>("params")?.steps)
.contains(mockEnrolLastStep)
.containsExactly(mockEnrolLastStep)
}
}

Expand Down