-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
963053b
commit 095f777
Showing
5 changed files
with
136 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/test/kotlin/no/liflig/documentstore/DomainFilterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package no.liflig.documentstore | ||
|
||
import io.kotest.matchers.collections.shouldHaveSize | ||
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 | ||
import no.liflig.documentstore.examples.ExampleEntity | ||
import no.liflig.documentstore.examples.ExampleQuery | ||
import no.liflig.documentstore.examples.ExampleSerializationAdapter | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class DomainFilterTest { | ||
val jdbi = createTestDatabase() | ||
|
||
val serializationAdapter = ExampleSerializationAdapter() | ||
val dao = CrudDaoJdbi(jdbi, "example", serializationAdapter) | ||
|
||
val searchRepository = SearchRepositoryJdbi(jdbi, "example", serializationAdapter) | ||
|
||
val mockAdapter: ExampleSerializationAdapter = mockk { | ||
every { fromJson(any()) } returns ExampleEntity.create("") | ||
} | ||
val searchRepositoryWithMock = SearchRepositoryJdbi(jdbi, "example", mockAdapter) | ||
|
||
@BeforeEach | ||
fun clearDatabase() { | ||
searchRepository.search(ExampleQuery()).forEach { | ||
dao.delete(it.item.id, it.version) | ||
} | ||
} | ||
@Test | ||
fun domainFilterWorks() { | ||
runBlocking { | ||
dao.create(ExampleEntity.create("Hello Tes")) | ||
dao.create(ExampleEntity.create("Hello Alfred")) | ||
dao.create(ExampleEntity.create("Bye Ted")) | ||
dao.create(ExampleEntity.create("Bye Alfred")) | ||
|
||
searchRepository.search( | ||
ExampleQuery( | ||
domainFilter = { it.text.contains("Hello") }, | ||
) | ||
) shouldHaveSize 2 | ||
} | ||
} | ||
|
||
@Test | ||
fun limitRunsDeserializingCorrectAmountOfTimes() { | ||
runBlocking { | ||
dao.create(ExampleEntity.create("Hello Tes")) | ||
dao.create(ExampleEntity.create("Hello Alfred")) | ||
dao.create(ExampleEntity.create("Bye Ted")) | ||
dao.create(ExampleEntity.create("Bye Alfred")) | ||
|
||
val result = searchRepositoryWithMock.search( | ||
ExampleQuery( | ||
limit = 1 | ||
) | ||
) | ||
|
||
result shouldHaveSize 1 | ||
verify(exactly = 1) { mockAdapter.fromJson(any()) } | ||
} | ||
} | ||
|
||
@Test | ||
fun offSetWorks() { | ||
runBlocking { | ||
dao.create(ExampleEntity.create("Hello Tes")) | ||
dao.create(ExampleEntity.create("Hello Alfred")) | ||
dao.create(ExampleEntity.create("Bye Ted")) | ||
dao.create(ExampleEntity.create("Bye Alfred")) | ||
|
||
val result = searchRepository.search( | ||
ExampleQuery( | ||
offset = 3 | ||
) | ||
) | ||
|
||
result shouldHaveSize 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters