fix(#458): pass customer as @-var to PleaseTopUp
Phillip Davis
created 1 month ago
SIMAction mixin referenced @customer, but PleaseTopUp
didn't have such a field, which caused "undefined
method `jid’ for nil:NilClass" when checking customer onboarding
Change summary
lib/sim_order.rb | 5 +++--
test/test_sim_order.rb | 30 ++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
Detailed changes
@@ -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
@@ -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