Skip to content

Commit

Permalink
Changed free trial check
Browse files Browse the repository at this point in the history
  • Loading branch information
nalcalag committed Dec 20, 2024
1 parent eeeeb2c commit 8bc1834
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ object SubscriptionsConstants {
const val YEARLY_PLAN_ROW = "ddg-privacy-pro-yearly-renews-row"
const val MONTHLY_PLAN_ROW = "ddg-privacy-pro-monthly-renews-row"

// List of offers
const val MONTHLY_FREE_TRIAL_OFFER_US = "ddg-privacy-pro-sandbox-freetrial-monthly-renews-us"
const val YEARLY_FREE_TRIAL_OFFER_US = "ddg-privacy-pro-sandbox-freetrial-yearly-renews-us"

// List of features
const val LEGACY_FE_NETP = "vpn"
const val LEGACY_FE_ITR = "identity-theft-restoration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ 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
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.MONTHLY_FREE_TRIAL_OFFER_US
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.PIR
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.PLATFORM
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.ROW_ITR
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.YEARLY
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.YEARLY_FREE_TRIAL_OFFER_US
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.YEARLY_PLAN_ROW
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.YEARLY_PLAN_US
import com.duckduckgo.subscriptions.impl.SubscriptionsManager
Expand Down Expand Up @@ -304,10 +306,9 @@ class SubscriptionWebViewViewModel @Inject constructor(

private fun getOfferJson(offer: SubscriptionOffer): OfferJson? {
return offer.offerId?.let {
val offerType = if (offer.pricingPhases.first().formattedPrice == "Free") {
OfferType.FREE_TRIAL
} else {
OfferType.UNKNOWN
val offerType = when (offer.pricingPhases.first().formattedPrice) {
MONTHLY_FREE_TRIAL_OFFER_US, YEARLY_FREE_TRIAL_OFFER_US -> OfferType.FREE_TRIAL
else -> OfferType.UNKNOWN
}

OfferJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
Expand Down Expand Up @@ -1159,7 +1160,6 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) {
@Test
fun whenGetSubscriptionOfferAndRowPlansAvailableThenReturnValue() = runTest {
authRepository.setFeatures(MONTHLY_PLAN_ROW, setOf(NETP))
authRepository.setFeatures(YEARLY_PLAN_ROW, setOf(NETP))
givenPlansAvailable(MONTHLY_PLAN_ROW, YEARLY_PLAN_ROW)
givenIsLaunchedRow(true)

Expand Down Expand Up @@ -1526,16 +1526,20 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) {
val productDetails: ProductDetails = mock { productDetails ->
whenever(productDetails.productId).thenReturn(SubscriptionsConstants.BASIC_SUBSCRIPTION)

val pricingPhaseList: List<PricingPhase> = listOf(
mock { pricingPhase -> whenever(pricingPhase.formattedPrice).thenReturn("1$") },
)
val mockPricingPhase: PricingPhase = mock {
on { formattedPrice } doReturn "1$"
on { billingPeriod } doReturn "P1M"
}

val pricingPhaseList: List<PricingPhase> = listOf(mockPricingPhase)

val pricingPhases: PricingPhases = mock { pricingPhases ->
whenever(pricingPhases.pricingPhaseList).thenReturn(pricingPhaseList)
}

val offers = basePlanIds.map { basePlanId ->
mock<SubscriptionOfferDetails> { offer ->
whenever(offer.basePlanId).thenReturn(basePlanId)
whenever(offer.basePlanId).thenReturn(basePlanId)
whenever(offer.pricingPhases).thenReturn(pricingPhases)
}
Expand Down

0 comments on commit 8bc1834

Please sign in to comment.