This thread contains a patchset. You're looking at the original emails,
but you may wish to use the patch review UI.
Review patch
1
[PATCH] fetch route and include it in form
---
forms/admin_info.rb | 6 ++++
lib/customer_info.rb | 13 +++++++--
test/test_customer_info.rb | 49 ++++++++++++++++++++++++++++++++-
test/test_customer_info_form.rb | 6 ++++
test/test_helper.rb | 7 +++++
test/test_porting_step.rb | 10 ++++++-
6 files changed, 86 insertions(+), 5 deletions(-)
diff --git a/forms/admin_info.rb b/forms/admin_info.rb
index 5a4d967..9b5a991 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 4833ded..e52808b 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 bdec062..c8d1094 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 72ce2e5..b5dd5b6 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 991de6c..f7391c3 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 0067451..71111e6 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
--
2.34.1
[PATCH v2] fetch route and include it in form
---
forms/admin_info.rb | 6 ++++
lib/customer_info.rb | 13 +++++++--
test/test_customer_info.rb | 49 ++++++++++++++++++++++++++++++++-
test/test_customer_info_form.rb | 6 ++++
test/test_helper.rb | 7 +++++
test/test_porting_step.rb | 10 ++++++-
6 files changed, 86 insertions(+), 5 deletions(-)
diff --git a/forms/admin_info.rb b/forms/admin_info.rb
index 5a4d967..9b5a991 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 4833ded..e52808b 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 bdec062..c8d1094 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 72ce2e5..b5dd5b6 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 991de6c..f7391c3 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 0067451..71111e6 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
--
2.34.1