-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBL-1722: Extended feature flag client to check user enabled feature …
…flags (#2129)
- Loading branch information
Showing
8 changed files
with
149 additions
and
37 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
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 | ||
|