|
| 1 | +package com.duckduckgo.app.survey.rmf |
| 2 | + |
| 3 | +import com.duckduckgo.app.browser.senseofprotection.SenseOfProtectionToggles |
| 4 | +import com.duckduckgo.app.browser.senseofprotection.SenseOfProtectionToggles.Cohorts |
| 5 | +import com.duckduckgo.feature.toggles.api.Toggle |
| 6 | +import com.duckduckgo.feature.toggles.api.Toggle.State.Cohort |
| 7 | +import kotlinx.coroutines.test.runTest |
| 8 | +import org.junit.Assert.assertEquals |
| 9 | +import org.junit.Test |
| 10 | +import org.mockito.kotlin.doReturn |
| 11 | +import org.mockito.kotlin.mock |
| 12 | +import org.mockito.kotlin.whenever |
| 13 | + |
| 14 | +class TemporaryDefaultSurveyParametersPluginTest { |
| 15 | + |
| 16 | + private val mockSenseOfProtectionToggles: SenseOfProtectionToggles = mock() |
| 17 | + |
| 18 | + @Test |
| 19 | + fun givenUserAssignedToModifiedControlThenCohortParamEvaluatesToModifiedControl() = runTest { |
| 20 | + val modifiedControlCohort = Cohort(Cohorts.MODIFIED_CONTROL.cohortName, 1) |
| 21 | + val mockToggle: Toggle = mock { |
| 22 | + on { it.isEnabled() } doReturn true |
| 23 | + on { it.getCohort() } doReturn modifiedControlCohort |
| 24 | + } |
| 25 | + whenever(mockSenseOfProtectionToggles.senseOfProtectionNewUserExperimentApr25()).thenReturn(mockToggle) |
| 26 | + |
| 27 | + val plugin = SenseOfProtectionCohortSurveyParameterPlugin(mockSenseOfProtectionToggles) |
| 28 | + |
| 29 | + assertEquals("modifiedControl", plugin.evaluate()) |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + fun givenUserAssignedToVariant1ThenCohortParamEvaluatesToVariant1() = runTest { |
| 34 | + val modifiedControlCohort = Cohort(Cohorts.VARIANT_1.cohortName, 1) |
| 35 | + val mockToggle: Toggle = mock { |
| 36 | + on { it.isEnabled() } doReturn true |
| 37 | + on { it.getCohort() } doReturn modifiedControlCohort |
| 38 | + } |
| 39 | + whenever(mockSenseOfProtectionToggles.senseOfProtectionNewUserExperimentApr25()).thenReturn(mockToggle) |
| 40 | + |
| 41 | + val plugin = SenseOfProtectionCohortSurveyParameterPlugin(mockSenseOfProtectionToggles) |
| 42 | + |
| 43 | + assertEquals("variant1", plugin.evaluate()) |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + fun givenUserAssignedToVariant2ThenCohortParamEvaluatesToVariant2() = runTest { |
| 48 | + val modifiedControlCohort = Cohort(Cohorts.VARIANT_2.cohortName, 2) |
| 49 | + val mockToggle: Toggle = mock { |
| 50 | + on { it.isEnabled() } doReturn true |
| 51 | + on { it.getCohort() } doReturn modifiedControlCohort |
| 52 | + } |
| 53 | + whenever(mockSenseOfProtectionToggles.senseOfProtectionNewUserExperimentApr25()).thenReturn(mockToggle) |
| 54 | + |
| 55 | + val plugin = SenseOfProtectionCohortSurveyParameterPlugin(mockSenseOfProtectionToggles) |
| 56 | + |
| 57 | + assertEquals("variant2", plugin.evaluate()) |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + fun givenNotAssignedOnSenseOfProtectionExperimentThenCohortParamEvaluatesToEmptyString() = runTest { |
| 62 | + val mockToggle: Toggle = mock { |
| 63 | + on { it.isEnabled() } doReturn false |
| 64 | + on { it.getCohort() } doReturn null |
| 65 | + } |
| 66 | + whenever(mockSenseOfProtectionToggles.senseOfProtectionNewUserExperimentApr25()).thenReturn(mockToggle) |
| 67 | + |
| 68 | + val plugin = SenseOfProtectionCohortSurveyParameterPlugin(mockSenseOfProtectionToggles) |
| 69 | + |
| 70 | + assertEquals("", plugin.evaluate()) |
| 71 | + } |
| 72 | +} |
0 commit comments