Skip to content

Commit cb2d266

Browse files
committed
Fix and update tests
1 parent 2691300 commit cb2d266

File tree

2 files changed

+9
-50
lines changed

2 files changed

+9
-50
lines changed

app/src/test/java/com/duckduckgo/app/browser/senseofprotection/SenseOfProtectionExperimentImplTest.kt

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SenseOfProtectionExperimentImplTest {
7575
}
7676

7777
@Test
78-
fun `when user is new and experiment is enabled for user's cohort then isEnabled returns true`() {
78+
fun `when user is new and enrolUserInNewExperimentIfEligible then user is in enrolled`() {
7979
fakeUserBrowserProperties.setDaysSinceInstalled(28)
8080
fakeSenseOfProtectionToggles.senseOfProtectionNewUserExperimentApr25().setRawStoredState(
8181
State(
@@ -86,7 +86,9 @@ class SenseOfProtectionExperimentImplTest {
8686
),
8787
)
8888

89-
assertTrue(testee.isEnabled(cohortName = MODIFIED_CONTROL))
89+
testee.enrolUserInNewExperimentIfEligible()
90+
91+
assertTrue(testee.enrolUserInNewExperimentIfEligible())
9092
}
9193

9294
@Test
@@ -101,7 +103,7 @@ class SenseOfProtectionExperimentImplTest {
101103
),
102104
)
103105

104-
assertFalse(testee.isEnabled(MODIFIED_CONTROL))
106+
assertFalse(testee.enrolUserInNewExperimentIfEligible())
105107
}
106108

107109
@Test
@@ -116,53 +118,7 @@ class SenseOfProtectionExperimentImplTest {
116118
),
117119
)
118120

119-
assertFalse(testee.isEnabled(MODIFIED_CONTROL))
120-
}
121-
122-
@Test
123-
fun `when user is existing and not enrolled in new user experiment then isEnabled returns true`() {
124-
fakeUserBrowserProperties.setDaysSinceInstalled(29) // just above threshold
125-
fakeSenseOfProtectionToggles.senseOfProtectionNewUserExperimentApr25().setRawStoredState(
126-
State(
127-
remoteEnableState = true,
128-
enable = true,
129-
assignedCohort = null,
130-
cohorts = cohorts,
131-
),
132-
)
133-
fakeSenseOfProtectionToggles.senseOfProtectionExistingUserExperimentApr25().setRawStoredState(
134-
State(
135-
remoteEnableState = true,
136-
enable = true,
137-
assignedCohort = State.Cohort(MODIFIED_CONTROL.cohortName, weight = 1),
138-
cohorts = cohorts,
139-
),
140-
)
141-
142-
assertTrue(testee.isEnabled(MODIFIED_CONTROL))
143-
}
144-
145-
@Test
146-
fun `when user is existing and enrolled in existing user experiment but existing user experiment disabled then isEnabled returns false`() {
147-
fakeUserBrowserProperties.setDaysSinceInstalled(100)
148-
fakeSenseOfProtectionToggles.senseOfProtectionNewUserExperimentApr25().setRawStoredState(
149-
State(
150-
remoteEnableState = true,
151-
enable = true,
152-
assignedCohort = null,
153-
cohorts = cohorts,
154-
),
155-
)
156-
fakeSenseOfProtectionToggles.senseOfProtectionExistingUserExperimentApr25().setRawStoredState(
157-
State(
158-
remoteEnableState = false,
159-
enable = false,
160-
assignedCohort = State.Cohort(MODIFIED_CONTROL.cohortName, weight = 1),
161-
cohorts = cohorts,
162-
),
163-
)
164-
165-
assertFalse(testee.isEnabled(MODIFIED_CONTROL))
121+
assertFalse(testee.enrolUserInNewExperimentIfEligible())
166122
}
167123

168124
@Test

app/src/test/java/com/duckduckgo/app/cta/ui/OnboardingDaxDialogTests.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.duckduckgo.app.cta.ui
1818

1919
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
2020
import com.duckduckgo.app.browser.DuckDuckGoUrlDetector
21+
import com.duckduckgo.app.browser.senseofprotection.SenseOfProtectionExperiment
2122
import com.duckduckgo.app.cta.db.DismissedCtaDao
2223
import com.duckduckgo.app.cta.model.CtaId.DAX_DIALOG_NETWORK
2324
import com.duckduckgo.app.cta.model.CtaId.DAX_DIALOG_OTHER
@@ -80,6 +81,7 @@ class OnboardingDaxDialogTests {
8081
private val mockBrokenSitePrompt: BrokenSitePrompt = mock()
8182
private val mockUserBrowserProperties: UserBrowserProperties = mock()
8283
private val mockSubscriptions: Subscriptions = mock()
84+
private val mockSenseOfProtectionExperiment: SenseOfProtectionExperiment = mock()
8385

8486
val mockEnabledToggle: Toggle = org.mockito.kotlin.mock { on { it.isEnabled() } doReturn true }
8587
val mockDisabledToggle: Toggle = org.mockito.kotlin.mock { on { it.isEnabled() } doReturn false }
@@ -107,6 +109,7 @@ class OnboardingDaxDialogTests {
107109
mockDuckPlayer,
108110
mockBrokenSitePrompt,
109111
mockUserBrowserProperties,
112+
mockSenseOfProtectionExperiment,
110113
)
111114
}
112115

0 commit comments

Comments
 (0)