From c7fb2817fc1518c05e05e269f0ca3cff8f549002 Mon Sep 17 00:00:00 2001 From: Cilly Leang Date: Mon, 16 Feb 2026 21:46:31 +1100 Subject: [PATCH] refactor(api/rest): create internal constructor for tests --- .../commonMain/kotlin/moe/lava/neon/api/ApiClient.kt | 11 ++++++++--- .../kotlin/moe/lava/neon/core/di/CoreModule.kt | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/rest/src/commonMain/kotlin/moe/lava/neon/api/ApiClient.kt b/api/rest/src/commonMain/kotlin/moe/lava/neon/api/ApiClient.kt index 371b589..bdad65b 100644 --- a/api/rest/src/commonMain/kotlin/moe/lava/neon/api/ApiClient.kt +++ b/api/rest/src/commonMain/kotlin/moe/lava/neon/api/ApiClient.kt @@ -20,7 +20,12 @@ import kotlinx.serialization.ExperimentalSerializationApi import moe.lava.neon.common.captcha.CaptchaRequest import moe.lava.neon.common.captcha.CaptchaResponse -class ApiClient { +class ApiClient internal constructor( + engine: HttpClientEngine, + assertSuccess: Boolean, +) { + constructor() : this(HttpClient().engine, true) + private val logger = Logger.withTag("neon.core.api/client") private var captchaHandler: (suspend (CaptchaRequest) -> CaptchaResponse)? = null @@ -30,8 +35,8 @@ class ApiClient { } @OptIn(ExperimentalSerializationApi::class) - internal val client = HttpClient { - expectSuccess = true + internal val client = HttpClient(engine) { + expectSuccess = assertSuccess install(ContentNegotiation) { json(ApiConstants.json) } diff --git a/core/src/commonMain/kotlin/moe/lava/neon/core/di/CoreModule.kt b/core/src/commonMain/kotlin/moe/lava/neon/core/di/CoreModule.kt index 6e79c70..600b7f2 100644 --- a/core/src/commonMain/kotlin/moe/lava/neon/core/di/CoreModule.kt +++ b/core/src/commonMain/kotlin/moe/lava/neon/core/di/CoreModule.kt @@ -11,7 +11,7 @@ import org.koin.dsl.module import org.koin.plugin.module.dsl.single val coreModule = module { - single() + factory { ApiClient() } single() single()