diff --git a/forms/admin_info.rb b/forms/admin_info.rb index 5a4d9678aa30fa3141cca8fb0333ec398c69736c..b891dcc87b0c1b4ce9f611b66000f69e04f3fd95 100644 --- a/forms/admin_info.rb +++ b/forms/admin_info.rb @@ -69,3 +69,9 @@ field( label: "Support Link", value: @admin_info.support_link ) + +field( + var: "route", + label: "Route", + value: @admin_info.route +) diff --git a/lib/customer_info.rb b/lib/customer_info.rb index 4833dedecc9db6dcefcc7b02075a728df683d64b..70a78561d6ddd0325a9094c475d2a987cd794339 100644 --- a/lib/customer_info.rb +++ b/lib/customer_info.rb @@ -113,7 +113,7 @@ class AdminInfo info CustomerInfo call_info String trust_level String - backend_jid String + backend BackendSgx subaccounts ArrayOf(::Subaccount), default: [] end @@ -129,12 +129,19 @@ class AdminInfo info: CustomerInfo.for(customer), call_info: call_info(customer, call_attempt_repo), trust_level: trust_level_repo.find(customer).then(&:to_s), - backend_jid: backend_repo.get(customer.customer_id) - .then(&:from_jid).then(&:to_s), + backend: backend_repo.get(customer.customer_id), subaccounts: Subaccount.get_subaccounts(customer.billing_customer_id) ).then(&method(:new)) end + def backend_jid + backend.from_jid.to_s + end + + def route + backend.jid + end + class FakeLowBalance def self.for(_) self diff --git a/test/test_customer_info.rb b/test/test_customer_info.rb index bdec0625f23818b1602fa8eaf42fa3a126c0a61c..c8d1094c354918c386fe02de29017a58bc86e145 100644 --- a/test/test_customer_info.rb +++ b/test/test_customer_info.rb @@ -130,7 +130,6 @@ class CustomerInfoTest < Minitest::Test EMPromise.resolve(nil), ["jmp_customer_backend_sgx-test"] ) - cust = customer(sgx: sgx, plan_name: "test_usd") trust_repo = Minitest::Mock.new @@ -300,4 +299,52 @@ class CustomerInfoTest < Minitest::Test assert_mock TrivialBackendSgxRepo::REDIS end em :test_admin_info_subaccount_does_not_crash + + def test_admin_info_includes_route + sgx = Minitest::Mock.new + 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, + EMPromise.resolve({ start_date: Time.now }), + [String, "test"] + ) + + CustomerUsage::DB.expect( + :query_one, + EMPromise.resolve({ charges: 0.to_d }), + [String, "test"] + ) + + Subaccount::DB.expect( + :query_defer, + EMPromise.resolve({}), + [String, ["test"]] + ) + + TrivialBackendSgxRepo::REDIS.expect( + :get, + EMPromise.resolve("route_value"), + ["jmp_customer_backend_sgx-test"] + ) + + cust = customer(sgx: sgx, plan_name: "test_usd") + + trust_repo = Minitest::Mock.new + trust_repo.expect(:find, TrustLevel::Basement, [cust]) + + admin_info = AdminInfo.for(cust, trust_level_repo: trust_repo).sync.form + + assert admin_info + assert admin_info.field("route").value == "route_value" + assert_mock sgx + assert_mock trust_repo + assert_mock CustomerUsage::DB + assert_mock Subaccount::DB + assert_mock TrivialBackendSgxRepo::REDIS + end + em :test_admin_info_includes_route end diff --git a/test/test_customer_info_form.rb b/test/test_customer_info_form.rb index 72ce2e51acca5c71d3aeb736786be984494cc50e..c8e8179d54d67b62be23a1dd660832f2a08833ba 100644 --- a/test/test_customer_info_form.rb +++ b/test/test_customer_info_form.rb @@ -107,4 +107,10 @@ class CustomerInfoFormTest < Minitest::Test assert_nil(result) end em :test_garbage + + def test_route + result = @info_form.parse_something("route").sync + assert_nil(result) + end + em :test_route end diff --git a/test/test_helper.rb b/test/test_helper.rb index 991de6cbe73b8eb716d5c4a367cddab51fa6118c..6235ecfed2e7dae17d3dafeb2bb5f9a861fb797f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -88,6 +88,13 @@ CONFIG = { username: "test_bw_user", password: "test_bw_password" }, + sgx_creds: { + route_value: { + username: "test_sgx_user", + password: "test_sgx_password", + account: "test_sgx_account" + } + }, notify_from: "notify_from@example.org", activation_amount: 1, activation_amount_accept: 1, diff --git a/test/test_porting_step.rb b/test/test_porting_step.rb index 00674517c973ecef9588a1504193cc23831a345e..f172fe687f9f3d60c204c2a56663cb27d5bcac7c 100644 --- a/test/test_porting_step.rb +++ b/test/test_porting_step.rb @@ -69,7 +69,15 @@ def admin_info(customer_id, tel) info: info(tel), call_info: "", trust_level: "", - backend_jid: "customer_#{customer_id}@example.com" + backend: BackendSgx.new( + jid: Blather::JID.new("testroute"), + from_jid: Blather::JID.new("customer_#{customer_id}@example.com"), + creds: {}, + transcription_enabled: false, + registered?: false, + fwd: nil, + ogm_url: nil + ) ) end