Skip to content

Commit

Permalink
fix(api): sort series properly ignoring case
Browse files Browse the repository at this point in the history
closes #85
  • Loading branch information
gotson committed Feb 5, 2020
1 parent 8f08ce8 commit 16dfe91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 16dfe91

Please sign in to comment.