-
Notifications
You must be signed in to change notification settings - Fork 2
MS-438 Prevent invalid person creation event #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,14 @@ | ||
| package com.simprints.feature.orchestrator.usecases | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import com.simprints.core.domain.fingerprint.IFingerIdentifier | ||
| import com.simprints.core.tools.time.TimeHelper | ||
| import com.simprints.core.tools.utils.EncodingUtils | ||
| import com.simprints.core.tools.time.Timestamp | ||
| import com.simprints.face.capture.FaceCaptureResult | ||
| import com.simprints.fingerprint.capture.FingerprintCaptureResult | ||
| import com.simprints.infra.events.SessionEventRepository | ||
| import com.simprints.infra.events.event.domain.models.PersonCreationEvent | ||
| import com.simprints.infra.events.event.domain.models.face.FaceCaptureBiometricsEvent | ||
| import com.simprints.infra.events.event.domain.models.face.FaceCaptureEvent | ||
| import com.simprints.infra.events.event.domain.models.fingerprint.FingerprintCaptureBiometricsEvent | ||
| import com.simprints.infra.events.event.domain.models.fingerprint.FingerprintCaptureEvent | ||
| import com.simprints.core.domain.fingerprint.IFingerIdentifier | ||
| import com.simprints.core.tools.time.Timestamp | ||
| import com.simprints.infra.events.SessionEventRepository | ||
| import com.simprints.testtools.common.coroutines.TestCoroutineRule | ||
| import io.mockk.MockKAnnotations | ||
| import io.mockk.coEvery | ||
|
|
@@ -36,30 +32,24 @@ internal class CreatePersonEventUseCaseTest { | |
| @MockK | ||
| lateinit var timeHelper: TimeHelper | ||
|
|
||
| @MockK | ||
| lateinit var encodingUtils: EncodingUtils | ||
|
|
||
| private lateinit var useCase: CreatePersonEventUseCase | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| MockKAnnotations.init(this, relaxed = true) | ||
|
|
||
| every { timeHelper.now() } returns Timestamp(0L) | ||
| every { encodingUtils.byteArrayToBase64(any()) } returns TEMPLATE | ||
|
|
||
| coEvery { eventRepository.getCurrentSessionScope() } returns mockk { | ||
| every { id } returns "sessionId" | ||
| } | ||
|
|
||
| useCase = CreatePersonEventUseCase(eventRepository, timeHelper, encodingUtils) | ||
| useCase = CreatePersonEventUseCase(eventRepository, timeHelper) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Does not create event if has person creation in session`() = runTest { | ||
| coEvery { eventRepository.getEventsInCurrentSession() } returns listOf( | ||
| mockk<FingerprintCaptureBiometricsEvent>(), | ||
| mockk<FaceCaptureBiometricsEvent>(), | ||
| mockk<PersonCreationEvent>(), | ||
| ) | ||
|
|
||
|
|
@@ -70,10 +60,7 @@ internal class CreatePersonEventUseCaseTest { | |
|
|
||
| @Test | ||
| fun `Does not create event if no biometric data`() = runTest { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need more tests to cover the case that is prevented with this PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is prevented by removing the repo and only using the step result data. I think the current tests cover that; IIRC, there are some extra checks in places where the data is added to step results. |
||
| coEvery { eventRepository.getEventsInCurrentSession() } returns listOf( | ||
| mockk<FingerprintCaptureEvent>(), | ||
| mockk<FaceCaptureEvent>(), | ||
| ) | ||
| coEvery { eventRepository.getEventsInCurrentSession() } returns listOf() | ||
|
|
||
| useCase(listOf()) | ||
|
|
||
|
|
@@ -82,18 +69,13 @@ internal class CreatePersonEventUseCaseTest { | |
|
|
||
| @Test | ||
| fun `Create event if there is face biometric data`() = runTest { | ||
| coEvery { eventRepository.getEventsInCurrentSession() } returns listOf( | ||
| mockk<FaceCaptureBiometricsEvent> { | ||
| every { payload.id } returns "eventFaceId1" | ||
| every { payload.face.template } returns TEMPLATE | ||
| }, | ||
| ) | ||
| coEvery { eventRepository.getEventsInCurrentSession() } returns listOf() | ||
|
|
||
| useCase(listOf(FaceCaptureResult(listOf(createFaceCaptureResultItem())))) | ||
|
|
||
| coVerify { | ||
| eventRepository.addOrUpdateEvent(withArg<PersonCreationEvent> { | ||
| assertThat(it.payload.faceCaptureIds).isEqualTo(listOf("eventFaceId1")) | ||
| assertThat(it.payload.faceCaptureIds).isEqualTo(listOf(FACE_ID)) | ||
| }) | ||
| } | ||
| } | ||
|
|
@@ -102,7 +84,7 @@ internal class CreatePersonEventUseCaseTest { | |
| fun `Create event if there is fingerprint biometric data`() = runTest { | ||
| coEvery { eventRepository.getEventsInCurrentSession() } returns listOf( | ||
| mockk<FingerprintCaptureBiometricsEvent> { | ||
| every { payload.id } returns "eventFinger1" | ||
| every { payload.id } returns FINGER_ID | ||
| every { payload.fingerprint.template } returns TEMPLATE | ||
| }, | ||
| ) | ||
|
|
@@ -111,22 +93,36 @@ internal class CreatePersonEventUseCaseTest { | |
|
|
||
| coVerify { | ||
| eventRepository.addOrUpdateEvent(withArg<PersonCreationEvent> { | ||
| assertThat(it.payload.fingerprintCaptureIds).isEqualTo(listOf("eventFinger1")) | ||
| assertThat(it.payload.fingerprintCaptureIds).isEqualTo(listOf(FINGER_ID)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| private fun createFingerprintCaptureResultItem() = FingerprintCaptureResult.Item( | ||
| IFingerIdentifier.RIGHT_THUMB, | ||
| FingerprintCaptureResult.Sample(IFingerIdentifier.RIGHT_THUMB, byteArrayOf(), 0, null, "format") | ||
| captureEventId = FINGER_ID, | ||
| identifier = IFingerIdentifier.RIGHT_THUMB, | ||
| sample = FingerprintCaptureResult.Sample( | ||
| IFingerIdentifier.RIGHT_THUMB, | ||
| TEMPLATE.toByteArray(), | ||
| 0, | ||
| null, | ||
| "format" | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| private fun createFaceCaptureResultItem() = | ||
| FaceCaptureResult.Item(0, FaceCaptureResult.Sample("faceId", byteArrayOf(), null, "format")) | ||
| FaceCaptureResult.Item( | ||
| captureEventId = FACE_ID, | ||
| index = 0, | ||
| sample = FaceCaptureResult.Sample(FACE_ID, TEMPLATE.toByteArray(), null, "format") | ||
| ) | ||
|
|
||
|
|
||
| companion object { | ||
|
|
||
| const val TEMPLATE = "template" | ||
| private const val TEMPLATE = "template" | ||
| private const val FINGER_ID = "eventFinger1" | ||
| private const val FACE_ID = "eventFinger1" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we log an error in the opposite case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but I am pretty sceptical that anyone will ever look into it.