From 1e619b1e9da761bbc4bd643530fab640890eb1e0 Mon Sep 17 00:00:00 2001 From: Noelia Alcala Date: Thu, 19 Dec 2024 16:52:12 +0000 Subject: [PATCH] update tests --- .../impl/RealSubscriptionsManagerTest.kt | 22 +++++++++++++------ .../ui/SubscriptionWebViewViewModelTest.kt | 16 ++++++++------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/RealSubscriptionsManagerTest.kt b/subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/RealSubscriptionsManagerTest.kt index 0433dd79d3a4..92cccbbb324a 100644 --- a/subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/RealSubscriptionsManagerTest.kt +++ b/subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/RealSubscriptionsManagerTest.kt @@ -23,9 +23,13 @@ import com.duckduckgo.subscriptions.api.SubscriptionStatus.NOT_AUTO_RENEWABLE import com.duckduckgo.subscriptions.api.SubscriptionStatus.UNKNOWN import com.duckduckgo.subscriptions.api.SubscriptionStatus.WAITING import com.duckduckgo.subscriptions.impl.RealSubscriptionsManager.RecoverSubscriptionResult +import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.LEGACY_FE_ITR +import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.LEGACY_FE_NETP +import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.LEGACY_FE_PIR import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.MONTHLY_PLAN_ROW import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.MONTHLY_PLAN_US import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.NETP +import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.ROW_ITR import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.YEARLY_PLAN_ROW import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.YEARLY_PLAN_US import com.duckduckgo.subscriptions.impl.auth2.AccessTokenClaims @@ -106,7 +110,10 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) { @SuppressLint("DenyListedApi") private val privacyProFeature: PrivacyProFeature = FakeFeatureToggleFactory.create(PrivacyProFeature::class.java) - .apply { authApiV2().setRawStoredState(State(authApiV2Enabled)) } + .apply { + authApiV2().setRawStoredState(State(authApiV2Enabled)) + featuresApi().setRawStoredState(State(true)) + } private val authClient: AuthClient = mock() private val pkceGenerator: PkceGenerator = PkceGeneratorImpl() private val authJwtValidator: AuthJwtValidator = mock() @@ -1132,7 +1139,7 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) { @Test fun whenGetSubscriptionOfferThenReturnValue() = runTest { - authRepository.setFeatures(MONTHLY_PLAN_US, setOf(NETP)) + privacyProFeature.featuresApi().setRawStoredState(State(false)) givenPlansAvailable(MONTHLY_PLAN_US, YEARLY_PLAN_US) val subscriptionOffers = subscriptionsManager.getSubscriptionOffer() @@ -1142,7 +1149,7 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) { assertEquals("1$", find { it.planId == MONTHLY_PLAN_US }?.pricingPhases?.first()?.formattedPrice) assertTrue(any { it.planId == YEARLY_PLAN_US }) assertEquals("1$", find { it.planId == YEARLY_PLAN_US }?.pricingPhases?.first()?.formattedPrice) - assertEquals(setOf(NETP), first().features) + assertEquals(setOf(LEGACY_FE_NETP, LEGACY_FE_PIR, LEGACY_FE_ITR), first().features) } } @@ -1151,12 +1158,12 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) { authRepository.setFeatures(MONTHLY_PLAN_US, emptySet()) givenPlansAvailable(MONTHLY_PLAN_US, YEARLY_PLAN_US) - assertNull(subscriptionsManager.getSubscriptionOffer()) + assertTrue(subscriptionsManager.getSubscriptionOffer().isEmpty()) } @Test fun whenGetSubscriptionOfferAndRowPlansAvailableThenReturnValue() = runTest { - authRepository.setFeatures(MONTHLY_PLAN_ROW, setOf(NETP)) + privacyProFeature.featuresApi().setRawStoredState(State(false)) givenPlansAvailable(MONTHLY_PLAN_ROW, YEARLY_PLAN_ROW) givenIsLaunchedRow(true) @@ -1167,7 +1174,7 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) { assertEquals("1$", find { it.planId == MONTHLY_PLAN_ROW }?.pricingPhases?.first()?.formattedPrice) assertTrue(any { it.planId == YEARLY_PLAN_ROW }) assertEquals("1$", find { it.planId == YEARLY_PLAN_ROW }?.pricingPhases?.first()?.formattedPrice) - assertEquals(setOf(NETP), first().features) + assertEquals(setOf(NETP, ROW_ITR), first().features) } } @@ -1177,7 +1184,7 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) { givenPlansAvailable(MONTHLY_PLAN_ROW, YEARLY_PLAN_ROW) givenIsLaunchedRow(false) - assertNull(subscriptionsManager.getSubscriptionOffer()) + assertTrue(subscriptionsManager.getSubscriptionOffer().isEmpty()) } @Test @@ -1533,6 +1540,7 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) { val offers = basePlanIds.map { basePlanId -> mock { offer -> whenever(offer.basePlanId).thenReturn(basePlanId) + whenever(offer.offerId).thenReturn(null) whenever(offer.pricingPhases).thenReturn(pricingPhases) } } diff --git a/subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/ui/SubscriptionWebViewViewModelTest.kt b/subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/ui/SubscriptionWebViewViewModelTest.kt index 3f0a605f934e..16dbb657a493 100644 --- a/subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/ui/SubscriptionWebViewViewModelTest.kt +++ b/subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/ui/SubscriptionWebViewViewModelTest.kt @@ -20,6 +20,8 @@ import com.duckduckgo.subscriptions.impl.PrivacyProFeature import com.duckduckgo.subscriptions.impl.SubscriptionOfferDetails import com.duckduckgo.subscriptions.impl.SubscriptionsChecker import com.duckduckgo.subscriptions.impl.SubscriptionsConstants +import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.MONTHLY_PLAN_US +import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.YEARLY_PLAN_US import com.duckduckgo.subscriptions.impl.SubscriptionsManager import com.duckduckgo.subscriptions.impl.pixels.SubscriptionPixelSender import com.duckduckgo.subscriptions.impl.ui.SubscriptionWebViewViewModel.Command @@ -199,20 +201,20 @@ class SubscriptionWebViewViewModelTest { fun whenGetSubscriptionOptionsThenSendCommand() = runTest { val testSubscriptionOfferList = listOf( SubscriptionOfferDetails( - planId = "monthly", + planId = MONTHLY_PLAN_US, offerId = null, pricingPhases = listOf(PricingPhase(formattedPrice = "$1")), features = setOf(SubscriptionsConstants.NETP), ), SubscriptionOfferDetails( - planId = "yearly", + planId = YEARLY_PLAN_US, offerId = null, pricingPhases = listOf(PricingPhase(formattedPrice = "$10")), features = setOf(SubscriptionsConstants.NETP), ), ) - privacyProFeature.allowPurchase().setRawStoredState(Toggle.State(enable = true)) whenever(subscriptionsManager.getSubscriptionOffer()).thenReturn(testSubscriptionOfferList) + privacyProFeature.allowPurchase().setRawStoredState(Toggle.State(enable = true)) viewModel.commands().test { viewModel.processJsCallbackMessage("test", "getSubscriptionOptions", "id", JSONObject("{}")) @@ -224,8 +226,8 @@ class SubscriptionWebViewViewModelTest { assertEquals("id", response.id) assertEquals("test", response.featureName) assertEquals("getSubscriptionOptions", response.method) - assertEquals("yearly", params?.options?.first()?.id) - assertEquals("monthly", params?.options?.last()?.id) + assertEquals(YEARLY_PLAN_US, params?.options?.first()?.id) + assertEquals(MONTHLY_PLAN_US, params?.options?.last()?.id) } } @@ -254,13 +256,13 @@ class SubscriptionWebViewViewModelTest { fun whenGetSubscriptionsAndToggleOffThenSendCommandWithEmptyData() = runTest { val testSubscriptionOfferList = listOf( SubscriptionOfferDetails( - planId = "monthly", + planId = MONTHLY_PLAN_US, offerId = null, pricingPhases = listOf(PricingPhase(formattedPrice = "$1")), features = setOf(SubscriptionsConstants.NETP), ), SubscriptionOfferDetails( - planId = "yearly", + planId = YEARLY_PLAN_US, offerId = null, pricingPhases = listOf(PricingPhase(formattedPrice = "$10")), features = setOf(SubscriptionsConstants.NETP),