Updated on 2026-08-14
This commit is contained in:
parent
7d9c12f1bc
commit
690318cd8d
10 changed files with 80 additions and 65 deletions
|
|
@ -13,8 +13,9 @@ import com.tangem.datasource.api.common.config.ApiConfig.Companion.RELEASE_BUILD
|
|||
import com.tangem.datasource.api.common.visa.TangemVisaAuthProvider
|
||||
import com.tangem.lib.auth.ExpressAuthProvider
|
||||
import com.tangem.lib.auth.StakeKitAuthProvider
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.ProviderSuspend
|
||||
import com.tangem.utils.version.AppVersionProvider
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
|
@ -37,6 +38,8 @@ private val API_CONFIGS = setOf(
|
|||
Express(configManager, expressAuthProvider, appVersionProvider),
|
||||
TangemTech(appVersionProvider, appAuthProvider),
|
||||
StakeKit(stakeKitAuthProvider),
|
||||
TangemVisaAuth(),
|
||||
TangemVisa(visaAuthProvider),
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +59,7 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
every { stakeKitAuthProvider.getApiKey() } returns STAKE_KIT_API_KEY
|
||||
every { appAuthProvider.getCardId() } returns APP_CARD_ID
|
||||
every { appAuthProvider.getCardPublicKey() } returns APP_CARD_PUBLIC_KEY
|
||||
every { runBlocking { visaAuthProvider.getAuthHeader() } } returns VISA_AUTH_HEADER // TODO
|
||||
coEvery { visaAuthProvider.getAuthHeader() } returns VISA_AUTH_HEADER
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -66,8 +69,8 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
Truth.assertThat(actual.environment).isEqualTo(model.expected.environment)
|
||||
Truth.assertThat(actual.baseUrl).isEqualTo(model.expected.baseUrl)
|
||||
|
||||
Truth.assertThat(actual.headers.mapValues { it.value() })
|
||||
.isEqualTo(model.expected.headers.mapValues { it.value() })
|
||||
Truth.assertThat(actual.headers.mapValues { runBlocking { it.value() } })
|
||||
.isEqualTo(model.expected.headers.mapValues { runBlocking { it.value() } })
|
||||
}
|
||||
|
||||
data class Model(val id: ApiConfig.ID, val expected: ApiEnvironmentConfig)
|
||||
|
|
@ -122,23 +125,23 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
else -> error("Unknown build type [${BuildConfig.BUILD_TYPE}]")
|
||||
},
|
||||
headers = mapOf(
|
||||
"api-key" to Provider {
|
||||
"api-key" to ProviderSuspend {
|
||||
if (environment == ApiEnvironment.PROD) {
|
||||
MockEnvironmentConfigStorage.EXPRESS_API_KEY
|
||||
} else {
|
||||
MockEnvironmentConfigStorage.EXPRESS_DEV_API_KEY
|
||||
}
|
||||
},
|
||||
"user-id" to Provider { EXPRESS_USER_ID },
|
||||
"session-id" to Provider { EXPRESS_SESSION_ID },
|
||||
"refcode" to Provider { EXPRESS_REF_CODE },
|
||||
"version" to Provider { VERSION_NAME },
|
||||
"platform" to Provider { "android" },
|
||||
"language" to Provider { Locale.getDefault().language.checkHeaderValueOrEmpty() },
|
||||
"timezone" to Provider {
|
||||
"user-id" to ProviderSuspend { EXPRESS_USER_ID },
|
||||
"session-id" to ProviderSuspend { EXPRESS_SESSION_ID },
|
||||
"refcode" to ProviderSuspend { EXPRESS_REF_CODE },
|
||||
"version" to ProviderSuspend { VERSION_NAME },
|
||||
"platform" to ProviderSuspend { "android" },
|
||||
"language" to ProviderSuspend { Locale.getDefault().language.checkHeaderValueOrEmpty() },
|
||||
"timezone" to ProviderSuspend {
|
||||
TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT).checkHeaderValueOrEmpty()
|
||||
},
|
||||
"device" to Provider { "${Build.MANUFACTURER} ${Build.MODEL}".checkHeaderValueOrEmpty() },
|
||||
"device" to ProviderSuspend { "${Build.MANUFACTURER} ${Build.MODEL}".checkHeaderValueOrEmpty() },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -151,15 +154,15 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
environment = ApiEnvironment.PROD,
|
||||
baseUrl = "https://api.tangem-tech.com/v1/",
|
||||
headers = mapOf(
|
||||
"card_id" to Provider { APP_CARD_ID },
|
||||
"card_public_key" to Provider { APP_CARD_PUBLIC_KEY },
|
||||
"version" to Provider { VERSION_NAME },
|
||||
"platform" to Provider { "android" },
|
||||
"language" to Provider { Locale.getDefault().language.checkHeaderValueOrEmpty() },
|
||||
"timezone" to Provider {
|
||||
"card_id" to ProviderSuspend { APP_CARD_ID },
|
||||
"card_public_key" to ProviderSuspend { APP_CARD_PUBLIC_KEY },
|
||||
"version" to ProviderSuspend { VERSION_NAME },
|
||||
"platform" to ProviderSuspend { "android" },
|
||||
"language" to ProviderSuspend { Locale.getDefault().language.checkHeaderValueOrEmpty() },
|
||||
"timezone" to ProviderSuspend {
|
||||
TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT).checkHeaderValueOrEmpty()
|
||||
},
|
||||
"device" to Provider { "${Build.MANUFACTURER} ${Build.MODEL}".checkHeaderValueOrEmpty() },
|
||||
"device" to ProviderSuspend { "${Build.MANUFACTURER} ${Build.MODEL}".checkHeaderValueOrEmpty() },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -172,8 +175,8 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
environment = ApiEnvironment.PROD,
|
||||
baseUrl = "https://api.stakek.it/v1/",
|
||||
headers = mapOf(
|
||||
"X-API-KEY" to Provider { STAKE_KIT_API_KEY },
|
||||
"accept" to Provider { "application/json" },
|
||||
"X-API-KEY" to ProviderSuspend { STAKE_KIT_API_KEY },
|
||||
"accept" to ProviderSuspend { "application/json" },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -196,7 +199,7 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
environment = ApiEnvironment.PROD,
|
||||
baseUrl = "https://bff.tangem.com/",
|
||||
headers = mapOf(
|
||||
"Authorization" to Provider { VISA_AUTH_HEADER },
|
||||
"Authorization" to ProviderSuspend { VISA_AUTH_HEADER },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue