Skip to content

Commit

Permalink
Fix category reorder Endpoint. Added Test for Category Reorder (#232)
Browse files Browse the repository at this point in the history
* Fix category reorder Endpoint. Added Test for Category Reorder

* Remove streams and use kotlin filtering
  • Loading branch information
ntbm authored Oct 30, 2021
1 parent 82837e3 commit 0ee7494
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
}

0 comments on commit 0ee7494

Please sign in to comment.