-
Notifications
You must be signed in to change notification settings - Fork 988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MBL-1722: Extended feature flag client to check user enabled feature flags #2129
Merged
+149
−37
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f539c23
- FeatureFlagClient
Arkariang 0bb4dae
- Check locally if the user has backend enabled ff
Arkariang 81de334
- Added functionality on FeatureFlag client to request for Backend us…
Arkariang dc4c527
Merge branch 'master' into imartin/MBL-1722-simple
Arkariang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ query UserPrivacy { | |
isDeliverable | ||
isEmailVerified | ||
chosenCurrency | ||
enabledFeatures | ||
} | ||
} | ||
|
||
|
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
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 |
---|---|---|
|
@@ -547,7 +547,8 @@ open class MockApolloClient : ApolloClientType { | |
true, | ||
true, | ||
true, | ||
"USD" | ||
"USD", | ||
emptyList() | ||
) | ||
) | ||
) | ||
|
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
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
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
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
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 |
---|---|---|
|
@@ -4,10 +4,14 @@ import com.kickstarter.KSRobolectricTestCase | |
import com.kickstarter.R | ||
import com.kickstarter.libs.Environment | ||
import com.kickstarter.libs.featureflag.FlagKey | ||
import com.kickstarter.libs.featureflag.FlipperFlagKey | ||
import com.kickstarter.libs.utils.extensions.addToDisposable | ||
import com.kickstarter.mock.MockFeatureFlagClient | ||
import com.kickstarter.mock.factories.UserFactory | ||
import com.kickstarter.mock.services.MockApolloClientV2 | ||
import com.kickstarter.models.User | ||
import com.kickstarter.models.UserPrivacy | ||
import io.reactivex.Observable | ||
import io.reactivex.disposables.CompositeDisposable | ||
import io.reactivex.subscribers.TestSubscriber | ||
import org.junit.After | ||
|
@@ -161,51 +165,130 @@ class LoggedInViewHolderViewModelTest : KSRobolectricTestCase() { | |
} | ||
|
||
@Test | ||
fun `when pledged projects feature is flag off, should emit false`() { | ||
val mockFeatureFlagClient: MockFeatureFlagClient = | ||
object : MockFeatureFlagClient() { | ||
override fun getBoolean(FlagKey: FlagKey): Boolean { | ||
return false | ||
} | ||
} | ||
fun `when user has project alerts, should emit true`() { | ||
setUpEnvironment(environment()) | ||
val user = UserFactory.user().toBuilder().ppoHasAction(true).build() | ||
this.vm.inputs.configureWith(user) | ||
|
||
setUpEnvironment(environment().toBuilder().featureFlagClient(mockFeatureFlagClient).build()) | ||
val user = UserFactory.user() | ||
this.pledgedProjectsIndicatorIsVisible.assertValue(true) | ||
} | ||
|
||
this.pledgedProjectsIsVisible.assertValue(false) | ||
@Test | ||
fun `when user doesnt have project alerts, should emit false`() { | ||
setUpEnvironment(environment()) | ||
val user = UserFactory.user().toBuilder().ppoHasAction(false).build() | ||
this.vm.inputs.configureWith(user) | ||
|
||
this.pledgedProjectsIndicatorIsVisible.assertValue(false) | ||
} | ||
|
||
@Test | ||
fun `when pledged projects feature is flag on, should emit true`() { | ||
val mockFeatureFlagClient: MockFeatureFlagClient = | ||
object : MockFeatureFlagClient() { | ||
override fun getBoolean(FlagKey: FlagKey): Boolean { | ||
return true | ||
} | ||
fun `test feature flag enabled in backed and mobile shows PPO`() { | ||
val privacy = UserPrivacy( | ||
"Some Name", | ||
"[email protected]", | ||
true, | ||
true, | ||
true, | ||
true, | ||
"USD", | ||
enabledFeatures = listOf("some_key_here", FlipperFlagKey.FLIPPER_PLEDGED_PROJECTS_OVERVIEW.key) | ||
) | ||
|
||
val apolloClient = object : MockApolloClientV2() { | ||
override fun userPrivacy(): Observable<UserPrivacy> { | ||
return Observable.just( | ||
privacy | ||
) | ||
} | ||
} | ||
val ffClient = object : MockFeatureFlagClient() { | ||
override fun getBoolean(FlagKey: FlagKey): Boolean { | ||
return true | ||
} | ||
} | ||
|
||
setUpEnvironment(environment().toBuilder().featureFlagClient(mockFeatureFlagClient).build()) | ||
val user = UserFactory.user() | ||
val environment = environment().toBuilder() | ||
.apolloClientV2(apolloClient) | ||
.featureFlagClient(ffClient) | ||
.build() | ||
|
||
setUpEnvironment(environment) | ||
|
||
this.pledgedProjectsIsVisible.assertValue(true) | ||
} | ||
|
||
@Test | ||
fun `when user has project alerts, should emit true`() { | ||
setUpEnvironment(environment()) | ||
val user = UserFactory.user().toBuilder().ppoHasAction(true).build() | ||
this.vm.inputs.configureWith(user) | ||
fun `test feature flag disabled in backed and enabled in mobile not show PPO`() { | ||
val privacy = UserPrivacy( | ||
"Some Name", | ||
"[email protected]", | ||
true, | ||
true, | ||
true, | ||
true, | ||
"USD", | ||
enabledFeatures = listOf("some_key_here") | ||
) | ||
|
||
val apolloClient = object : MockApolloClientV2() { | ||
override fun userPrivacy(): Observable<UserPrivacy> { | ||
return Observable.just( | ||
privacy | ||
) | ||
} | ||
} | ||
val ffClient = object : MockFeatureFlagClient() { | ||
override fun getBoolean(FlagKey: FlagKey): Boolean { | ||
return true | ||
} | ||
} | ||
|
||
this.pledgedProjectsIndicatorIsVisible.assertValue(true) | ||
val environment = environment().toBuilder() | ||
.apolloClientV2(apolloClient) | ||
.featureFlagClient(ffClient) | ||
.build() | ||
|
||
setUpEnvironment(environment) | ||
|
||
this.pledgedProjectsIsVisible.assertValue(false) | ||
} | ||
|
||
@Test | ||
fun `when user doesnt have project alerts, should emit false`() { | ||
setUpEnvironment(environment()) | ||
val user = UserFactory.user().toBuilder().ppoHasAction(false).build() | ||
this.vm.inputs.configureWith(user) | ||
fun `test feature flag disabled in backed and disabled in mobile not show PPO`() { | ||
val privacy = UserPrivacy( | ||
"Some Name", | ||
"[email protected]", | ||
true, | ||
true, | ||
true, | ||
true, | ||
"USD", | ||
enabledFeatures = listOf("some_key_here") | ||
) | ||
|
||
val apolloClient = object : MockApolloClientV2() { | ||
override fun userPrivacy(): Observable<UserPrivacy> { | ||
return Observable.just( | ||
privacy | ||
) | ||
} | ||
} | ||
|
||
this.pledgedProjectsIndicatorIsVisible.assertValue(false) | ||
val ffClient = object : MockFeatureFlagClient() { | ||
override fun getBoolean(FlagKey: FlagKey): Boolean { | ||
return false | ||
} | ||
} | ||
|
||
val environment = environment().toBuilder() | ||
.apolloClientV2(apolloClient) | ||
.featureFlagClient(ffClient) | ||
.build() | ||
|
||
setUpEnvironment(environment) | ||
|
||
this.pledgedProjectsIsVisible.assertValue(false) | ||
} | ||
|
||
@After | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at the query: