add apitest
This commit is contained in:
@@ -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())
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user