mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
Fix category reorder Endpoint. Added Test for Category Reorder (#232)
* Fix category reorder Endpoint. Added Test for Category Reorder * Remove streams and use kotlin filtering
This commit is contained in:
@@ -77,11 +77,13 @@ object MangaAPI {
|
||||
get("", CategoryController::categoryList)
|
||||
post("", CategoryController::categoryCreate)
|
||||
|
||||
// The order here is important {categoryId} needs to be applied last
|
||||
// or throws a NumberFormatException
|
||||
patch("reorder", CategoryController::categoryReorder)
|
||||
|
||||
get("{categoryId}", CategoryController::categoryMangas)
|
||||
patch("{categoryId}", CategoryController::categoryModify)
|
||||
delete("{categoryId}", CategoryController::categoryDelete)
|
||||
|
||||
patch("reorder", CategoryController::categoryReorder)
|
||||
}
|
||||
|
||||
path("backup") {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package suwayomi.tachidesk.manga.controller
|
||||
|
||||
import org.jetbrains.exposed.sql.deleteAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import suwayomi.BASE_PATH
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryTable
|
||||
import suwayomi.tachidesk.server.applicationSetup
|
||||
import xyz.nulldev.ts.config.CONFIG_PREFIX
|
||||
import java.io.File
|
||||
|
||||
internal class CategoryControllerTest {
|
||||
|
||||
@BeforeEach
|
||||
internal fun setUp() {
|
||||
val dataRoot = File(BASE_PATH).absolutePath
|
||||
System.setProperty("$CONFIG_PREFIX.server.rootDir", dataRoot)
|
||||
applicationSetup()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun categoryReorder() {
|
||||
Category.createCategory("foo")
|
||||
Category.createCategory("bar")
|
||||
val cats = Category.getCategoryList()
|
||||
val foo = cats.asSequence().filter { it.name == "foo" }.first()
|
||||
val bar = cats.asSequence().filter { it.name == "bar" }.first()
|
||||
assertEquals(1, foo.order)
|
||||
assertEquals(2, bar.order)
|
||||
Category.reorderCategory(1, 2)
|
||||
val catsReordered = Category.getCategoryList()
|
||||
val fooReordered = catsReordered.asSequence().filter { it.name == "foo" }.first()
|
||||
val barReordered = catsReordered.asSequence().filter { it.name == "bar" }.first()
|
||||
assertEquals(2, fooReordered.order)
|
||||
assertEquals(1, barReordered.order)
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
internal fun tearDown() {
|
||||
transaction {
|
||||
CategoryTable.deleteAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user