Skip to content

Commit 9497db6

Browse files
authored
Round down yearly plan savings % (#7089)
Task/Issue URL: https://app.asana.com/1/137249556945/task/1211855463961045?focus=true ### Description Change rounding strategy from HALF_UP to ROUND_DOWN ### Steps to test this PR _Pre steps_ - [x] Apply patch from https://app.asana.com/1/137249556945/project/1209991789468715/task/1210448620621729?focus=true _Upgrade_ - [x] Install from branch - [x] Purchase a test monthly subscription (Free Trial) - [x] Cancel and wait until Free Trial expires **OR** wait until free trial is renewed to a paid monthly subscription - [x] If expired after canceled, purchase a monthly subscription again - [x] Go to Subscription Settings - [x] Check Switch option is there with updated text "Switch to Yearly and Save 16%" - [x] Select Switch option - [x] Check copy for upgrade option is correct (16%) _Downgrade_ - [x] Switch to yearly - [x] Wait until screen refreshes - [x] Select switch option - [x] Check copy for downgrade option is correct (16%) ### No UI changes
1 parent 2468399 commit 9497db6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

subscriptions/subscriptions-impl/src/main/java/com/duckduckgo/subscriptions/impl/SubscriptionsManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class RealSubscriptionsManager @Inject constructor(
466466
val totalMonthlyAnnual = monthlyPriceAmount * 12.toBigDecimal()
467467
val savingsAmount = totalMonthlyAnnual - yearlyPriceAmount
468468
val savingsPercentage = ((savingsAmount / totalMonthlyAnnual) * 100.toBigDecimal())
469-
.setScale(0, RoundingMode.HALF_UP)
469+
.setScale(0, RoundingMode.DOWN)
470470
.toInt()
471471

472472
SwitchPlanPricingInfo(

subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/RealSubscriptionsManagerTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) {
20222022
assertEquals("$9.99", result!!.currentPrice)
20232023
assertEquals("$99.99", result.targetPrice)
20242024
assertEquals("$8.33", result.yearlyMonthlyEquivalent)
2025-
assertEquals(17, result.savingsPercentage)
2025+
assertEquals(16, result.savingsPercentage)
20262026
}
20272027

20282028
@Test
@@ -2042,7 +2042,7 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) {
20422042
assertEquals("$99.99", result!!.currentPrice)
20432043
assertEquals("$9.99", result.targetPrice)
20442044
assertEquals("$8.33", result.yearlyMonthlyEquivalent)
2045-
assertEquals(17, result.savingsPercentage)
2045+
assertEquals(16, result.savingsPercentage)
20462046
}
20472047

20482048
@Test
@@ -2072,8 +2072,8 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) {
20722072

20732073
assertNotNull(result)
20742074
assertEquals("€7.50", result!!.yearlyMonthlyEquivalent)
2075-
// Savings: (8.99 * 12 - 89.99) / (8.99 * 12) * 100 = 16.58% ≈ 17%
2076-
assertEquals(17, result.savingsPercentage)
2075+
// Savings: (8.99 * 12 - 89.99) / (8.99 * 12) * 100 = 16.58% rounds down to 16%
2076+
assertEquals(16, result.savingsPercentage)
20772077
}
20782078

20792079
@Test
@@ -2091,8 +2091,8 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) {
20912091
val result = subscriptionsManager.getSwitchPlanPricing(isUpgrade = true)
20922092

20932093
assertNotNull(result)
2094-
// Savings: (10 * 12 - 100) / (10 * 12) * 100 = 16.666...% rounds to 17%
2095-
assertEquals(17, result!!.savingsPercentage)
2094+
// Savings: (10 * 12 - 100) / (10 * 12) * 100 = 16.666...% rounds down to 16%
2095+
assertEquals(16, result!!.savingsPercentage)
20962096
}
20972097

20982098
@Test

0 commit comments

Comments
 (0)