diff --git a/lib/customer_info.rb b/lib/customer_info.rb index 4565149f023280d839229dbd8f907ab294b66162..880e85677b49d4fa9be27c497c6f40df00e79015 100644 --- a/lib/customer_info.rb +++ b/lib/customer_info.rb @@ -103,14 +103,18 @@ class AdminInfo trust_level String end - def self.for(customer, plan, trust_level_repo: TrustLevelRepo.new) + def self.for( + customer, plan, + trust_level_repo: TrustLevelRepo.new, + call_attempt_repo: CallAttemptRepo.new + ) PromiseHash.all( jid: customer.jid, customer_id: customer.customer_id, fwd: customer.fwd, info: CustomerInfo.for(customer, plan), api: customer.api, - call_info: call_info(customer), + call_info: call_info(customer, call_attempt_repo), trust_level: trust_level_repo.find(customer).then(&:to_s) ).then(&method(:new)) end @@ -125,10 +129,10 @@ class AdminInfo end end - def self.call_info(customer) + def self.call_info(customer, call_attempt_repo) if customer.registered? - CallAttemptRepo.new - .find_outbound(customer, "+1", call_id: "", low_balance: FakeLowBalance) + call_attempt_repo + .find_outbound(customer, "+1", call_id: "dry_run") .then(&:to_s) else EMPromise.resolve("No calling") diff --git a/test/test_customer_info.rb b/test/test_customer_info.rb index 6abafbcc2577b46efa7e7bfd9e60195335203c30..19e2454043001e958927285981e0b5b1da48d18c 100644 --- a/test/test_customer_info.rb +++ b/test/test_customer_info.rb @@ -58,6 +58,39 @@ class CustomerInfoTest < Minitest::Test end em :test_admin_info_does_not_crash + def test_admin_info_with_tel_does_not_crash + registered = Struct.new(:phone).new("+12223334444") + fwd = CustomerFwd.for(uri: "tel:+12223334444", timeout: 15) + sgx = Struct.new(:registered?, :fwd).new(registered, fwd) + + CustomerPlan::DB.expect( + :query_one, + EMPromise.resolve({ start_date: Time.now }), + [String, "test"] + ) + + cust = customer(sgx: sgx, plan_name: "test_usd") + + call_attempt_repo = Minitest::Mock.new + call_attempt_repo.expect( + :find_outbound, + CallAttempt::Unsupported.new(direction: :outbound), + [cust, "+1", { call_id: "dry_run" }] + ) + + trust_repo = Minitest::Mock.new + trust_repo.expect(:find, TrustLevel::Basement, [cust]) + + assert cust + .admin_info( + trust_level_repo: trust_repo, + call_attempt_repo: call_attempt_repo + ).sync.form + assert_mock call_attempt_repo + assert_mock trust_repo + end + em :test_admin_info_with_tel_does_not_crash + def test_inactive_info_does_not_crash sgx = Minitest::Mock.new sgx.expect(:registered?, false)