refactor(api/rest): create internal constructor for tests
This commit is contained in:
parent
db1f469a4f
commit
c7fb2817fc
2 changed files with 9 additions and 4 deletions
|
|
@ -20,7 +20,12 @@ import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
import moe.lava.neon.common.captcha.CaptchaRequest
|
import moe.lava.neon.common.captcha.CaptchaRequest
|
||||||
import moe.lava.neon.common.captcha.CaptchaResponse
|
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 val logger = Logger.withTag("neon.core.api/client")
|
||||||
|
|
||||||
private var captchaHandler: (suspend (CaptchaRequest) -> CaptchaResponse)? = null
|
private var captchaHandler: (suspend (CaptchaRequest) -> CaptchaResponse)? = null
|
||||||
|
|
@ -30,8 +35,8 @@ class ApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
internal val client = HttpClient {
|
internal val client = HttpClient(engine) {
|
||||||
expectSuccess = true
|
expectSuccess = assertSuccess
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
json(ApiConstants.json)
|
json(ApiConstants.json)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import org.koin.dsl.module
|
||||||
import org.koin.plugin.module.dsl.single
|
import org.koin.plugin.module.dsl.single
|
||||||
|
|
||||||
val coreModule = module {
|
val coreModule = module {
|
||||||
single<ApiClient>()
|
factory { ApiClient() }
|
||||||
single<AppSettings>()
|
single<AppSettings>()
|
||||||
|
|
||||||
single<AuthRepository>()
|
single<AuthRepository>()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue