Updated on 2026-08-14
This commit is contained in:
commit
d036b23ba4
1274 changed files with 51752 additions and 15452 deletions
|
|
@ -8,6 +8,10 @@ android {
|
|||
namespace = "com.tangem.domain.card"
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.core.analytics.models)
|
||||
implementation(projects.core.error)
|
||||
|
|
@ -25,6 +29,7 @@ dependencies {
|
|||
implementation(projects.domain.visa.models)
|
||||
implementation(projects.core.utils)
|
||||
|
||||
implementation(projects.libs.tangemSdkApi)
|
||||
|
||||
implementation(tangemDeps.card.core)
|
||||
implementation(tangemDeps.blockchain) {
|
||||
|
|
@ -32,9 +37,8 @@ dependencies {
|
|||
}
|
||||
|
||||
/** Testing libraries */
|
||||
testImplementation(deps.test.junit5)
|
||||
testRuntimeOnly(deps.test.junit5.engine)
|
||||
testImplementation(deps.test.mockk)
|
||||
testImplementation(deps.test.truth)
|
||||
testRuntimeOnly(deps.test.junit5.vintage.engine)
|
||||
testImplementation(projects.common.test)
|
||||
testImplementation(projects.test.core)
|
||||
}
|
||||
|
|
@ -1,8 +1,33 @@
|
|||
package com.tangem.domain.card
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.raise.either
|
||||
import com.tangem.common.doOnFailure
|
||||
import com.tangem.sdk.api.TangemSdkManager
|
||||
import com.tangem.utils.logging.TangemLogger
|
||||
|
||||
interface DeleteSavedAccessCodesUseCase {
|
||||
/**
|
||||
* Removes saved user codes (access code and/or passcode) for a physical Tangem card
|
||||
* from the device's secure storage.
|
||||
*
|
||||
* Typically invoked after a successful factory reset of the card, so that stale codes
|
||||
* for an already-wiped card are not left on the device.
|
||||
*
|
||||
* @property tangemSdkManager Card SDK wrapper that performs the code removal operation
|
||||
*/
|
||||
class DeleteSavedAccessCodesUseCase(
|
||||
private val tangemSdkManager: TangemSdkManager,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(cardId: String): Either<Throwable, Unit>
|
||||
/**
|
||||
* @param cardId identifier of the card whose saved codes must be removed
|
||||
* @return [Unit] on success; a Card SDK error (as [Throwable]) if removal failed
|
||||
*/
|
||||
suspend operator fun invoke(cardId: String): Either<Throwable, Unit> = either {
|
||||
tangemSdkManager.deleteSavedUserCodes(cardsIds = setOf(cardId))
|
||||
.doOnFailure { error ->
|
||||
TangemLogger.e("Failed to delete saved access codes for card with id: $cardId", error)
|
||||
raise(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.tangem.domain.card
|
||||
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.common.core.TangemSdkError
|
||||
import com.tangem.sdk.api.TangemSdkManager
|
||||
import com.tangem.test.core.assertEitherLeft
|
||||
import com.tangem.test.core.assertEitherRight
|
||||
import io.mockk.clearMocks
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
internal class DeleteSavedAccessCodesUseCaseTest {
|
||||
|
||||
private val tangemSdkManager = mockk<TangemSdkManager>()
|
||||
|
||||
private lateinit var useCase: DeleteSavedAccessCodesUseCase
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
clearMocks(tangemSdkManager)
|
||||
useCase = DeleteSavedAccessCodesUseCase(tangemSdkManager = tangemSdkManager)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns Right Unit when sdk deletes codes successfully`() = runTest {
|
||||
// Arrange
|
||||
val cardId = "AA00000000000001"
|
||||
coEvery { tangemSdkManager.deleteSavedUserCodes(setOf(cardId)) } returns CompletionResult.Success(Unit)
|
||||
|
||||
// Act
|
||||
val actual = useCase(cardId = cardId)
|
||||
|
||||
// Assert
|
||||
assertEitherRight(actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns Left with sdk error when sdk fails`() = runTest {
|
||||
// Arrange
|
||||
val cardId = "AA00000000000002"
|
||||
val sdkError = TangemSdkError.ExceptionError(RuntimeException("boom"))
|
||||
coEvery { tangemSdkManager.deleteSavedUserCodes(setOf(cardId)) } returns CompletionResult.Failure(sdkError)
|
||||
|
||||
// Act
|
||||
val actual = useCase(cardId = cardId)
|
||||
|
||||
// Assert
|
||||
assertEitherLeft(actual, sdkError)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `passes exactly the given cardId as a singleton set to sdk`() = runTest {
|
||||
// Arrange
|
||||
val cardId = "AA00000000000003"
|
||||
coEvery { tangemSdkManager.deleteSavedUserCodes(any()) } returns CompletionResult.Success(Unit)
|
||||
|
||||
// Act
|
||||
useCase(cardId = cardId)
|
||||
|
||||
// Assert
|
||||
coVerify(exactly = 1) { tangemSdkManager.deleteSavedUserCodes(setOf(cardId)) }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue