From 1b94a4c72a3931394d943636edfdc867ddf204d8 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 16 Feb 2026 10:14:29 -0500 Subject: [PATCH] Data only fixes --- lib/registration.rb | 5 +---- lib/sim_kind.rb | 11 ++++------- test/test_sim_kind.rb | 30 +++++++++++++----------------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/lib/registration.rb b/lib/registration.rb index fd37f5f2c7aa816ed93d8b950b79211456947e9d..928442d70bd060bd75b12abd7b48e71612767eda 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -43,7 +43,6 @@ class Registration Command.reply { |reply| reply.command << FormTemplate.render( "registration/pay_without_code", - product: @sim_kind, instructions: instructions, currency_required: !@customer.currency, title: "Pay for #{@sim_kind.label}" @@ -97,9 +96,7 @@ class Registration def write @sim_kind.get_processor(@customer).then { |order| # NOTE: cheogram will swallow any stanza - # with type `completed` - # `can_complete: false` is needed to prevent customer - # from (possibly) permanently losing their eSIM QR code + # with available action `complete` order.process(can_complete: false) } end diff --git a/lib/sim_kind.rb b/lib/sim_kind.rb index c65f02c784a503621fa062148f32a6a7014baad8..553552ffd8c5fc6dc4e00b2c4afd32036f6eece4 100644 --- a/lib/sim_kind.rb +++ b/lib/sim_kind.rb @@ -8,6 +8,8 @@ class SIMKind SIMOrder when "esim" SIMOrder::ESIM + else + raise "Unknown SIM kind" end @variant = variant end @@ -23,10 +25,7 @@ class SIMKind cfg = cfg(customer.currency) raise ArgumentError, "Invalid config" unless cfg - @klass.new( - customer, - **cfg - ) + @klass.for(customer, **cfg) end # @return [String] The result of either @@ -39,9 +38,7 @@ class SIMKind # @return [Float, NilClass] Returns nil if `customer.currency` # is nil, or if @variant is malformed. def price(customer) - cfg = cfg(customer.currency) - return nil unless cfg - + cfg = cfg(customer.currency || :USD) cfg[:price] / 100.to_d end diff --git a/test/test_sim_kind.rb b/test/test_sim_kind.rb index a121bae47c263048f4bb4af7845594da6c5ed52e..8e5500f18d40c8c5e04c36d5ed2f89af153316b1 100644 --- a/test/test_sim_kind.rb +++ b/test/test_sim_kind.rb @@ -26,7 +26,7 @@ class SIMKindTest < Minitest::Test iq.form.fields = [] } - @cust = customer(plan_name: "test_usd") + @cust = customer(plan_name: "test_usd", balance: 1000) end def test_initialize_with_sim @@ -40,13 +40,15 @@ class SIMKindTest < Minitest::Test end def test_initialize_with_invalid_variant - kind = SIMKind.new("invalid") - assert_raises(ArgumentError) { kind.get_processor(@cust) } + assert_raises do + SIMKind.new("invalid") + end end def test_initialize_with_nil - kind = SIMKind.new(nil) - assert_raises(NoMethodError) { kind.get_processor(@cust) } + assert_raises do + SIMKind.new(nil) + end end def test_from_form_with_sim @@ -59,21 +61,15 @@ class SIMKindTest < Minitest::Test assert_instance_of SIMOrder::ESIM, kind.get_processor(@cust) end - def test_price_returns_nil_when_customer_currency_nil + def test_price_returns_usd_when_customer_currency_nil kind = SIMKind.new("sim") cust = customer(currency: nil) - assert_nil kind.price(cust) + assert_equal 5, kind.price(cust) end - def test_price_returns_nil_when_config_missing_variant - kind = SIMKind.new("invalid") - cust = customer(currency: :USD) - assert_nil kind.price(cust) - end - - def test_cfg_returns_nil_when_config_missing_currency - kind = SIMKind.new("sim") - cust = customer(currency: :EUR) - assert_nil kind.price(cust) + def test_price_raises_when_config_missing_variant + assert_raises do + SIMKind.new("invalid") + end end end