diff --git a/forms/admin_info.rb b/forms/admin_info.rb index 1da597a6efb4b17c9ed2a36a3870ce1707aa6935..c655c80735ef8875ed2c1b4e57c33e013f0d61d7 100644 --- a/forms/admin_info.rb +++ b/forms/admin_info.rb @@ -45,6 +45,12 @@ if @admin_info.fwd.uri ) end +field( + var: "call_info", + label: "Call Status", + value: @admin_info.call_info +) + field( var: "api", label: "API", diff --git a/lib/call_attempt.rb b/lib/call_attempt.rb index 16546689a9221d71d591af767892e9db1475cd22..92bce9bc53c761bc4c3bd6b6bf6cdaa4a647d3f9 100644 --- a/lib/call_attempt.rb +++ b/lib/call_attempt.rb @@ -48,6 +48,10 @@ class CallAttempt ["#{direction}/connect", { locals: to_h }] end + def to_s + "Allowed(max_minutes: #{max_minutes}, limit_remaining: #{limit_remaining})" + end + def create_call(fwd, *args, &block) fwd.create_call(*args, &block) end @@ -119,6 +123,10 @@ class CallAttempt [view] end + def to_s + "Unsupported" + end + def create_call(*); end def as_json(*) @@ -135,8 +143,8 @@ class CallAttempt self.for(rate: rate, **kwargs) if credit < rate * 10 end - def self.for(customer:, direction:, **kwargs) - LowBalance.for(customer).then(&:notify!).then do |amount| + def self.for(customer:, direction:, low_balance: LowBalance, **kwargs) + low_balance.for(customer).then(&:notify!).then do |amount| if amount&.positive? CallAttempt.for( customer: customer.with_balance(customer.balance + amount), @@ -165,6 +173,10 @@ class CallAttempt [view, { locals: to_h }] end + def to_s + "NoBalance" + end + def create_call(*); end def as_json(*) @@ -211,6 +223,11 @@ class CallAttempt [view, { locals: to_h }] end + def to_s + "AtLimit(max_minutes: #{max_minutes}, "\ + "limit_remaining: #{limit_remaining})" + end + def create_call(fwd, *args, &block) fwd.create_call(*args, &block) end diff --git a/lib/customer_info.rb b/lib/customer_info.rb index 353f59dfce318afe29f76c952543cf286bf3b126..ddc39a0b97fbe4fe1acbd557a0cce952daf0cc5f 100644 --- a/lib/customer_info.rb +++ b/lib/customer_info.rb @@ -99,6 +99,7 @@ class AdminInfo fwd Either(CustomerFwd, nil) info CustomerInfo api API + call_info String end def self.for(customer, plan) @@ -107,10 +108,31 @@ class AdminInfo customer_id: customer.customer_id, fwd: customer.fwd, info: CustomerInfo.for(customer, plan), - api: customer.api + api: customer.api, + call_info: call_info(customer) ).then(&method(:new)) end + class FakeLowBalance + def self.for(_) + self + end + + def self.notify! + EMPromise.resolve(0) + end + end + + def self.call_info(customer) + if customer.registered? + CallAttemptRepo.new + .find_outbound(customer, "+1", call_id: "", low_balance: FakeLowBalance) + .then(&:to_s) + else + EMPromise.resolve("No calling") + end + end + def form FormTemplate.render("admin_info", admin_info: self) end diff --git a/test/test_customer_info.rb b/test/test_customer_info.rb index 14e371980a10cc694ba0c76b1b474904742ab32a..91239c4df51aaae9828cbd829969f139b86df5dc 100644 --- a/test/test_customer_info.rb +++ b/test/test_customer_info.rb @@ -37,6 +37,7 @@ class CustomerInfoTest < Minitest::Test sgx.expect(:registered?, false) fwd = CustomerFwd.for(uri: "tel:+12223334444", timeout: 15) sgx.expect(:fwd, fwd) + sgx.expect(:registered?, false) CustomerPlan::DB.expect( :query_one, @@ -69,6 +70,7 @@ class CustomerInfoTest < Minitest::Test def test_inactive_admin_info_does_not_crash sgx = Minitest::Mock.new sgx.expect(:registered?, false) + sgx.expect(:registered?, false) sgx.expect(:fwd, CustomerFwd::None.new(uri: nil, timeout: nil)) plan = CustomerPlan.new("test", plan: nil, expires_at: nil)