Skip to content

Commit

Permalink
Fix Manga Meta, add Manga Meta test (Suwayomi#245)
Browse files Browse the repository at this point in the history
* Fix Manga Meta, add Manga Meta test

* Tweak assertion strings
  • Loading branch information
Syer10 authored Nov 7, 2021
1 parent 3d7953d commit 420d14f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ object Manga {

fun modifyMangaMeta(mangaId: Int, key: String, value: String) {
transaction {
val manga = MangaMetaTable.select { (MangaTable.id eq mangaId) }
val manga = MangaTable.select { MangaTable.id eq mangaId }
.first()[MangaTable.id]
val meta =
transaction { MangaMetaTable.select { (MangaMetaTable.ref eq manga) and (MangaMetaTable.key eq key) } }.firstOrNull()
Expand Down
61 changes: 61 additions & 0 deletions server/src/test/kotlin/suwayomi/tachidesk/manga/impl/MangaTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package suwayomi.tachidesk.manga.impl

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import suwayomi.tachidesk.manga.model.table.MangaMetaTable
import suwayomi.tachidesk.manga.model.table.MangaTable
import suwayomi.tachidesk.test.ApplicationTest
import suwayomi.tachidesk.test.clearTables
import suwayomi.tachidesk.test.createLibraryManga

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MangaTest : ApplicationTest() {
@Test
fun getMangaMeta() {
val metaManga = createLibraryManga("META_TEST")
val emptyMeta = Manga.getMangaMetaMap(metaManga).size
assertEquals(0, emptyMeta, "Default Manga meta should be empty at start")

Manga.modifyMangaMeta(metaManga, "test", "value")
assertEquals(1, Manga.getMangaMetaMap(metaManga).size, "Manga meta should have one member")
assertEquals("value", Manga.getMangaMetaMap(metaManga)["test"], "Manga meta use the value 'value' for key 'test'")

Manga.modifyMangaMeta(metaManga, "test", "newValue")
assertEquals(
1,
Manga.getMangaMetaMap(metaManga).size,
"Manga meta should still only have one pair"
)
assertEquals(
"newValue", Manga.getMangaMetaMap(metaManga)["test"],
"Manga meta with key 'test' should use the value `newValue`"
)

Manga.modifyMangaMeta(metaManga, "test2", "value2")
assertEquals(
2, Manga.getMangaMetaMap(metaManga).size,
"Manga Meta should have an additional pair"
)
assertEquals(
"value2", Manga.getMangaMetaMap(metaManga)["test2"],
"Manga Meta for key 'test2' should be 'value2'"
)
}

@AfterEach
internal fun tearDown() {
clearTables(
MangaMetaTable,
MangaTable
)
}
}

0 comments on commit 420d14f

Please sign in to comment.