Fix Manga Meta, add Manga Meta test (#245)

* Fix Manga Meta, add Manga Meta test

* Tweak assertion strings
This commit is contained in:
Mitchell Syer
2021-11-07 18:38:22 -05:00
committed by GitHub
parent 3d7953d977
commit 420d14fc37
2 changed files with 62 additions and 1 deletions
@@ -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()
@@ -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
)
}
}