From 19fd189827e972447dca0742c0629c5e3c877782 Mon Sep 17 00:00:00 2001 From: Amolith Date: Mon, 8 Jun 2026 17:09:09 -0600 Subject: [PATCH] Ceil monthly data limit steps 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. --- 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(-) diff --git a/lib/monthly_data_limit.rb b/lib/monthly_data_limit.rb index 503402a8c49500f331c214b3160085013a454e96..19bd223ebe2b62eefaca1352b22da4fe3b973619 100644 --- a/lib/monthly_data_limit.rb +++ b/lib/monthly_data_limit.rb @@ -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 diff --git a/lib/sim_pricing.rb b/lib/sim_pricing.rb index 9374187c26027be9bddbfbbbc7186310b12abcd2..9d238d2e150560157118d637c10f9866e9a4c0d9 100644 --- a/lib/sim_pricing.rb +++ b/lib/sim_pricing.rb @@ -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 diff --git a/test/test_monthly_data_limit.rb b/test/test_monthly_data_limit.rb index 7d4ac2f96276565663d8e0db09c15781add7f3a6..c1e64965ceb40b8c3ae1f4d8f36300e0a5ef4cb3 100644 --- a/test/test_monthly_data_limit.rb +++ b/test/test_monthly_data_limit.rb @@ -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 diff --git a/test/test_plan_settings_form.rb b/test/test_plan_settings_form.rb index 4ff925a35fa041468f564210fc60df41a5484cc4..101341ce0650838d3abe792a3cab87384841a951 100644 --- a/test/test_plan_settings_form.rb +++ b/test/test_plan_settings_form.rb @@ -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