Skip to content

Commit

Permalink
Make tests also for domain filtered search
Browse files Browse the repository at this point in the history
  • Loading branch information
TrulsStenrud committed Aug 29, 2023
1 parent b6490d4 commit f04d7f9
Showing 1 changed file with 61 additions and 5 deletions.
66 changes: 61 additions & 5 deletions src/test/kotlin/no/liflig/documentstore/SearchRepositoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SearchRepositoryTest {
val mockAdapter: ExampleSerializationAdapter = mockk {
every { fromJson(any()) } returns createEntity("")
}
val searchRepositoryWithMock = SearchRepositoryJdbi<ExampleId, ExampleEntity, ExampleQuery>(jdbi, "example", mockAdapter)
val searchRepositoryWithMock =
SearchRepositoryJdbi<ExampleId, ExampleEntity, ExampleQuery>(jdbi, "example", mockAdapter)

@BeforeEach
fun clearDatabase() {
Expand Down Expand Up @@ -144,6 +145,21 @@ class SearchRepositoryTest {
}
}

@Test
fun `orderBy orders correctly for domain filtered search`() {
runBlocking {
dao.create(createEntity("A"))
dao.create(createEntity("B"))
dao.create(createEntity("C"))

val result =
searchRepository.searchDomainFiltered(ExampleQuery(orderBy = "data->>'text'", orderDesc = false)) { true }
.map { it.item.text }

result shouldBeEqual listOf("A", "B", "C")
}
}

@Test
fun `orderDesc flips direction`() {
runBlocking {
Expand All @@ -159,6 +175,24 @@ class SearchRepositoryTest {
}
}

@Test
fun `orderDesc flips direction in fomain filtered search`() {
runBlocking {
dao.create(createEntity("A"))
dao.create(createEntity("B"))
dao.create(createEntity("C"))

val result =
searchRepository.searchDomainFiltered(ExampleQuery(orderBy = "data->>'text'", orderDesc = false)) { true }
.map { it.item.id }
val resul2 =
searchRepository.searchDomainFiltered(ExampleQuery(orderBy = "data->>'text'", orderDesc = true)) { true }
.map { it.item.id }

result shouldBeEqual resul2.asReversed()
}
}

@Test
fun `domain filter returns correct items`() {
runBlocking {
Expand All @@ -174,26 +208,28 @@ class SearchRepositoryTest {
}

@Test
fun `deserializer runs until limit is reached`() {
fun `deserializer runs exactly once when one match is found`() {
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(
val result = searchRepositoryWithMock.searchDomainFiltered(
ExampleQuery(
limit = 1
)
)
) {
true
}

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

@Test
fun `offset skips correct amount of items`() {
fun `offset works as intended`() {
runBlocking {
dao.create(createEntity("Hello Tes"))
dao.create(createEntity("Hello Alfred"))
Expand All @@ -209,4 +245,24 @@ class SearchRepositoryTest {
result shouldHaveSize 1
}
}

@Test
fun `offset works as intended for search with domain filter`() {
runBlocking {
dao.create(createEntity("Hello Tes"))
dao.create(createEntity("Hello Alfred"))
dao.create(createEntity("Bye Ted"))
dao.create(createEntity("Bye Alfred"))

val result = searchRepository.searchDomainFiltered(
ExampleQuery(
offset = 3
)
) {
true
}

result shouldHaveSize 1
}
}
}

0 comments on commit f04d7f9

Please sign in to comment.