Updated on 2026-08-14
This commit is contained in:
parent
47f1ccb854
commit
8a83664e9a
19 changed files with 218 additions and 39 deletions
|
|
@ -10,15 +10,15 @@ internal class DefaultTangemPayCloseCardStore(
|
|||
private val prefs: AppPreferencesStore,
|
||||
) : TangemPayCloseCardStore {
|
||||
|
||||
override suspend fun setCloseOrderId(cardId: String, orderId: String?) {
|
||||
if (orderId == null) {
|
||||
prefs.edit { it.remove(getCloseKey(cardId)) }
|
||||
} else {
|
||||
prefs.store(
|
||||
key = getCloseKey(cardId),
|
||||
value = orderId,
|
||||
)
|
||||
}
|
||||
override suspend fun storeCloseOrderId(cardId: String, orderId: String) {
|
||||
prefs.store(
|
||||
key = getCloseKey(cardId),
|
||||
value = orderId,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun removeCloseOrderId(cardId: String) {
|
||||
prefs.edit { it.remove(getCloseKey(cardId)) }
|
||||
}
|
||||
|
||||
override suspend fun getOrderId(cardId: String): String? {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.datasource.local.visa
|
||||
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import com.tangem.datasource.local.datastore.RuntimeDataStore
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
|
|
@ -31,6 +32,10 @@ internal class DefaultTangemPayReissueCardStore(
|
|||
)
|
||||
}
|
||||
|
||||
override suspend fun removeReissueOrderId(cardId: String) {
|
||||
prefs.edit { it.remove(getReissueKey(cardId)) }
|
||||
}
|
||||
|
||||
override suspend fun getOrderId(cardId: String): String? {
|
||||
return prefs.getSyncOrNull(key = getReissueKey(cardId))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package com.tangem.datasource.local.visa
|
|||
|
||||
interface TangemPayCloseCardStore {
|
||||
|
||||
suspend fun setCloseOrderId(cardId: String, orderId: String?)
|
||||
suspend fun storeCloseOrderId(cardId: String, orderId: String)
|
||||
|
||||
suspend fun removeCloseOrderId(cardId: String)
|
||||
|
||||
suspend fun getOrderId(cardId: String): String?
|
||||
}
|
||||
|
|
@ -11,5 +11,7 @@ interface TangemPayReissueCardStore {
|
|||
|
||||
suspend fun storeReissueOrderId(cardId: String, orderId: String)
|
||||
|
||||
suspend fun removeReissueOrderId(cardId: String)
|
||||
|
||||
suspend fun getOrderId(cardId: String): String?
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.tangem.datasource.local.visa
|
||||
|
||||
import androidx.datastore.preferences.core.emptyPreferences
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.tangem.datasource.local.datastore.RuntimeDataStore
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.domain.models.pay.TangemPayReissueCardFee
|
||||
import com.tangem.test.core.datastore.MockStateDataStore
|
||||
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
|
||||
/**
|
||||
* Tests for [DefaultTangemPayReissueCardStore], focused on the reissue order-id lifecycle.
|
||||
*
|
||||
* Uses a real [AppPreferencesStore] backed by an in-memory [MockStateDataStore] so the preferences
|
||||
* round-trip (store / read / remove) is exercised end-to-end. The remove path backs the [REDACTED_TASK_KEY] fix:
|
||||
* a terminal reissue order must be forgotten so the payment-account refresh stops re-polling
|
||||
* `GET /order/{id}` for it.
|
||||
*/
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
internal class DefaultTangemPayReissueCardStoreTest {
|
||||
|
||||
private val dataStore = MockStateDataStore(default = emptyPreferences())
|
||||
private val prefs = AppPreferencesStore(
|
||||
moshi = Moshi.Builder().build(),
|
||||
dispatchers = TestingCoroutineDispatcherProvider(),
|
||||
preferencesDataStore = dataStore,
|
||||
)
|
||||
private val feeStore: RuntimeDataStore<TangemPayReissueCardFee> = mockk(relaxed = true)
|
||||
|
||||
private val store = DefaultTangemPayReissueCardStore(feeStore = feeStore, prefs = prefs)
|
||||
|
||||
@BeforeEach
|
||||
fun resetStore() {
|
||||
runBlocking { dataStore.updateData { emptyPreferences() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN order id stored WHEN getOrderId THEN returns stored id`() = runTest {
|
||||
// Arrange
|
||||
store.storeReissueOrderId(CARD_ID, ORDER_ID)
|
||||
|
||||
// Act
|
||||
val result = store.getOrderId(CARD_ID)
|
||||
|
||||
// Assert
|
||||
assertThat(result).isEqualTo(ORDER_ID)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN order id stored WHEN removeReissueOrderId THEN order id is cleared`() = runTest {
|
||||
// Arrange
|
||||
store.storeReissueOrderId(CARD_ID, ORDER_ID)
|
||||
|
||||
// Act
|
||||
store.removeReissueOrderId(CARD_ID)
|
||||
|
||||
// Assert
|
||||
assertThat(store.getOrderId(CARD_ID)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN clearing one card WHEN another card has an order THEN the other is untouched`() = runTest {
|
||||
// Arrange
|
||||
store.storeReissueOrderId(CARD_ID, ORDER_ID)
|
||||
store.storeReissueOrderId(OTHER_CARD_ID, OTHER_ORDER_ID)
|
||||
|
||||
// Act
|
||||
store.removeReissueOrderId(CARD_ID)
|
||||
|
||||
// Assert
|
||||
assertThat(store.getOrderId(CARD_ID)).isNull()
|
||||
assertThat(store.getOrderId(OTHER_CARD_ID)).isEqualTo(OTHER_ORDER_ID)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val CARD_ID = "card-1"
|
||||
const val OTHER_CARD_ID = "card-2"
|
||||
const val ORDER_ID = "reissue-order-1"
|
||||
const val OTHER_ORDER_ID = "reissue-order-2"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue