Bug 1862403 - Remove unneeded states from RecommendedProductState

Removed unneeded states from RecommendedProductState: Loading and Error,
because the UI only uses the other 2 states.
fenix/121.0
RebecaTudor 8 months ago committed by mergify[bot]
parent 030d3e40e8
commit 10f56ea925

@ -18,7 +18,7 @@ private const val MAXIMUM_FRACTION_DIGITS = 2
* Maps [ProductRecommendation] to [RecommendedProductState].
*/
fun ProductRecommendation?.toRecommendedProductState(): RecommendedProductState =
this?.toRecommendedProduct() ?: RecommendedProductState.Error
this?.toRecommendedProduct() ?: RecommendedProductState.Initial
private fun ProductRecommendation.toRecommendedProduct(): RecommendedProductState.Product =
RecommendedProductState.Product(

@ -19,7 +19,6 @@ import org.mozilla.fenix.shopping.store.ReviewQualityCheckMiddleware
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.OptedIn.ProductReviewState
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent.AnalysisStatus
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.RecommendedProductState
/**
* Middleware that handles network requests for the review quality check feature.
@ -162,7 +161,6 @@ class ReviewQualityCheckNetworkMiddleware(
if (currentState is ReviewQualityCheckState.OptedIn &&
currentState.productRecommendationsPreference == true
) {
dispatch(UpdateRecommendedProduct(RecommendedProductState.Loading))
reviewQualityCheckService.productRecommendation().toRecommendedProductState().also {
dispatch(UpdateRecommendedProduct(it))
}

@ -164,16 +164,6 @@ sealed interface ReviewQualityCheckState : State {
*/
object Initial : RecommendedProductState
/**
* The state when the recommended product is loading.
*/
object Loading : RecommendedProductState
/**
* The state when an error has occurred while fetching the recommended product.
*/
object Error : RecommendedProductState
/**
* The state when the recommended product is available.
*

@ -18,9 +18,9 @@ class ProductRecommendationMapperTest {
val localeTestRule = LocaleTestRule(Locale.US)
@Test
fun `WHEN ProductRecommendation is null THEN it is mapped to Error`() {
fun `WHEN ProductRecommendation is null THEN it is mapped to Initial`() {
val actual = null.toRecommendedProductState()
val expected = ReviewQualityCheckState.RecommendedProductState.Error
val expected = ReviewQualityCheckState.RecommendedProductState.Initial
assertEquals(expected, actual)
}

@ -686,7 +686,7 @@ class ReviewQualityCheckStoreTest {
}
@Test
fun `GIVEN product recommendations are enabled WHEN a product analysis is fetched successfully and product recommendation fails THEN product recommendations state should be error`() =
fun `GIVEN product recommendations are enabled WHEN a product analysis is fetched successfully and product recommendation fails THEN product recommendations state should be initial`() =
runTest {
val tested = ReviewQualityCheckStore(
middleware = provideReviewQualityCheckMiddleware(
@ -709,7 +709,7 @@ class ReviewQualityCheckStoreTest {
val expected = ReviewQualityCheckState.OptedIn(
productReviewState = ProductAnalysisTestData.analysisPresent(
recommendedProductState = ReviewQualityCheckState.RecommendedProductState.Error,
recommendedProductState = ReviewQualityCheckState.RecommendedProductState.Initial,
),
productRecommendationsPreference = true,
productVendor = ProductVendor.BEST_BUY,

Loading…
Cancel
Save