Skip to content

Commit

Permalink
Merge pull request #2368 from HedvigInsurance/cleanup/obsolete_tier_f…
Browse files Browse the repository at this point in the history
…lag_completely

Remove Feature.TIER entirely
  • Loading branch information
StylianosGakis authored Jan 10, 2025
2 parents 2be8156 + cc7b1b1 commit e5d4c14
Show file tree
Hide file tree
Showing 26 changed files with 252 additions and 555 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.hedvig.android.feature.force.upgrade.ForceUpgradeBlockingScreen
import com.hedvig.android.feature.login.navigation.LoginDestination
import com.hedvig.android.featureflags.FeatureManager
import com.hedvig.android.language.LanguageService
import com.hedvig.android.logger.LogPriority
import com.hedvig.android.logger.logcat
import com.hedvig.android.market.MarketManager
import com.hedvig.android.navigation.activity.ExternalNavigator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,100 +35,94 @@ internal class CreateChangeTierDeductibleIntentUseCaseImpl(
source: ChangeTierCreateSource,
): Either<ErrorMessage, ChangeTierDeductibleIntent> {
return either {
val isTierEnabled = featureManager.isFeatureEnabled(Feature.TIER).first()
val isAddonFlagEnabled = featureManager.isFeatureEnabled(Feature.TRAVEL_ADDON).first()
if (!isTierEnabled) {
logcat(ERROR) { "Tried to get changeTierQuotes when feature flag is disabled!" }
raise(ErrorMessage())
} else {
val changeTierDeductibleResponse = apolloClient
.mutation(
ChangeTierDeductibleCreateIntentMutation(
contractId = insuranceId,
source = source.toSource(),
addonsFlagOn = isAddonFlagEnabled,
),
)
.safeExecute()
val intent = changeTierDeductibleResponse.getOrNull()?.changeTierDeductibleCreateIntent?.intent
if (intent != null) {
if (intent.quotes.isNotEmpty()) {
val currentQuote = with(intent.agreementToChange) {
ensureNotNull(tierLevel) {
ErrorMessage("For insuranceId:$insuranceId and source:$source, agreementToChange tierLevel was null")
}
ensureNotNull(tierName) {
ErrorMessage("For insuranceId:$insuranceId and source:$source, agreementToChange tierName was null")
}
TierDeductibleQuote(
id = TierConstants.CURRENT_ID,
deductible = deductible?.toDeductible(),
premium = UiMoney.fromMoneyFragment(premium),
productVariant = productVariant.toProductVariant(),
tier = Tier(
tierName = tierName,
tierLevel = tierLevel,
tierDescription = productVariant.tierDescription,
tierDisplayName = productVariant.displayNameTier,
),
displayItems = displayItems.toDisplayItems(),
addons = emptyList(), // todo: we don't show current agreement addon anywhere
)
val changeTierDeductibleResponse = apolloClient
.mutation(
ChangeTierDeductibleCreateIntentMutation(
contractId = insuranceId,
source = source.toSource(),
addonsFlagOn = isAddonFlagEnabled,
),
)
.safeExecute()
val intent = changeTierDeductibleResponse.getOrNull()?.changeTierDeductibleCreateIntent?.intent
if (intent != null) {
if (intent.quotes.isNotEmpty()) {
val currentQuote = with(intent.agreementToChange) {
ensureNotNull(tierLevel) {
ErrorMessage("For insuranceId:$insuranceId and source:$source, agreementToChange tierLevel was null")
}
val quotesToOffer = intent.quotes.map {
ensureNotNull(it.tierLevel) {
ErrorMessage("For insuranceId:$insuranceId and source:$source, tierLevel was null")
}
ensureNotNull(it.tierName) {
ErrorMessage("For insuranceId:$insuranceId and source:$source, tierName was null")
}
TierDeductibleQuote(
id = it.id,
deductible = it.deductible?.toDeductible(),
displayItems = it.displayItems.toDisplayItems(),
premium = UiMoney.fromMoneyFragment(it.premium),
productVariant = it.productVariant.toProductVariant(),
tier = Tier(
tierName = it.tierName,
tierLevel = it.tierLevel,
tierDescription = it.productVariant.tierDescription,
tierDisplayName = it.productVariant.displayNameTier,
),
addons = it.addons?.map { addon ->
ChangeTierDeductibleAddonQuote(
addonId = addon.addonId,
displayName = addon.displayName,
displayItems = addon.displayItems.toDisplayItems(),
previousPremium = UiMoney.fromMoneyFragment(addon.previousPremium),
premium = UiMoney.fromMoneyFragment(addon.premium),
addonVariant = addon.addonVariant.toAddonVariant(),
)
} ?: emptyList(),
)
ensureNotNull(tierName) {
ErrorMessage("For insuranceId:$insuranceId and source:$source, agreementToChange tierName was null")
}
val intentResult = ChangeTierDeductibleIntent(
activationDate = intent.activationDate,
quotes = listOf(currentQuote) + quotesToOffer,
TierDeductibleQuote(
id = TierConstants.CURRENT_ID,
deductible = deductible?.toDeductible(),
premium = UiMoney.fromMoneyFragment(premium),
productVariant = productVariant.toProductVariant(),
tier = Tier(
tierName = tierName,
tierLevel = tierLevel,
tierDescription = productVariant.tierDescription,
tierDisplayName = productVariant.displayNameTier,
),
displayItems = displayItems.toDisplayItems(),
addons = emptyList(), // todo: we don't show current agreement addon anywhere
)
logcat(LogPriority.VERBOSE) { "createChangeTierDeductibleIntentUseCase has intent: $intentResult" }
intentResult
} else {
val intentResult = ChangeTierDeductibleIntent(
activationDate = intent.activationDate,
quotes = listOf(),
}
val quotesToOffer = intent.quotes.map {
ensureNotNull(it.tierLevel) {
ErrorMessage("For insuranceId:$insuranceId and source:$source, tierLevel was null")
}
ensureNotNull(it.tierName) {
ErrorMessage("For insuranceId:$insuranceId and source:$source, tierName was null")
}
TierDeductibleQuote(
id = it.id,
deductible = it.deductible?.toDeductible(),
displayItems = it.displayItems.toDisplayItems(),
premium = UiMoney.fromMoneyFragment(it.premium),
productVariant = it.productVariant.toProductVariant(),
tier = Tier(
tierName = it.tierName,
tierLevel = it.tierLevel,
tierDescription = it.productVariant.tierDescription,
tierDisplayName = it.productVariant.displayNameTier,
),
addons = it.addons?.map { addon ->
ChangeTierDeductibleAddonQuote(
addonId = addon.addonId,
displayName = addon.displayName,
displayItems = addon.displayItems.toDisplayItems(),
previousPremium = UiMoney.fromMoneyFragment(addon.previousPremium),
premium = UiMoney.fromMoneyFragment(addon.premium),
addonVariant = addon.addonVariant.toAddonVariant(),
)
} ?: emptyList(),
)
logcat(LogPriority.VERBOSE) { "createChangeTierDeductibleIntentUseCase has intent: $intentResult" }
intentResult
}
val intentResult = ChangeTierDeductibleIntent(
activationDate = intent.activationDate,
quotes = listOf(currentQuote) + quotesToOffer,
)
logcat(LogPriority.VERBOSE) { "createChangeTierDeductibleIntentUseCase has intent: $intentResult" }
intentResult
} else {
if (changeTierDeductibleResponse.isRight()) {
logcat(ERROR) { "Tried to get changeTierQuotes but output intent is null!" }
}
if (changeTierDeductibleResponse.isLeft()) {
logcat(ERROR) { "Tried to get changeTierQuotes but got error: $changeTierDeductibleResponse!" }
}
raise(ErrorMessage())
val intentResult = ChangeTierDeductibleIntent(
activationDate = intent.activationDate,
quotes = listOf(),
)
logcat(LogPriority.VERBOSE) { "createChangeTierDeductibleIntentUseCase has intent: $intentResult" }
intentResult
}
} else {
if (changeTierDeductibleResponse.isRight()) {
logcat(ERROR) { "Tried to get changeTierQuotes but output intent is null!" }
}
if (changeTierDeductibleResponse.isLeft()) {
logcat(ERROR) { "Tried to get changeTierQuotes but got error: $changeTierDeductibleResponse!" }
}
raise(ErrorMessage())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {

@Test
fun `when BE response has empty quotes return intent with empty quotes`() = runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TIER to true, Feature.TRAVEL_ADDON to true))
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodResponseButEmptyQuotes,
featureManager = featureManager,
Expand All @@ -367,13 +367,8 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {
}

@Test
fun `when response is fine and tier feature flag is on get a good result`() = runTest {
val featureManager = FakeFeatureManager2(
fixedMap = mapOf(
Feature.TIER to true,
Feature.TRAVEL_ADDON to true,
),
)
fun `when response is fine get a good result`() = runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodResponse,
featureManager = featureManager,
Expand All @@ -399,37 +394,9 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {
.isEqualTo(500.0)
}

@Test
fun `when response is fine but tier feature flag is off the result is ErrorMessage`() = runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TIER to false, Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodResponse,
featureManager = featureManager,
)
val result = createChangeTierDeductibleIntentUseCase.invoke(testId, ChangeTierCreateSource.SELF_SERVICE)

assertk.assertThat(result)
.isNotNull()
.isLeft()
}

@Test
fun `when response is bad and tier feature flag is on the result is ErrorMessage`() = runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TIER to true, Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithBadResponse,
featureManager = featureManager,
)
val result = createChangeTierDeductibleIntentUseCase.invoke(testId, ChangeTierCreateSource.SELF_SERVICE)

assertk.assertThat(result)
.isNotNull()
.isLeft()
}

@Test
fun `when response is otherwise good but the intent is null the result is ErrorMessage`() = runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TIER to true, Feature.TRAVEL_ADDON to true))
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodButNullResponse,
featureManager = featureManager,
Expand All @@ -444,7 +411,7 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {
@Test
fun `when response is otherwise good but the tierName in existing agreement is null the result is ErrorMessage`() =
runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TIER to true, Feature.TRAVEL_ADDON to true))
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodResponseButNullTierNameInExisting,
featureManager = featureManager,
Expand All @@ -459,7 +426,7 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {
@Test
fun `when response is otherwise good but the tierName in one of the quotes is null the result is ErrorMessage`() =
runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TIER to true, Feature.TRAVEL_ADDON to true))
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodResponseButNullTierNameInOneQuote,
featureManager = featureManager,
Expand All @@ -473,7 +440,7 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {

@Test
fun `in good response one of the quotes should have the current const id`() = runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TIER to true, Feature.TRAVEL_ADDON to true))
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodResponse,
featureManager = featureManager,
Expand All @@ -492,4 +459,18 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {
.prop(TierDeductibleQuote::id)
.isEqualTo(TierConstants.CURRENT_ID)
}

@Test
fun `when response is bad the result is ErrorMessage`() = runTest {
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithBadResponse,
featureManager = featureManager,
)
val result = createChangeTierDeductibleIntentUseCase.invoke(testId, ChangeTierCreateSource.SELF_SERVICE)

assertk.assertThat(result)
.isNotNull()
.isLeft()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ private fun CustomizeTravelAddonCard(
),
size = Small,
containerColor = HedvigTheme.colorScheme.fillNegative,
hintText = stringResource(R.string.ADDON_FLOW_SELECT_DAYS_PLACEHOLDER), // there is always one option chosen, should never be shown anyway
// there is always one option chosen, should never be shown anyway
hintText = stringResource(R.string.ADDON_FLOW_SELECT_DAYS_PLACEHOLDER),
chosenItemIndex = uiState.travelAddonOffer.addonOptions.indexOf(uiState.currentlyChosenOption)
.takeIf { it >= 0 },
onDoAlongWithDismissRequest = onSetOptionBackToPreviouslyChosen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ private fun SummarySuccessScreen(uiState: Content, onConfirmClick: () -> Unit, n
R.string.ADDON_FLOW_PRICE_LABEL,
uiState.totalPriceChange.amount.toInt(),
)
} // without + (supposedly with minus)
else {
} else {
// without + (supposedly with minus)
stringResource(
R.string.TERMINATION_FLOW_PAYMENT_PER_MONTH, // todo: mb better to have a separate key?
uiState.totalPriceChange.amount.toInt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import arrow.core.raise.either
import com.apollographql.apollo.ApolloClient
import com.hedvig.android.apollo.safeExecute
import com.hedvig.android.core.common.ErrorMessage
import com.hedvig.android.featureflags.FeatureManager
import com.hedvig.android.featureflags.flags.Feature.TIER
import com.hedvig.android.logger.LogPriority.ERROR
import com.hedvig.android.logger.logcat
import kotlinx.coroutines.flow.first
import octopus.CurrentContractsForTierChangeQuery

internal interface GetCurrentContractDataUseCase {
Expand All @@ -18,15 +15,9 @@ internal interface GetCurrentContractDataUseCase {

internal class GetCurrentContractDataUseCaseImpl(
private val apolloClient: ApolloClient,
private val featureManager: FeatureManager,
) : GetCurrentContractDataUseCase {
override suspend fun invoke(insuranceId: String): Either<ErrorMessage, CurrentContractData> {
return either {
val isTierEnabled = featureManager.isFeatureEnabled(TIER).first()
if (!isTierEnabled) {
logcat(ERROR) { "Tried to start Change Tier flow when feature flag is disabled" }
raise(ErrorMessage("Tried to start Change Tier flow when feature flag is disabled"))
}
val result = apolloClient
.query(CurrentContractsForTierChangeQuery())
.safeExecute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import com.hedvig.android.apollo.safeFlow
import com.hedvig.android.core.common.ErrorMessage
import com.hedvig.android.data.contract.ContractGroup
import com.hedvig.android.data.contract.toContractGroup
import com.hedvig.android.featureflags.FeatureManager
import com.hedvig.android.featureflags.flags.Feature
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import octopus.ContractsEligibleForTierChangeQuery

interface GetCustomizableInsurancesUseCase {
Expand All @@ -22,22 +20,16 @@ interface GetCustomizableInsurancesUseCase {

internal class GetCustomizableInsurancesUseCaseImpl(
private val apolloClient: ApolloClient,
private val featureManager: FeatureManager,
) : GetCustomizableInsurancesUseCase {
override suspend fun invoke(): Flow<Either<ErrorMessage, NonEmptyList<CustomisableInsurance>?>> {
return combine(
featureManager.isFeatureEnabled(Feature.TIER),
apolloClient
.query(ContractsEligibleForTierChangeQuery())
.safeFlow(::ErrorMessage),
) { isEnabled, memberResponse ->
either {
if (!isEnabled) {
raise(ErrorMessage())
return apolloClient
.query(ContractsEligibleForTierChangeQuery())
.safeFlow(::ErrorMessage)
.map { memberResponse ->
either {
memberResponse.bind().currentMember.toInsurancesForChangingTier().toNonEmptyListOrNull()
}
memberResponse.bind().currentMember.toInsurancesForChangingTier().toNonEmptyListOrNull()
}
}
}
}

Expand Down
Loading

0 comments on commit e5d4c14

Please sign in to comment.