From c92ea39bfda931534e014039d3afd4af56a59499 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 18 Apr 2022 13:44:07 -0500 Subject: [PATCH] Say what customer was affected --- lib/bill_plan_command.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/bill_plan_command.rb b/lib/bill_plan_command.rb index 79a72afca098a6ee8f806e1444772522235b86fe..c1a87308eeda3ee0db6ac88bc71b8e9cd70c7986 100644 --- a/lib/bill_plan_command.rb +++ b/lib/bill_plan_command.rb @@ -2,7 +2,7 @@ class BillPlanCommand def self.for(customer) - return ForUnregistered.new unless customer.registered? + return ForUnregistered.new(customer) unless customer.registered? unless customer.balance > customer.monthly_price return ForLowBalance.new(customer) @@ -19,7 +19,7 @@ class BillPlanCommand @customer.bill_plan(note: "Renew account plan") Command.reply do |reply| reply.note_type = :info - reply.note_text = "Customer billed" + reply.note_text = "#{@customer.customer_id} billed" end end @@ -30,12 +30,12 @@ class BillPlanCommand def call LowBalance.for(@customer).then(&:notify!).then do |amount| - return command_for(amount).call if amount&.positive? + next command_for(amount).call if amount&.positive? notify_failure Command.reply do |reply| reply.note_type = :error - reply.note_text = "Customer balance is too low" + reply.note_text = "#{@customer.customer_id} balance is too low" end end end @@ -59,10 +59,14 @@ class BillPlanCommand end class ForUnregistered + def initialize(customer) + @customer = customer + end + def call Command.reply do |reply| reply.note_type = :error - reply.note_text = "Customer is not registered" + reply.note_text = "#{@customer.customer_id} is not registered" end end end