Skip to content

Commit

Permalink
Replace hardcoded error message with real one
Browse files Browse the repository at this point in the history
  • Loading branch information
samiuelson committed Dec 5, 2024
1 parent 100e988 commit 8b4f5f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.woocommerce.android.ui.woopos.util.WooPosNetworkStatus
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsTracker
import com.woocommerce.android.ui.woopos.util.format.WooPosFormatPrice
import com.woocommerce.android.util.UiStringParser
import com.woocommerce.android.util.WooLog
import com.woocommerce.android.util.WooLog.T
import com.woocommerce.android.viewmodel.ResourceProvider
Expand Down Expand Up @@ -57,6 +58,7 @@ class WooPosTotalsViewModel @Inject constructor(
private val analyticsTracker: WooPosAnalyticsTracker,
private val networkStatus: WooPosNetworkStatus,
private val cardReaderPaymentControllerFactory: CardReaderPaymentControllerFactory,
private val uiStringParser: UiStringParser,
private val savedState: SavedStateHandle,
) : ViewModel() {

Expand Down Expand Up @@ -239,7 +241,7 @@ class WooPosTotalsViewModel @Inject constructor(
childrenToParentEventSender.sendToParent(ChildToParentEvent.OrderSuccessfullyPaid)
}
is CardReaderPaymentState.PaymentFailed.ExternalReaderFailedPayment -> {
uiState.value = buildPaymentFailedState()
uiState.value = buildPaymentFailedState(paymentState)
childrenToParentEventSender.sendToParent(ChildToParentEvent.PaymentFailed)
}
is CardReaderPaymentOrRefundState.CardReaderInteracRefundState,
Expand All @@ -253,13 +255,11 @@ class WooPosTotalsViewModel @Inject constructor(
}
}

private fun buildPaymentFailedState(): PaymentFailed = PaymentFailed(
private fun buildPaymentFailedState(state: CardReaderPaymentState.PaymentFailed.ExternalReaderFailedPayment): PaymentFailed = PaymentFailed(
title = resourceProvider.getString(
R.string.woopos_success_totals_payment_failed_title
),
subtitle = resourceProvider.getString(
R.string.woopos_success_totals_payment_failed_subtitle
)
subtitle = uiStringParser.asString(state.errorType.message)
)

private fun buildPaymentProcessingState(): PaymentProcessing = PaymentProcessing(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.woocommerce.android.util

import android.content.Context
import com.woocommerce.android.model.UiString
import com.woocommerce.android.util.UiHelpers.getTextOfUiString
import javax.inject.Inject

class UiStringParser @Inject constructor(
private val context: Context
) {
fun asString(uiString: UiString): String = getTextOfUiString(context, uiString)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsTracker
import com.woocommerce.android.ui.woopos.util.format.WooPosFormatPrice
import com.woocommerce.android.util.CurrencyFormatter
import com.woocommerce.android.util.UiStringParser
import com.woocommerce.android.viewmodel.ResourceProvider
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -97,6 +98,7 @@ class WooPosTotalsViewModelTest {
private val cardReaderOnboardingChecker: CardReaderOnboardingChecker = mock()
private val cardReaderConfigProvider: CardReaderCountryConfigProvider = mock()
private val paymentReceiptShare: PaymentReceiptShare = mock()
private val uiStringParser: UiStringParser = mock()
private val paymentControllerFactory = CardReaderPaymentControllerFactory(
cardReaderManager = cardReaderManager,
orderRepository = orderRepository,
Expand Down Expand Up @@ -840,8 +842,7 @@ class WooPosTotalsViewModelTest {
.thenReturn("Please wait…")
whenever(resourceProvider.getString(R.string.woopos_success_totals_payment_failed_title))
.thenReturn("Payment failed")
whenever(resourceProvider.getString(R.string.woopos_success_totals_payment_failed_subtitle))
.thenReturn("Unfortunately, this payment has been declined.")
whenever(uiStringParser.asString(any())).thenReturn("Unfortunately, this payment has been declined.")

whenever(networkStatus.isConnected()).thenReturn(true)
val readerStatus = MutableStateFlow<CardReaderStatus>(CardReaderStatus.Connected(mock()))
Expand Down Expand Up @@ -878,8 +879,7 @@ class WooPosTotalsViewModelTest {
.thenReturn("Please wait…")
whenever(resourceProvider.getString(R.string.woopos_success_totals_payment_failed_title))
.thenReturn("Payment failed")
whenever(resourceProvider.getString(R.string.woopos_success_totals_payment_failed_subtitle))
.thenReturn("Unfortunately, this payment has been declined.")
whenever(uiStringParser.asString(any())).thenReturn("Unfortunately, this payment has been declined.")

whenever(networkStatus.isConnected()).thenReturn(true)
val readerStatus = MutableStateFlow<CardReaderStatus>(CardReaderStatus.Connected(mock()))
Expand Down Expand Up @@ -977,6 +977,7 @@ class WooPosTotalsViewModelTest {
analyticsTracker = analyticsTracker,
networkStatus = networkStatus,
cardReaderPaymentControllerFactory = cardReaderPaymentControllerFactory,
uiStringParser = uiStringParser,
savedState = savedState,
)
}

0 comments on commit 8b4f5f7

Please sign in to comment.