test: more FTS tests

This commit is contained in:
Gauthier Roebroeck 2021-08-02 12:07:28 +08:00
parent 01f293d606
commit d2a2096aa8

View file

@ -29,6 +29,7 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.test.context.junit.jupiter.SpringExtension
import java.net.URL
@ExtendWith(SpringExtension::class)
@SpringBootTest
@ -403,6 +404,30 @@ class BookDtoDaoTest(
assertThat(found.map { it.name }).containsExactly("X-Men", "Another X-Men adventure")
}
@Test
fun `given books when searching by single letter then results are ordered by rank`() {
// given
seriesLifecycle.addBooks(
series,
listOf(
makeBook("J", seriesId = series.id, libraryId = library.id),
makeBook("Adventures of J. J.", seriesId = series.id, libraryId = library.id),
makeBook("Jackal", seriesId = series.id, libraryId = library.id),
)
)
// when
val found = bookDtoDao.findAll(
BookSearchWithReadProgress(searchTerm = "j"),
user.id,
UnpagedSorted(Sort.by("relevance")),
).content
// then
assertThat(found).hasSize(2)
assertThat(found.map { it.name }).containsExactly("J", "Adventures of J. J.")
}
@Test
fun `when searching by unknown field then empty result are returned and no exception is thrown`() {
assertThatCode {
@ -417,4 +442,25 @@ class BookDtoDaoTest(
assertThat(found).hasSize(0)
}.doesNotThrowAnyException()
}
@Test
fun `given books in CJK when searching by CJK term then results are ordered by rank`() {
// given
seriesLifecycle.addBooks(
series,
listOf(
makeBook("[不道德公會][河添太一 ][東立]Vol.04-搬运", seriesId = series.id, libraryId = library.id, url = URL("file:/file.cbz")),
)
)
// when
val found = bookDtoDao.findAll(
BookSearchWithReadProgress(searchTerm = "不道德"),
user.id,
UnpagedSorted(Sort.by("relevance")),
).content
// then
assertThat(found).hasSize(1)
}
}