Updated on 2026-08-14
This commit is contained in:
parent
aed32a47f1
commit
58e26ca5e6
8 changed files with 139 additions and 14 deletions
|
|
@ -6,6 +6,7 @@ import androidx.compose.ui.test.junit4.createEmptyComposeRule
|
|||
import androidx.compose.ui.test.printToLog
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import com.kaspersky.components.alluresupport.interceptors.step.ScreenshotStepInterceptor
|
||||
import com.kaspersky.components.alluresupport.withForcedAllureSupport
|
||||
|
|
@ -19,6 +20,7 @@ import com.tangem.common.rules.ApiEnvironmentRule
|
|||
import com.tangem.datasource.api.common.config.managers.ApiConfigsManager
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
import com.tangem.datasource.utils.WireMockRedirectInterceptor
|
||||
import com.tangem.domain.promo.PromoRepository
|
||||
import com.tangem.domain.promo.models.PromoId
|
||||
import com.tangem.tap.MainActivity
|
||||
|
|
@ -86,6 +88,9 @@ abstract class BaseTestCase : TestCase(
|
|||
additionalAfterSection: () -> Unit = {},
|
||||
) = before {
|
||||
Allure.label(ALLURE_LABEL_NAME, ALLURE_LABEL_VALUE)
|
||||
// Setup WireMock redirect for CI with local WireMock instances
|
||||
val wiremockUrl = InstrumentationRegistry.getArguments().getString(WIREMOCK_BASE_URL_ARG)
|
||||
WireMockRedirectInterceptor.overriddenBaseUrl = wiremockUrl
|
||||
hiltRule.inject()
|
||||
runBlocking {
|
||||
appPreferencesStore.editData { mutablePreferences ->
|
||||
|
|
@ -147,4 +152,8 @@ abstract class BaseTestCase : TestCase(
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val WIREMOCK_BASE_URL_ARG = "wiremockBaseUrl"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +1,31 @@
|
|||
package com.tangem.common.utils
|
||||
|
||||
import com.tangem.datasource.utils.WireMockRedirectInterceptor
|
||||
import okhttp3.*
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
|
||||
private const val DEFAULT_WIREMOCK_URL = "[REDACTED_ENV_URL]"
|
||||
|
||||
/**
|
||||
* Returns the WireMock base URL to use.
|
||||
*/
|
||||
private fun getWireMockBaseUrl(): String =
|
||||
WireMockRedirectInterceptor.overriddenBaseUrl ?: DEFAULT_WIREMOCK_URL
|
||||
|
||||
/**
|
||||
* Method uses to set WireMock scenario state
|
||||
* @param scenarioName Name of the scenario to modify
|
||||
* @param state The target state to set (must be one of the scenario's possibleStates)
|
||||
* @param baseUrl WireMock base URL
|
||||
* @param baseUrl WireMock base URL (defaults to local override if set, otherwise remote)
|
||||
* @return true if state was set successfully, false otherwise
|
||||
*/
|
||||
fun setWireMockScenarioState(
|
||||
scenarioName: String,
|
||||
state: String,
|
||||
baseUrl: String = "[REDACTED_ENV_URL]"
|
||||
baseUrl: String = getWireMockBaseUrl()
|
||||
): Boolean {
|
||||
Timber.i("=== WireMock Scenario Set ===")
|
||||
Timber.i("Setting scenario '$scenarioName' to state: $state")
|
||||
|
|
@ -46,8 +55,9 @@ fun setWireMockScenarioState(
|
|||
|
||||
/**
|
||||
* Method checks accessibility of WireMock
|
||||
* @param baseUrl WireMock base URL (defaults to local override if set, otherwise remote)
|
||||
*/
|
||||
fun checkWireMockStatus(baseUrl: String = "[REDACTED_ENV_URL]"): Boolean {
|
||||
fun checkWireMockStatus(baseUrl: String = getWireMockBaseUrl()): Boolean {
|
||||
val client = OkHttpClient()
|
||||
val request = Request.Builder()
|
||||
.url("$baseUrl/__admin/scenarios")
|
||||
|
|
@ -69,8 +79,9 @@ fun checkWireMockStatus(baseUrl: String = "[REDACTED_ENV_URL]"): Boolean {
|
|||
|
||||
/**
|
||||
* Method to reset all WireMock scenarios
|
||||
* @param baseUrl WireMock base URL (defaults to local override if set, otherwise remote)
|
||||
*/
|
||||
fun resetWireMockScenarios(baseUrl: String = "[REDACTED_ENV_URL]"): Boolean {
|
||||
fun resetWireMockScenarios(baseUrl: String = getWireMockBaseUrl()): Boolean {
|
||||
Timber.i("=== WireMock Scenarios Reset ===")
|
||||
Timber.i("Base URL: $baseUrl")
|
||||
|
||||
|
|
@ -105,13 +116,13 @@ fun resetWireMockScenarios(baseUrl: String = "[REDACTED_ENV_URL]"): Boolean {
|
|||
* Method to reset a specific WireMock scenario to its initial state
|
||||
* @param scenarioName Name of the scenario to reset
|
||||
* @param initialState The target state to reset the scenario to (must be one of the scenario's possibleStates)
|
||||
* @param baseUrl WireMock base URL
|
||||
* @param baseUrl WireMock base URL (defaults to local override if set, otherwise remote)
|
||||
* @return true if reset was successful, false otherwise
|
||||
*/
|
||||
fun resetWireMockScenarioState(
|
||||
scenarioName: String,
|
||||
initialState: String = "Started",
|
||||
baseUrl: String = "[REDACTED_ENV_URL]"
|
||||
baseUrl: String = getWireMockBaseUrl()
|
||||
): Boolean {
|
||||
Timber.i("=== WireMock Scenario Reset ===")
|
||||
Timber.i("Resetting scenario '$scenarioName' to initial state: $initialState")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue