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 @@ -157,7 +157,7 @@ internal class ClientApiViewModelTest {
deleteSessionEventsIfNeeded(any())
persistentLogger.log(any(), any(), any(), any())
}
verify { resultMapper.invoke(withArg { it is ActionResponse.EnrolActionResponse }) }
verify { resultMapper.invoke(match<ActionResponse> { it is ActionResponse.EnrolActionResponse }) }
viewModel.returnResponse.test().assertHasValue()
}

Expand All @@ -172,7 +172,7 @@ internal class ClientApiViewModelTest {
simpleEventReporter.addCompletionCheckEvent(eq(true))
persistentLogger.log(any(), any(), any(), any())
}
verify { resultMapper.invoke(withArg { it is ActionResponse.IdentifyActionResponse }) }
verify { resultMapper.invoke(match<ActionResponse> { it is ActionResponse.IdentifyActionResponse }) }
viewModel.returnResponse.test().assertHasValue()
}

Expand All @@ -188,7 +188,7 @@ internal class ClientApiViewModelTest {
deleteSessionEventsIfNeeded(any())
persistentLogger.log(any(), any(), any(), any())
}
verify { resultMapper.invoke(withArg { it is ActionResponse.ConfirmActionResponse }) }
verify { resultMapper.invoke(match<ActionResponse> { it is ActionResponse.ConfirmActionResponse }) }
viewModel.returnResponse.test().assertHasValue()
}

Expand All @@ -205,7 +205,7 @@ internal class ClientApiViewModelTest {
deleteSessionEventsIfNeeded(any())
persistentLogger.log(any(), any(), any(), any())
}
verify { resultMapper.invoke(withArg { it is ActionResponse.VerifyActionResponse }) }
verify { resultMapper.invoke(match<ActionResponse> { it is ActionResponse.VerifyActionResponse }) }
viewModel.returnResponse.test().assertHasValue()
}

Expand All @@ -225,7 +225,7 @@ internal class ClientApiViewModelTest {
deleteSessionEventsIfNeeded(any())
persistentLogger.log(any(), any(), any(), any())
}
verify { resultMapper.invoke(withArg { it is ActionResponse.ExitFormActionResponse }) }
verify { resultMapper.invoke(match<ActionResponse> { it is ActionResponse.ExitFormActionResponse }) }
viewModel.returnResponse.test().assertHasValue()
}

