fetch route and include it in form

Phillip Davis created

Change summary

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(-)

Detailed changes

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
+)

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

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

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

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,

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