From a5feabef36dd083ec40ec4e6a824c446cf954f6d Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Fri, 7 Nov 2025 11:33:41 -0500 Subject: [PATCH] fix(#458): pass customer as @-var to PleaseTopUp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SIMAction mixin referenced @customer, but PleaseTopUp didn't have such a field, which caused "undefined method `jid’ for nil:NilClass" when checking customer onboarding --- lib/sim_order.rb | 5 +++-- test/test_sim_order.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/sim_order.rb b/lib/sim_order.rb index 03a033e4c073e4c59589cc4f30a854b813f2c7d4..dc7b04082a695251d6a6e1bd318b782504097c94 100644 --- a/lib/sim_order.rb +++ b/lib/sim_order.rb @@ -44,7 +44,7 @@ class SIMOrder if top_up.can_top_up? WithTopUp.new(customer, self, price: price, top_up: top_up, **kwargs) else - PleaseTopUp.new(price: price, **kwargs) + PleaseTopUp.new(price: price, customer: customer, **kwargs) end end end @@ -242,9 +242,10 @@ protected class PleaseTopUp include SIMAction - def initialize(price:, plan:) + def initialize(price:, plan:, customer:) @price = price @plan = plan + @customer = customer end def form diff --git a/test/test_sim_order.rb b/test/test_sim_order.rb index 886b95d1e6f14d6687f1cb3a953ce986ab7f241e..39c280696a282bc60ad8f46489c8c341072194e9 100644 --- a/test/test_sim_order.rb +++ b/test/test_sim_order.rb @@ -222,4 +222,34 @@ class SIMOrderTest < Minitest::Test } end em :test_complete_nick_present + + def test_please_top_up_process_with_insufficient_balanace + customer = customer(balance: 0) + + execute_command { + LowBalance::AutoTopUp.stub( + :for, + OpenStruct.new(can_top_up?: false), + [customer, @price] + ) do + order = SIMOrder.for(customer, price: @price, plan: @plan_name) + + assert_kind_of( + SIMOrder::PleaseTopUp, + order + ) + + Command::COMMAND_MANAGER.expect( + :write, + EMPromise.reject(:test_result), + [Matching.new do |iq| + assert iq.allowed_actions.include?(:complete) + end] + ) + + order.process.catch { |e| e }.sync + end + } + end + em :test_please_top_up_process_with_insufficient_balanace end