Ceil monthly data limit steps
Amolith
created 1 month ago
Monthly data limit choices are in whole dollars, but a 5GB refill can
cost a fractional dollar amount. Round the refill price up when deriving
the step so valid choices cover the full refill charge.
Change summary
lib/monthly_data_limit.rb | 4 +---
lib/sim_pricing.rb | 6 ------
test/test_monthly_data_limit.rb | 18 +++++++++++++++---
test/test_plan_settings_form.rb | 7 +++++++
4 files changed, 23 insertions(+), 12 deletions(-)
Detailed changes
@@ -10,9 +10,7 @@ module MonthlyDataLimit
end
def self.for_currency(currency, config)
- step = SIMPricing.whole_dollars(
- SIMPricing.five_gb_refill_price(currency, config)
- )
+ step = SIMPricing.five_gb_refill_price(currency, config).ceil
{
step: step,
max: step * MAX_MULTIPLIER
@@ -34,10 +34,4 @@ module SIMPricing
annual_price(currency, config)
]
end
-
- # CustomerRepo#put_monthly_limits stores limits with to_i, so render monthly
- # data limit form steps in that same integer-dollar unit.
- def self.whole_dollars(price)
- price.to_i
- end
end
@@ -78,7 +78,7 @@ class MonthlyDataLimitTest < Minitest::Test
assert_equal({}, MonthlyDataLimit.for_sims([], :CAD, CONFIG))
end
- def test_uses_integer_dollars_for_fractional_refill_price
+ def test_ceil_integer_dollars_for_fractional_refill_price
config = CONFIG.merge(
sims: CONFIG[:sims].merge(
per_gb: CONFIG[:sims][:per_gb].merge(CAD: 125)
@@ -86,7 +86,19 @@ class MonthlyDataLimitTest < Minitest::Test
)
limits = MonthlyDataLimit.for_currency(:CAD, config)
- assert_equal 6, limits[:step]
- assert_equal 60, limits[:max]
+ assert_equal 7, limits[:step]
+ assert_equal 70, limits[:max]
+ end
+
+ def test_ceil_six_ninety_nine_per_gb_for_step
+ config = CONFIG.merge(
+ sims: CONFIG[:sims].merge(
+ per_gb: CONFIG[:sims][:per_gb].merge(CAD: 699)
+ )
+ )
+ limits = MonthlyDataLimit.for_currency(:CAD, config)
+
+ assert_equal 35, limits[:step]
+ assert_equal 350, limits[:max]
end
end
@@ -70,4 +70,11 @@ class PlanSettingsFormTest < Minitest::Test
assert_equal "10", field.value
end
+
+ def test_monthly_data_limit_keeps_invalid_existing_value_out_of_options
+ field = render(data_limit: "7").field("monthly_data_limit")
+
+ assert_equal "7", field.value
+ refute_includes field.options.map(&:value), "7"
+ end
end