Skip to content

Commit

Permalink
Fix mapping for ppro-status in survey params (#5079)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/488551667048375/1208377228655940/f

### Description
Fix the ppro_status values in the survey params.
See more info in linked task.

### Steps to test this PR
QA-optional (Unit tests should pass)
  • Loading branch information
karlenDimla authored Sep 27, 2024
1 parent f89fc55 commit 71654a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class PproDaysUntilExpirySurveyParameterPlugin @Inject constructor(
class PproStatusParameterPlugin @Inject constructor(
private val subscriptionsManager: SubscriptionsManager,
) : SurveyParameterPlugin {
private val invalidCharRegex = Regex("[ -]")
override val surveyParamKey: String = "ppro_status"

override suspend fun evaluate(): String = subscriptionsManager.getSubscription()?.status?.statusName?.lowercase() ?: ""
override suspend fun evaluate(): String =
subscriptionsManager.getSubscription()?.status?.statusName?.lowercase()?.replace(invalidCharRegex, "_") ?: ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.duckduckgo.subscriptions.impl.survey

import com.duckduckgo.common.utils.CurrentTimeProvider
import com.duckduckgo.subscriptions.api.SubscriptionStatus.AUTO_RENEWABLE
import com.duckduckgo.subscriptions.api.SubscriptionStatus.GRACE_PERIOD
import com.duckduckgo.subscriptions.api.SubscriptionStatus.INACTIVE
import com.duckduckgo.subscriptions.api.SubscriptionStatus.NOT_AUTO_RENEWABLE
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants
import com.duckduckgo.subscriptions.impl.SubscriptionsManager
import com.duckduckgo.subscriptions.impl.repository.Subscription
Expand Down Expand Up @@ -138,7 +141,34 @@ class PproSurveyParameterPluginTest {

val plugin = PproStatusParameterPlugin(subscriptionsManager)

assertEquals("auto-renewable", plugin.evaluate())
assertEquals("auto_renewable", plugin.evaluate())
}

@Test
fun whenSubscriptionIsInactiveThenStatusParamEvaluatesToSubscriptionData() = runTest {
whenever(subscriptionsManager.getSubscription()).thenReturn(testSubscription.copy(status = INACTIVE))

val plugin = PproStatusParameterPlugin(subscriptionsManager)

assertEquals("inactive", plugin.evaluate())
}

@Test
fun whenSubscriptionIsNotAutoRenewableThenStatusParamEvaluatesToSubscriptionData() = runTest {
whenever(subscriptionsManager.getSubscription()).thenReturn(testSubscription.copy(status = NOT_AUTO_RENEWABLE))

val plugin = PproStatusParameterPlugin(subscriptionsManager)

assertEquals("not_auto_renewable", plugin.evaluate())
}

@Test
fun whenSubscriptionIsGracePeriodThenStatusParamEvaluatesToSubscriptionData() = runTest {
whenever(subscriptionsManager.getSubscription()).thenReturn(testSubscription.copy(status = GRACE_PERIOD))

val plugin = PproStatusParameterPlugin(subscriptionsManager)

assertEquals("grace_period", plugin.evaluate())
}

@Test
Expand Down

0 comments on commit 71654a3

Please sign in to comment.