Skip to content

Commit 8c99dbd

Browse files
committed
Fixed AppstoreClientTest
1 parent ed2ea23 commit 8c99dbd

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/api/AppstoreClient.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
package io.rebble.cobble.shared.api
22

3-
import io.ktor.client.HttpClient
4-
import io.ktor.client.call.body
5-
import io.ktor.client.request.delete
6-
import io.ktor.client.request.get
7-
import io.ktor.client.request.headers
8-
import io.ktor.client.request.put
9-
import io.ktor.http.HttpHeaders
3+
import io.ktor.client.*
4+
import io.ktor.client.call.*
5+
import io.ktor.client.request.*
6+
import io.ktor.http.*
107
import io.rebble.cobble.shared.domain.api.appstore.LockerEntry
118
import org.koin.core.component.KoinComponent
12-
import org.koin.core.component.inject
139

1410
class AppstoreClient(
1511
val baseUrl: String,
16-
private val token: String
12+
private val token: String,
13+
private val client: HttpClient,
1714
): KoinComponent {
1815
private val version = "v1"
19-
private val client: HttpClient by inject()
2016

2117
suspend fun getLocker(): List<LockerEntry> {
2218
val res = client.get("$baseUrl/$version/locker") {
@@ -34,7 +30,7 @@ class AppstoreClient(
3430
return body["applications"] ?: emptyList()
3531
}
3632

37-
suspend fun addToLocker(uuid: String) {
33+
suspend fun addToLocker(uuid: String) {
3834
val res = client.put("$baseUrl/$version/locker/$uuid") {
3935
headers {
4036
append(HttpHeaders.Accept, "application/json")

android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/api/RWS.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.StateFlow
99
import kotlinx.coroutines.flow.map
1010
import kotlinx.coroutines.flow.stateIn
1111
import org.koin.core.component.KoinComponent
12+
import org.koin.core.component.get
1213
import org.koin.core.component.inject
1314
import org.koin.core.qualifier.named
1415

@@ -18,7 +19,7 @@ object RWS: KoinComponent {
1819
private val scope = CoroutineScope(Dispatchers.Default)
1920

2021
val appstoreClientFlow = token.map {
21-
it.tokenOrNull?.let { t -> AppstoreClient("https://appstore-api.$domainSuffix/api", t) }
22+
it.tokenOrNull?.let { t -> AppstoreClient("https://appstore-api.$domainSuffix/api", t, get()) }
2223
}.stateIn(scope, SharingStarted.Eagerly, null)
2324
val authClientFlow = token.map {
2425
it.tokenOrNull?.let { t -> AuthClient("https://auth.$domainSuffix/api", t) }

android/shared/src/commonTest/kotlin/io/rebble/cobble/domain/api/AppstoreClientTest.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package io.rebble.cobble.domain.api
22

3+
import io.ktor.client.*
34
import io.ktor.client.engine.mock.MockEngine
45
import io.ktor.client.engine.mock.respond
6+
import io.ktor.client.plugins.contentnegotiation.*
57
import io.ktor.http.HttpHeaders
68
import io.ktor.http.HttpMethod
79
import io.ktor.http.HttpStatusCode
810
import io.ktor.http.headersOf
11+
import io.ktor.serialization.kotlinx.json.*
12+
import io.ktor.utils.io.core.*
913
import io.rebble.cobble.shared.api.AppstoreClient
1014
import io.rebble.libpebblecommon.util.runBlocking
1115
import kotlin.test.Test
@@ -1418,7 +1422,7 @@ class AppstoreClientTest {
14181422
]
14191423
}
14201424
""".trimIndent()
1421-
val mockEngine = MockEngine { request ->
1425+
MockEngine { request ->
14221426
when (request.url.encodedPath) {
14231427
"/api/v1/locker" -> {
14241428
if (request.headers[HttpHeaders.Authorization] != "Bearer x") {
@@ -1442,9 +1446,16 @@ class AppstoreClientTest {
14421446
}
14431447
else -> error("Unhandled ${request.url.encodedPath}")
14441448
}
1449+
}.use { engine ->
1450+
val httpClient = HttpClient(engine) {
1451+
install(ContentNegotiation) {
1452+
json() // Example: Register JSON content transformation
1453+
// Add more transformations as needed for other content types
1454+
}
1455+
}
1456+
val client = AppstoreClient("https://appstore-api.rebble.io/api", "x", httpClient)
1457+
val locker = client.getLocker()
1458+
assertEquals(13, locker.size)
14451459
}
1446-
val client = AppstoreClient("https://appstore-api.rebble.io/api", "x")
1447-
val locker = client.getLocker()
1448-
assertEquals(13, locker.size)
14491460
}
14501461
}

0 commit comments

Comments
 (0)