Updated on 2026-08-14
This commit is contained in:
parent
a40e6e7e28
commit
fa86588528
7 changed files with 52 additions and 22 deletions
|
|
@ -435,6 +435,7 @@ internal class DefaultWalletsRepository(
|
|||
}
|
||||
|
||||
override suspend fun activatePromoCode(
|
||||
userWalletId: UserWalletId,
|
||||
promoCode: String,
|
||||
bitcoinAddress: String,
|
||||
): Either<ActivatePromoCodeError, String> = withContext(dispatchers.io) {
|
||||
|
|
@ -442,6 +443,7 @@ internal class DefaultWalletsRepository(
|
|||
body = PromocodeActivationBody(
|
||||
promoCode = promoCode,
|
||||
address = bitcoinAddress,
|
||||
walletId = userWalletId.stringValue,
|
||||
),
|
||||
).fold(
|
||||
onSuccess = { it.status.right() },
|
||||
|
|
|
|||
|
|
@ -268,6 +268,7 @@ class DefaultWalletsRepositoryTest {
|
|||
@Test
|
||||
fun `GIVEN valid data WHEN activatePromoCode THEN returns Right with status and calls API`() = runTest {
|
||||
// GIVEN
|
||||
val walletId = UserWalletId("1234567890abcdef")
|
||||
val promoCode = "PROMO123"
|
||||
val address = "bc1qexampleaddress"
|
||||
coEvery { tangemTechApi.activatePromoCode(any()) } returns ApiResponse.Success(
|
||||
|
|
@ -275,7 +276,11 @@ class DefaultWalletsRepositoryTest {
|
|||
)
|
||||
|
||||
// WHEN
|
||||
val result = repository.activatePromoCode(promoCode = promoCode, bitcoinAddress = address)
|
||||
val result = repository.activatePromoCode(
|
||||
userWalletId = walletId,
|
||||
promoCode = promoCode,
|
||||
bitcoinAddress = address
|
||||
)
|
||||
|
||||
// THEN
|
||||
var right: String? = null
|
||||
|
|
@ -294,13 +299,14 @@ class DefaultWalletsRepositoryTest {
|
|||
@Test
|
||||
fun `GIVEN NOT_FOUND error WHEN activatePromoCode THEN returns Left InvalidPromoCode`() = runTest {
|
||||
// GIVEN
|
||||
val walletId = UserWalletId("1234567890abcdef")
|
||||
coEvery { tangemTechApi.activatePromoCode(any()) } returns
|
||||
ApiResponse.Error(
|
||||
HttpException(code = HttpException.Code.NOT_FOUND, message = null, errorBody = null),
|
||||
) as ApiResponse<PromocodeActivationResponse>
|
||||
|
||||
// WHEN
|
||||
val result = repository.activatePromoCode(promoCode = "PROMO", bitcoinAddress = "addr")
|
||||
val result = repository.activatePromoCode(userWalletId = walletId, promoCode = "PROMO", bitcoinAddress = "addr")
|
||||
|
||||
// THEN
|
||||
var error: ActivatePromoCodeError? = null
|
||||
|
|
@ -311,13 +317,14 @@ class DefaultWalletsRepositoryTest {
|
|||
@Test
|
||||
fun `GIVEN CONFLICT error WHEN activatePromoCode THEN returns Left PromocodeAlreadyUsed`() = runTest {
|
||||
// GIVEN
|
||||
val walletId = UserWalletId("1234567890abcdef")
|
||||
coEvery { tangemTechApi.activatePromoCode(any()) } returns
|
||||
ApiResponse.Error(
|
||||
HttpException(code = HttpException.Code.CONFLICT, message = null, errorBody = null),
|
||||
) as ApiResponse<PromocodeActivationResponse>
|
||||
|
||||
// WHEN
|
||||
val result = repository.activatePromoCode(promoCode = "PROMO", bitcoinAddress = "addr")
|
||||
val result = repository.activatePromoCode(userWalletId = walletId, promoCode = "PROMO", bitcoinAddress = "addr")
|
||||
|
||||
// THEN
|
||||
var error: ActivatePromoCodeError? = null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue