Skip to content
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

Remove Feature.TIER entirely #2368

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -368,12 +368,7 @@ 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,
),
)
val featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodResponse,
featureManager = featureManager,
Expand Down Expand Up @@ -401,7 +396,7 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {

@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 featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithGoodResponse,
featureManager = featureManager,
Expand All @@ -415,7 +410,7 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {

@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 featureManager = FakeFeatureManager2(fixedMap = mapOf(Feature.TRAVEL_ADDON to true))
val createChangeTierDeductibleIntentUseCase = CreateChangeTierDeductibleIntentUseCaseImpl(
apolloClient = apolloClientWithBadResponse,
featureManager = featureManager,
Expand All @@ -429,7 +424,7 @@ class CreateChangeTierDeductibleIntentUseCaseImplTest {

@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 +439,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 +454,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 +468,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 Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.hedvig.android.feature.change.tier.ui.chooseinsurance.ChooseInsurance
import com.hedvig.android.feature.change.tier.ui.stepcustomize.SelectCoverageViewModel
import com.hedvig.android.feature.change.tier.ui.stepstart.StartTierFlowViewModel
import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryViewModel
import com.hedvig.android.featureflags.FeatureManager
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module

Expand Down Expand Up @@ -42,14 +41,12 @@ val chooseTierModule = module {
single<GetCurrentContractDataUseCase> {
GetCurrentContractDataUseCaseImpl(
apolloClient = get<ApolloClient>(),
featureManager = get<FeatureManager>(),
)
}

single<GetCustomizableInsurancesUseCase> {
GetCustomizableInsurancesUseCaseImpl(
apolloClient = get<ApolloClient>(),
featureManager = get<FeatureManager>(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ internal data class SelectCoverageSuccessUiState(
val isTierChoiceEnabled: Boolean,
val quoteToNavigateFurther: TierDeductibleQuote? = null,
val quotesToCompare: List<TierDeductibleQuote>? = null,
val tiers: List<Pair<Tier, UiMoney>>, // sorted list of tiers with corresponding premiums (depending on selected deductible)
// sorted list of tiers with corresponding premiums (depending on selected deductible)
val tiers: List<Pair<Tier, UiMoney>>,
val quotesForChosenTier: List<TierDeductibleQuote>,
)

Expand Down
Loading
Loading