Expand All @@ -242,7 +242,7 @@ internal class ClientApiViewModelTest {
deleteSessionEventsIfNeeded(any())
persistentLogger.log(any(), any(), any(), any())
}
verify { resultMapper.invoke(withArg { it is ActionResponse.ErrorActionResponse }) }
verify { resultMapper.invoke(match<ActionResponse> { it is ActionResponse.ErrorActionResponse }) }
viewModel.returnResponse.test().assertHasValue()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,15 @@ class RealmEnrolmentRecordLocalDataSourceTest {

@Test
fun performSubjectCreationAction_deletesOldSamples() = runTest {
val faceReferenceId = "faceToDelete"
val fingerReferenceId = "fingerToDelete"
every { realmSingleQuery.find() } returns getRandomSubject()
.copy(
faceSamples = listOf(
getRandomFaceSample("faceToDelete"),
getRandomFaceSample(referenceId = faceReferenceId),
),
fingerprintSamples = listOf(
getRandomFingerprintSample("fingerToDelete"),
getRandomFingerprintSample(referenceId = fingerReferenceId),
),
).toRealmDb()
val subject = getFakePerson()
Expand All @@ -284,8 +286,8 @@ class RealmEnrolmentRecordLocalDataSourceTest {
)

verify {
mutableRealm.delete(withArg<DbFaceSample> { it.id == "faceToDelete" })
mutableRealm.delete(withArg<DbFingerprintSample> { it.id == "faceToDelete" })
mutableRealm.delete(match<DbFaceSample> { it.referenceId == faceReferenceId })
mutableRealm.delete(match<DbFingerprintSample> { it.referenceId == fingerReferenceId })
}
val peopleCount = enrolmentRecordLocalDataSource.count()
assertThat(peopleCount).isEqualTo(1)
Expand All @@ -294,13 +296,15 @@ class RealmEnrolmentRecordLocalDataSourceTest {
@Test
fun performSubjectUpdateAction() = runTest {
val subject = getFakePerson()
val faceReferenceId = "faceToDelete"
val fingerReferenceId = "fingerToDelete"
every { realmSingleQuery.find() } returns getRandomSubject(
faceSamples = listOf(
getRandomFaceSample(referenceId = "faceToDelete"),
getRandomFaceSample(referenceId = faceReferenceId),
getRandomFaceSample(),
),
fingerprintSamples = listOf(
getRandomFingerprintSample(referenceId = "fingerToDelete"),
getRandomFingerprintSample(referenceId = fingerReferenceId),
getRandomFingerprintSample(),
),
).toRealmDb()
Expand All @@ -311,23 +315,23 @@ class RealmEnrolmentRecordLocalDataSourceTest {
subject.subjectId.toString(),
faceSamplesToAdd = listOf(getRandomFaceSample()),
fingerprintSamplesToAdd = listOf(getRandomFingerprintSample()),
referenceIdsToRemove = listOf("faceToDelete", "fingerToDelete"),
referenceIdsToRemove = listOf(faceReferenceId, fingerReferenceId),
),
),
project,
)
val peopleCount = enrolmentRecordLocalDataSource.count()
assertThat(peopleCount).isEqualTo(1)
verify {
mutableRealm.delete(withArg<DbFaceSample> { it.id == "faceToDelete" })
mutableRealm.delete(withArg<DbFingerprintSample> { it.id == "faceToDelete" })
mutableRealm.delete(match<DbFaceSample> { it.referenceId == faceReferenceId })
mutableRealm.delete(match<DbFingerprintSample> { it.referenceId == fingerReferenceId })
mutableRealm.copyToRealm(
withArg<DbSubject> {
match<DbSubject> {
// one old + one new
it.faceSamples.size == 2 &&
it.fingerprintSamples.size == 2 &&
it.faceSamples.none { it.referenceId == "faceToDelete" } &&
it.fingerprintSamples.none { it.referenceId == "fingerToDelete" }
it.fingerprintSamples.size == 2 &&
it.faceSamples.none { sample -> sample.referenceId == faceReferenceId } &&
it.fingerprintSamples.none { sample -> sample.referenceId == fingerReferenceId }
},
any(),
)
Expand Down Expand Up @@ -368,7 +372,6 @@ class RealmEnrolmentRecordLocalDataSourceTest {
assertThat(peopleCount).isEqualTo(0)
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun `loadAllSubjectsInBatches with no subjects should return empty list and close channel`() = runTest {
val batchSize = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.simprints.infra.config.store.models.Project
import com.simprints.infra.config.sync.ConfigManager
import com.simprints.infra.enrolment.records.repository.EnrolmentRecordRepository
import com.simprints.infra.enrolment.records.repository.domain.models.Subject
import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAction.Creation
import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAction.Deletion
import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAction
import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAction.*
import com.simprints.infra.events.EventRepository
import com.simprints.infra.events.event.domain.models.downsync.EventDownSyncRequestEvent
import com.simprints.infra.events.event.domain.models.scope.EventScope
Expand Down Expand Up @@ -509,7 +509,7 @@ class EventDownSyncTaskTest {
}

@Test
fun downSync_shouldProcessRecordUpdateEvent_withCreations() = runTest {
fun downSync_shouldProcessRecordUpdateEvent_withUpdate() = runTest {
coEvery { enrolmentRecordRepository.load(any()) } returns listOf(
Subject(
subjectId = "subjectId",
Expand All @@ -529,34 +529,9 @@ class EventDownSyncTaskTest {

coVerify {
enrolmentRecordRepository.performActions(
withArg { actions -> actions.all { it is Creation } },
any(),
)
}
}

@Test
fun downSync_shouldProcessRecordUpdateEvent_withDeletions() = runTest {
coEvery { enrolmentRecordRepository.load(any()) } returns listOf(
Subject(
subjectId = "subjectId",
projectId = "projectId",
attendantId = "moduleId".asTokenizableRaw(),
moduleId = "attendantId".asTokenizableRaw(),
faceSamples = listOf(
FaceSample(byteArrayOf(), "format", "referenceIdToDelete"),
),
),
)

val event = ENROLMENT_RECORD_UPDATE
mockProgressEmission(listOf(event))

eventDownSyncTask.downSync(this, projectOp, eventScope, project).toList()

coVerify {
enrolmentRecordRepository.performActions(
withArg { actions -> actions.all { it is Deletion } },
match<List<SubjectAction>> { actions ->
actions.size == 1 && actions.first() is Update
},
any(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DatabasePersistentLoggerTest {

coVerify {
logEntryDao.save(
coWithArg {
match<DbLogEntry> {
it.timestampMs == 0L && it.title == "title" && it.body == "body"
},
)
Expand All @@ -74,7 +74,7 @@ class DatabasePersistentLoggerTest {

coVerify {
logEntryDao.save(
coWithArg {
match<DbLogEntry> {
it.timestampMs == 1L && it.title == "title" && it.body == "body"
},
)
Expand All @@ -88,7 +88,7 @@ class DatabasePersistentLoggerTest {

coVerify {
logEntryDao.save(
coWithArg {
match<DbLogEntry> {
it.timestampMs == 0L && it.title == "title" && it.body == "body"
},
)
Expand All @@ -102,7 +102,7 @@ class DatabasePersistentLoggerTest {

coVerify {
logEntryDao.save(
coWithArg {
match<DbLogEntry> {
it.timestampMs == 1L && it.title == "title" && it.body == "body"
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class CrashlyticsLogWriterTest {

verify {
crashMock.recordException(
withArg {
it is Exception && it.message.contentEquals("Test Message")
},
match<Exception> { it.message?.contains("Test Message") == true }
)
}
}
Expand All @@ -84,7 +82,7 @@ class CrashlyticsLogWriterTest {
Simber.w("Test Message", custException)

verify {
crashMock.log(withArg { it.contains("Test Message") })
crashMock.log(match<String> { it.contains("Test Message") })
}
verify {
crashMock.recordException(custException)
Expand All @@ -102,7 +100,7 @@ class CrashlyticsLogWriterTest {
Simber.e("Test Message", custException)

verify {
crashMock.log(withArg { it.contains("Test Message") })
crashMock.log(match<String> { it.contains("Test Message") })
}
verify {
crashMock.recordException(custException)
Expand Down