diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt index f6a4b2846..15cc96561 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt @@ -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") { diff --git a/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/CategoryControllerTest.kt b/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/CategoryControllerTest.kt new file mode 100644 index 000000000..c3ff768dc --- /dev/null +++ b/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/CategoryControllerTest.kt @@ -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() + } + } +}