add apitest

This commit is contained in:
2026-09-17 21:12:47 +03:00
parent c062588dd1
commit 597cde3f58
3 changed files with 86 additions and 0 deletions
+3
View File
@@ -39,6 +39,9 @@ kotlin {
implementation(kotlin("test")) implementation(kotlin("test"))
} }
} }
desktopTest.dependencies {
implementation(kotlin("test"))
}
val wasmJsMain by getting { val wasmJsMain by getting {
dependencies { dependencies {
implementation(libs.sqldelight.web.driver) implementation(libs.sqldelight.web.driver)
@@ -0,0 +1,18 @@
package ru.shadowsparky.vbox.shared
import kotlinx.coroutines.runBlocking
import ru.shadowsparky.domain.Log
import ru.shadowsparky.koin
import ru.shadowsparky.vbox.shared.domain.VideoApi
import kotlin.test.Test
class ApiTest : BaseTest() {
private val videoApi by lazy { koin.get<VideoApi>() }
private val log by lazy { koin.get<Log>() }
@Test
fun test(): Unit = runBlocking {
val videos = videoApi.fetchNewVideos("Южный парк")
log.d("GetVideosTest", videos.items.joinToString())
}
}
@@ -0,0 +1,65 @@
package ru.shadowsparky.vbox.shared
import kotlinx.coroutines.runBlocking
import org.koin.core.annotation.KoinApplication
import org.koin.core.annotation.Module
import org.koin.core.annotation.Single
import org.koin.core.context.stopKoin
import org.koin.plugin.module.dsl.startKoin
import ru.shadowsparky.domain.AppConfig
import ru.shadowsparky.http.domain.TokenInfo
import ru.shadowsparky.koin
import ru.shadowsparky.vbox.shared.domain.AuthTokenRepository
import ru.shadowsparky.vbox.shared.domain.TokenRequest
import ru.shadowsparky.vbox.shared.domain.model.LoginInfo
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
abstract class BaseTest {
private lateinit var tokenInfo: TokenInfo
private val authRepository by lazy { koin.get<AuthTokenRepository>() }
@BeforeTest
fun before() {
startKoin<VBox>()
runBlocking {
tokenInfo = authRepository.login(
LoginInfo(
System.getenv("VBOX_LOGIN"),
System.getenv("VBOX_PASSWORD")
)
)
onBefore()
}
}
@AfterTest
fun after() {
runBlocking {
authRepository.revoke(TokenRequest(tokenInfo.refresh!!))
onAfter()
}
stopKoin()
}
open suspend fun onAfter() {}
open suspend fun onBefore() {}
}
@KoinApplication(modules = [AppModule::class])
object VBox
@Module
class AppModule {
@Single
fun provideAppConfig(): AppConfig {
return object : AppConfig {
override val debug = true
override val appId = "VBoxTest"
override val versionCode = 1L
override val versionName = "1.0"
}
}
}