Let backend know that the rate app flow was triggered
by setting the feature flag to false. This is not a guarantee that the rate app dialog was shown, as the final decision on whether to show the "rate app dialog" or not is done by google play lib based on "API usage quota" (the rate dialog can only be shown so many times in a given timeframe). MAILAND-3071
This commit is contained in:
parent
72d67e9b6c
commit
54cf43d280
|
@ -34,24 +34,32 @@ class StartRateAppFlowIfNeeded @Inject constructor(
|
|||
) {
|
||||
|
||||
suspend operator fun invoke(userId: UserId) {
|
||||
if (!showReviewFeatureFlag(userId)) {
|
||||
if (!isShowReviewFeatureFlagEnabled(userId)) {
|
||||
return
|
||||
}
|
||||
if (mailboxScreenViewsRepository.screenViewCount < MailboxScreenViewsThreshold) {
|
||||
return
|
||||
}
|
||||
startRateAppFlow()
|
||||
recordReviewFlowStarted(userId)
|
||||
}
|
||||
|
||||
private suspend fun showReviewFeatureFlag(userId: UserId): Boolean {
|
||||
val featureId = MailFeatureFlags.ShowReviewAppDialog.featureId
|
||||
return featureFlagManager.getOrDefault(
|
||||
userId,
|
||||
featureId,
|
||||
FeatureFlag.default(featureId.id, false)
|
||||
).value
|
||||
private suspend fun recordReviewFlowStarted(userId: UserId) {
|
||||
val featureFlag = getShowReviewFeatureFlag(userId)
|
||||
val offFeatureFlag = featureFlag.copy(defaultValue = false, value = false)
|
||||
featureFlagManager.update(offFeatureFlag)
|
||||
}
|
||||
|
||||
private suspend fun isShowReviewFeatureFlagEnabled(userId: UserId) = getShowReviewFeatureFlag(userId).value
|
||||
|
||||
private suspend fun getShowReviewFeatureFlag(
|
||||
userId: UserId
|
||||
) = featureFlagManager.getOrDefault(
|
||||
userId,
|
||||
MailFeatureFlags.ShowReviewAppDialog.featureId,
|
||||
FeatureFlag.default(MailFeatureFlags.ShowReviewAppDialog.featureId.id, false)
|
||||
)
|
||||
|
||||
companion object {
|
||||
private const val MailboxScreenViewsThreshold = 2
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import ch.protonmail.android.featureflags.MailFeatureFlags
|
|||
import ch.protonmail.android.testdata.UserTestData
|
||||
import io.mockk.Called
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
|
@ -37,8 +38,10 @@ import org.junit.Test
|
|||
|
||||
class StartRateAppFlowIfNeededTest {
|
||||
|
||||
private val userId = UserTestData.userId
|
||||
|
||||
private val mailboxScreenViewsRepository: MailboxScreenViewInMemoryRepository = mockk()
|
||||
private val featureFlagManager: FeatureFlagManager = mockk()
|
||||
private val featureFlagManager: FeatureFlagManager = mockk(relaxUnitFun = true)
|
||||
private val startRateAppFlow: StartRateAppFlow = mockk(relaxUnitFun = true)
|
||||
|
||||
private val startRateAppFlowIfNeeded = StartRateAppFlowIfNeeded(
|
||||
|
@ -50,7 +53,6 @@ class StartRateAppFlowIfNeededTest {
|
|||
@Test
|
||||
fun `rate app flow is started when feature flag is true and mailbox screen views reached threshold`() = runTest {
|
||||
// given
|
||||
val userId = UserTestData.userId
|
||||
mockFeatureFlagValue(userId, true)
|
||||
mockScreenViews(2)
|
||||
|
||||
|
@ -64,7 +66,6 @@ class StartRateAppFlowIfNeededTest {
|
|||
@Test
|
||||
fun `rate app flow is not started when feature flag is false`() = runTest {
|
||||
// given
|
||||
val userId = UserTestData.userId
|
||||
mockFeatureFlagValue(userId, false)
|
||||
mockScreenViews(2)
|
||||
|
||||
|
@ -78,7 +79,6 @@ class StartRateAppFlowIfNeededTest {
|
|||
@Test
|
||||
fun `rate app flow is not started when mailbox screen views are less than threshold`() = runTest {
|
||||
// given
|
||||
val userId = UserTestData.userId
|
||||
mockFeatureFlagValue(userId, true)
|
||||
mockScreenViews(1)
|
||||
|
||||
|
@ -89,6 +89,21 @@ class StartRateAppFlowIfNeededTest {
|
|||
verify { startRateAppFlow wasNot Called }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `notify backend that the rate flow was started by disabling feature flag`() = runTest {
|
||||
// given
|
||||
mockFeatureFlagValue(userId, true)
|
||||
mockScreenViews(2)
|
||||
|
||||
// when
|
||||
startRateAppFlowIfNeeded(userId)
|
||||
|
||||
// then
|
||||
val featureId = MailFeatureFlags.ShowReviewAppDialog.featureId
|
||||
val featureFlag = FeatureFlag(userId, featureId, Scope.User, defaultValue = false, value = false)
|
||||
coVerify { featureFlagManager.update(featureFlag) }
|
||||
}
|
||||
|
||||
private suspend fun mockFeatureFlagValue(userId: UserId, isEnabled: Boolean) {
|
||||
val featureId = MailFeatureFlags.ShowReviewAppDialog.featureId
|
||||
coEvery {
|
||||
|
|
Loading…
Reference in New Issue