Skip to content
Snippets Groups Projects
Unverified Commit fe1b2379 authored by chris-cwa's avatar chris-cwa Committed by GitHub
Browse files

Unit Tests for CheckIn Repository (EXPOSUREAPP-5062) (#2615)


* test add checkin

* test update checkin

* test get checkin

* - unnecessary equals override

* extending base test

Co-authored-by: default avatarMatthias Urhahn <matthias.urhahn@sap.com>
Co-authored-by: default avatarMohamed Metwalli <mohamed.metwalli@sap.com>
parent 7ce046c8
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ package de.rki.coronawarnapp.eventregistration.checkins
import org.joda.time.Instant
@Suppress("LongParameterList")
class CheckIn(
data class CheckIn(
val id: Long,
val guid: String,
val version: Int,
......
package de.rki.coronawarnapp.eventregistration.checkins
import de.rki.coronawarnapp.eventregistration.storage.TraceLocationDatabase
import de.rki.coronawarnapp.eventregistration.storage.dao.CheckInDao
import de.rki.coronawarnapp.eventregistration.storage.entity.TraceLocationCheckInEntity
import io.kotest.matchers.shouldBe
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.impl.annotations.MockK
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runBlockingTest
import org.joda.time.Instant
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import testhelpers.BaseTest
class CheckInRepositoryTest : BaseTest() {
@MockK lateinit var factory: TraceLocationDatabase.Factory
@MockK lateinit var database: TraceLocationDatabase
@MockK lateinit var checkInDao: CheckInDao
private val allEntriesFlow = MutableStateFlow(emptyList<TraceLocationCheckInEntity>())
@BeforeEach
fun setup() {
MockKAnnotations.init(this)
every { factory.create() } returns database
every { database.eventCheckInDao() } returns checkInDao
every { checkInDao.allEntries() } returns allEntriesFlow
}
private fun createInstance(scope: CoroutineScope) = CheckInRepository(
factory,
scope
)
@Test
fun `add new check in`() {
coEvery { checkInDao.insert(any()) } returns 0L
runBlockingTest {
val time = Instant.ofEpochMilli(1397210400000)
createInstance(scope = this).addCheckIn(
CheckIn(
id = 0L,
guid = "41da2115-eba2-49bd-bf17-adb3d635ddaf",
version = 1,
type = 2,
description = "brothers birthday",
address = "Malibu",
traceLocationStart = time,
traceLocationEnd = null,
defaultCheckInLengthInMinutes = null,
signature = "abc",
checkInStart = time,
checkInEnd = null,
targetCheckInEnd = null,
createJournalEntry = false
)
)
coVerify {
checkInDao.insert(
TraceLocationCheckInEntity(
id = 0L,
guid = "41da2115-eba2-49bd-bf17-adb3d635ddaf",
version = 1,
type = 2,
description = "brothers birthday",
address = "Malibu",
traceLocationStart = time,
traceLocationEnd = null,
defaultCheckInLengthInMinutes = null,
signature = "abc",
checkInStart = time,
checkInEnd = null,
targetCheckInEnd = null,
createJournalEntry = false
)
)
}
}
}
@Test
fun `update new check in`() {
coEvery { checkInDao.update(any()) } returns Unit
runBlockingTest {
val start = Instant.ofEpochMilli(1397210400000)
val end = Instant.ofEpochMilli(1615796487)
createInstance(scope = this).updateCheckIn(
CheckIn(
id = 0L,
guid = "6e5530ce-1afc-4695-a4fc-572e6443eacd",
version = 1,
type = 2,
description = "sisters birthday",
address = "Long Beach",
traceLocationStart = start,
traceLocationEnd = end,
defaultCheckInLengthInMinutes = null,
signature = "efg",
checkInStart = start,
checkInEnd = end,
targetCheckInEnd = end,
createJournalEntry = false
)
)
coVerify {
checkInDao.update(
TraceLocationCheckInEntity(
id = 0L,
guid = "6e5530ce-1afc-4695-a4fc-572e6443eacd",
version = 1,
type = 2,
description = "sisters birthday",
address = "Long Beach",
traceLocationStart = start,
traceLocationEnd = end,
defaultCheckInLengthInMinutes = null,
signature = "efg",
checkInStart = start,
checkInEnd = end,
targetCheckInEnd = end,
createJournalEntry = false
)
)
}
}
}
@Test
fun `get data`() {
val start = Instant.ofEpochMilli(1615796487)
val end = Instant.ofEpochMilli(1397210400000)
allEntriesFlow.value = listOf(
TraceLocationCheckInEntity(
id = 0L,
guid = "6e5530ce-1afc-4695-a4fc-572e6443eacd",
version = 1,
type = 2,
description = "sisters birthday",
address = "Long Beach",
traceLocationStart = start,
traceLocationEnd = end,
defaultCheckInLengthInMinutes = null,
signature = "efg",
checkInStart = start,
checkInEnd = end,
targetCheckInEnd = end,
createJournalEntry = false
)
)
runBlockingTest {
createInstance(scope = this).allCheckIns.first() shouldBe listOf(
CheckIn(
id = 0L,
guid = "6e5530ce-1afc-4695-a4fc-572e6443eacd",
version = 1,
type = 2,
description = "sisters birthday",
address = "Long Beach",
traceLocationStart = start,
traceLocationEnd = end,
defaultCheckInLengthInMinutes = null,
signature = "efg",
checkInStart = start,
checkInEnd = end,
targetCheckInEnd = end,
createJournalEntry = false
)
)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment