Files
Suwayomi-Server/server/src/test/kotlin/suwayomi/tachidesk/test/TestUtils.kt
Mitchell Syer 2d535b44d8 Extension API 1.6 (#2120)
* Non-Extension Index changes for 1.6

* Changelog

* Minor fixes

* Implement extension store

* Test build fix

* Docs

* Simplify fetching manga and chapters

* Use EMPTY JsonObject

* Update docs/Configuring-Suwayomi‐Server.md

Co-authored-by: Constantin Piber <59023762+cpiber@users.noreply.github.com>

* Improve Fetch Extension Store

* Fixes

* Simplify deprecated isNsfw in SourceQuery

* Simplify ContentRating in Source.kt

* Simplify isNsfw in SourceType

* No magic numbers for ContentRating, improves safety for future versions of extension api

* Fix SearchTest

* Lint

* Lint

* Optimize imports and fix unchecked cast warning

* Proper extension store queries

* Optimize import fixes

* Add ContentRatingFilter

* Improve extension store sync

* fix: re-sync (#2121)

* Lint

* Add ExtenionStores to the fetchExtensions result since its possible for the stores to change.

* Use a single version of ContentRating

* Exclude ServerConfig.extensionStores from GraphQL

* Use syncDbToPrefs in ExtensionStoreMutation

* Optimize Imports

* Update server/server-config/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt

Co-authored-by: Constantin Piber <59023762+cpiber@users.noreply.github.com>

* Remove replaceWith and add specific description for GQL APIs

* Include OkHttp ZSTD

* Update to latest Mihon extension lib

* Fix latest Mihon Extension Lib

* Lint

* Optimize imports

* Lint

* Review fixes

* Add a index to extesnion table store url

* Lint

---------

Co-authored-by: Constantin Piber <59023762+cpiber@users.noreply.github.com>
2026-06-27 13:39:28 -04:00

81 lines
2.4 KiB
Kotlin

package suwayomi.tachidesk.test
/*
* 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 ch.qos.logback.classic.Level
import eu.kanade.tachiyomi.source.model.SManga
import io.github.oshai.kotlinlogging.DelegatingKLogger
import io.github.oshai.kotlinlogging.KotlinLogging
import org.jetbrains.exposed.v1.core.dao.id.IdTable
import org.jetbrains.exposed.v1.jdbc.batchInsert
import org.jetbrains.exposed.v1.jdbc.deleteAll
import org.jetbrains.exposed.v1.jdbc.insertAndGetId
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
import org.slf4j.Logger
import suwayomi.tachidesk.manga.model.table.ChapterTable
import suwayomi.tachidesk.manga.model.table.MangaTable
fun setLoggingEnabled(enabled: Boolean = true) {
val logger = ((KotlinLogging.logger(Logger.ROOT_LOGGER_NAME) as DelegatingKLogger<*>).underlyingLogger as ch.qos.logback.classic.Logger)
logger.level =
if (enabled) {
Level.DEBUG
} else {
Level.ERROR
}
}
const val BASE_PATH = "build/tmp/TestDesk"
fun createLibraryManga(_title: String): Int =
transaction {
MangaTable
.insertAndGetId {
it[title] = _title
it[url] = _title
it[sourceReference] = 1
it[inLibrary] = true
}.value
}
fun createSMangas(count: Int): List<SManga> =
(0 until count).map {
SManga.create().apply {
title = "Manga $it"
url = "https://$title"
}
}
fun createChapters(
mangaId: Int,
amount: Int,
read: Boolean,
start: Int = 1,
) {
val list = listOf((0 until amount)).flatten().map { it + start }
transaction {
ChapterTable
.batchInsert(list) {
this[ChapterTable.url] = "$it"
this[ChapterTable.name] = "$it"
this[ChapterTable.sourceOrder] = it
this[ChapterTable.isRead] = read
this[ChapterTable.manga] = mangaId
this[ChapterTable.memo] = "{}"
}
}
}
fun clearTables(vararg tables: IdTable<*>) {
transaction {
for (table in tables) {
table.deleteAll()
}
}
}