Skip to content

Commit

Permalink
Move tests to same file
Browse files Browse the repository at this point in the history
  • Loading branch information
TrulsStenrud committed Aug 28, 2023
1 parent 2a7bc05 commit 61078c4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 97 deletions.
89 changes: 0 additions & 89 deletions src/test/kotlin/no/liflig/documentstore/DomainFilterTest.kt

This file was deleted.

61 changes: 53 additions & 8 deletions src/test/kotlin/no/liflig/documentstore/SearchRepositoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package no.liflig.documentstore

import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.equals.shouldBeEqual
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import no.liflig.documentstore.dao.CrudDaoJdbi
import no.liflig.documentstore.dao.SearchRepositoryJdbi
Expand All @@ -23,6 +26,11 @@ class SearchRepositoryTest {
val searchRepository =
SearchRepositoryJdbi<ExampleId, ExampleEntity, ExampleQuery>(jdbi, "example", serializationAdapter)

val mockAdapter: ExampleSerializationAdapter = mockk {
every { fromJson(any()) } returns createEntity("")
}
val searchRepositoryWithMock = SearchRepositoryJdbi(jdbi, "example", mockAdapter)

@BeforeEach
fun clearDatabase() {
searchRepository.search(ExampleQuery()).forEach {
Expand All @@ -31,7 +39,7 @@ class SearchRepositoryTest {
}

@Test
fun whereWorks() {
fun exampleQueryWorks() {
runBlocking {
dao.create(createEntity("hello world"))
dao.create(createEntity("world"))
Expand All @@ -43,7 +51,7 @@ class SearchRepositoryTest {
}

@Test
fun limitWorks() {
fun `limit returns correct amount of items`() {
runBlocking {
dao.create(createEntity("1"))
dao.create(createEntity("2"))
Expand All @@ -56,7 +64,7 @@ class SearchRepositoryTest {
}

@Test
fun offSetWorks() {
fun `offset skips right amount of items`() {
runBlocking {
dao.create(createEntity("hello world"))
dao.create(createEntity("world"))
Expand All @@ -69,7 +77,7 @@ class SearchRepositoryTest {
}

@Test
fun offsetAndLimitWorks() {
fun `offset and limit returns correct items`() {
runBlocking {
dao.create(createEntity("A"))
dao.create(createEntity("B"))
Expand All @@ -84,7 +92,7 @@ class SearchRepositoryTest {
}

@Test
fun emptySearchReturnsAllElements() {
fun `empty search returns all items`() {
runBlocking {
dao.create(createEntity("A"))
dao.create(createEntity("B"))
Expand All @@ -97,7 +105,7 @@ class SearchRepositoryTest {
}

@Test
fun orderAscWorks() {
fun `orderBy orders correctly`() {
runBlocking {
dao.create(createEntity("A"))
dao.create(createEntity("B"))
Expand All @@ -109,7 +117,7 @@ class SearchRepositoryTest {
}
}
@Test
fun orderDescWorksBothWays() {
fun `orderDesc flips direction`() {
runBlocking {
dao.create(createEntity("A"))
dao.create(createEntity("B"))
Expand All @@ -123,7 +131,7 @@ class SearchRepositoryTest {
}

@Test
fun domainFilterWorks() {
fun `domain filter returns correct items`() {
runBlocking {
dao.create(createEntity("A"))
dao.create(createEntity("B"))
Expand All @@ -135,4 +143,41 @@ class SearchRepositoryTest {
result.first().item.text shouldBeEqual "B"
}
}

@Test
fun `deserializer runs until limit is reached`() {
runBlocking {
dao.create(createEntity("Hello Tes"))
dao.create(createEntity("Hello Alfred"))
dao.create(createEntity("Bye Ted"))
dao.create(createEntity("Bye Alfred"))

val result = searchRepositoryWithMock.search(
ExampleQuery(
limit = 1
)
)

result shouldHaveSize 1
verify(exactly = 1) { mockAdapter.fromJson(any()) }
}
}

@Test
fun `offset skips correct amount of items`() {
runBlocking {
dao.create(createEntity("Hello Tes"))
dao.create(createEntity("Hello Alfred"))
dao.create(createEntity("Bye Ted"))
dao.create(createEntity("Bye Alfred"))

val result = searchRepository.search(
ExampleQuery(
offset = 3
)
)

result shouldHaveSize 1
}
}
}

0 comments on commit 61078c4

Please sign in to comment.