-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add isReturningUser and isPrivacyProEligible targets and modularize t…
…arget management (#5277) Task/Issue URL: https://app.asana.com/0/1198194956794324/1208710375047087/f ### Description This PR adds couple new targets for FF, ie. isReturningUser and isPrivacyProEligible, both of type `Boolean` The PR also modularizes the way we hande targets, turning them into plugins so that it's easier in the future to add targets without (almost) touching the toggles API ### Steps to test this PR Added unit and integration tests _Test new targets_ - [ ] install from this branch - [ ] create a test feature - [ ] create a remote config for the test feature that contains `isPrivacyProEligible` as target - [ ] in a client that is not eligigle for PPro verify the feature is always disabled - [ ] in a client that is eligigle for PPro verify the feature is enabled when the feature is enabled in remote config - [ ] create a remote config for the test feature that contains `isReturningUser ` as target - [ ] in a fresh install verify the test feature is always disabled - [ ] in a returning install verify the test feature is enabled when the feature is enabled in remote config
- Loading branch information
Showing
14 changed files
with
698 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ts-impl/src/main/java/com/duckduckgo/experiments/impl/ReturningUserToggleTargetMatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.experiments.impl | ||
|
||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.experiments.api.VariantManager | ||
import com.duckduckgo.experiments.impl.reinstalls.REINSTALL_VARIANT | ||
import com.duckduckgo.feature.toggles.api.Toggle.State.Target | ||
import com.duckduckgo.feature.toggles.api.Toggle.TargetMatcherPlugin | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import javax.inject.Inject | ||
|
||
@ContributesMultibinding(AppScope::class) | ||
class ReturningUserToggleTargetMatcher @Inject constructor( | ||
private val variantManager: VariantManager, | ||
) : TargetMatcherPlugin { | ||
override fun matchesTargetProperty(target: Target): Boolean { | ||
return target.isReturningUser?.let { isReturningUserTarget -> | ||
val isReturningUser = variantManager.getVariantKey() == REINSTALL_VARIANT | ||
isReturningUserTarget == isReturningUser | ||
} ?: true | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...mpl/src/test/java/com/duckduckgo/experiments/impl/ReturningUserToggleTargetMatcherTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.duckduckgo.experiments.impl | ||
|
||
import com.duckduckgo.experiments.api.VariantManager | ||
import com.duckduckgo.feature.toggles.api.Toggle | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
|
||
class ReturningUserToggleTargetMatcherTest { | ||
private val variantManager: VariantManager = mock() | ||
private val matcher = ReturningUserToggleTargetMatcher(variantManager) | ||
|
||
@Test | ||
fun whenReturningUserAndNullTargetThenMatchesTargetReturnsTrue() { | ||
whenever(variantManager.getVariantKey()).thenReturn("ru") | ||
|
||
assertTrue(matcher.matchesTargetProperty(NULL_TARGET)) | ||
} | ||
|
||
@Test | ||
fun whenNotReturningUserAndNullTargetThenMatchesTargetReturnsTrue() { | ||
whenever(variantManager.getVariantKey()).thenReturn("foo") | ||
|
||
assertTrue(matcher.matchesTargetProperty(NULL_TARGET)) | ||
} | ||
|
||
@Test | ||
fun whenReturningUserAndTargetMatchesThenReturnTrue() { | ||
whenever(variantManager.getVariantKey()).thenReturn("ru") | ||
|
||
assertTrue(matcher.matchesTargetProperty(RU_TARGET)) | ||
} | ||
|
||
@Test | ||
fun whenNoReturningUserAndTargetMatchesThenReturnTrue() { | ||
whenever(variantManager.getVariantKey()).thenReturn("foo") | ||
|
||
assertTrue(matcher.matchesTargetProperty(NOT_RU_TARGET)) | ||
} | ||
|
||
@Test | ||
fun whenReturningUserAndTargetNotMatchingThenReturnFalse() { | ||
whenever(variantManager.getVariantKey()).thenReturn("ru") | ||
|
||
assertFalse(matcher.matchesTargetProperty(NOT_RU_TARGET)) | ||
} | ||
|
||
@Test | ||
fun whenNoReturningUserAndTargetNotMatchingThenReturnTrue() { | ||
whenever(variantManager.getVariantKey()).thenReturn("foo") | ||
|
||
assertFalse(matcher.matchesTargetProperty(RU_TARGET)) | ||
} | ||
|
||
companion object { | ||
private val NULL_TARGET = Toggle.State.Target(null, null, null, null, null) | ||
private val RU_TARGET = NULL_TARGET.copy(isReturningUser = true) | ||
private val NOT_RU_TARGET = NULL_TARGET.copy(isReturningUser = false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.