fix(api): sort series properly ignoring case

closes #85
This commit is contained in:
Gauthier Roebroeck 2020-02-05 13:35:12 +08:00
parent 8f08ce82e1
commit 16dfe91140
2 changed files with 20 additions and 1 deletions

View file

@ -62,7 +62,7 @@ class SeriesController(
val pageRequest = PageRequest.of(
page.pageNumber,
page.pageSize,
if (page.sort.isSorted) page.sort
if (page.sort.isSorted) Sort.by(page.sort.map { it.ignoreCase() }.toList())
else Sort.by(Sort.Order.asc("metadata.titleSort").ignoreCase())
)

View file

@ -7,6 +7,7 @@ import org.gotson.komga.domain.model.makeLibrary
import org.gotson.komga.domain.model.makeSeries
import org.gotson.komga.domain.persistence.LibraryRepository
import org.gotson.komga.domain.persistence.SeriesRepository
import org.hamcrest.Matchers
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
@ -80,6 +81,24 @@ class SeriesControllerTest(
jsonPath("$.content[1].metadata.title") { value("Beta") }
}
}
@Test
@WithMockCustomUser
fun `given series when requesting via api then series are sorted insensitive of case`() {
val series = listOf("a", "b", "B", "C").map { makeSeries(it).also { it.library = library } }
seriesRepository.saveAll(series)
mockMvc.get("/api/v1/series") {
param("sort", "metadata.titleSort,asc")
}
.andExpect {
status { isOk }
jsonPath("$.content[0].metadata.title") { value("a") }
jsonPath("$.content[1].metadata.title") { value(Matchers.equalToIgnoringCase("b")) }
jsonPath("$.content[2].metadata.title") { value(Matchers.equalToIgnoringCase("b")) }
jsonPath("$.content[3].metadata.title") { value("C") }
}
}
}
@Nested