From 2e792f671efeec9ee5116c6a819bf3091c04cb38 Mon Sep 17 00:00:00 2001 From: Milen Marinov Date: Mon, 11 Nov 2024 13:17:45 +0200 Subject: [PATCH] [MS-790] Add follow-up steps to session steps instead of replacing them --- .../feature/orchestrator/OrchestratorViewModel.kt | 10 ++++++---- .../feature/orchestrator/OrchestratorViewModelTest.kt | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorViewModel.kt b/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorViewModel.kt index 169d90209c..18e671aed2 100644 --- a/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorViewModel.kt +++ b/feature/orchestrator/src/main/java/com/simprints/feature/orchestrator/OrchestratorViewModel.kt @@ -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 } @@ -176,8 +179,7 @@ internal class OrchestratorViewModel @Inject constructor( if (step.id == StepId.ENROL_LAST_BIOMETRIC) { step.payload.getParcelable("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, diff --git a/feature/orchestrator/src/test/java/com/simprints/feature/orchestrator/OrchestratorViewModelTest.kt b/feature/orchestrator/src/test/java/com/simprints/feature/orchestrator/OrchestratorViewModelTest.kt index 5f24c1e5df..3af0726822 100644 --- a/feature/orchestrator/src/test/java/com/simprints/feature/orchestrator/OrchestratorViewModelTest.kt +++ b/feature/orchestrator/src/test/java/com/simprints/feature/orchestrator/OrchestratorViewModelTest.kt @@ -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 @@ -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 } @@ -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 } @@ -412,7 +413,7 @@ internal class OrchestratorViewModelTest { "projectId", TokenizableString.Tokenized("userId"), TokenizableString.Tokenized("moduleId"), - emptyList() + listOf(mockk()) )) every { stepsBuilder.build(any(), any()) } returns listOf( captureStep, @@ -428,7 +429,7 @@ internal class OrchestratorViewModelTest { viewModel.currentStep.test().value().peekContent()?.let { step -> assertThat(step.payload.getParcelable("params")?.steps) - .contains(mockEnrolLastStep) + .containsExactly(mockEnrolLastStep) } }