Re-add call info to Show Account Info

Amolith created

Fixes: https://todo.sr.ht/~singpolyma/soprani.ca/585

Change summary

forms/plan_info.rb         |  6 ++++
test/test_customer_info.rb | 56 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)

Detailed changes

forms/plan_info.rb 🔗

@@ -1,3 +1,9 @@
+field(
+	var: "remaining_included_calling_credit",
+	label: '"Free" Calls Remaining',
+	value: "$%.4f" % @plan_info.remaining_included_calling_credit
+)
+
 if @admin_info
 	field(
 		var: "plan",

test/test_customer_info.rb 🔗

@@ -44,6 +44,62 @@ class CustomerInfoTest < Minitest::Test
 	end
 	em :test_info_does_not_crash
 
+	def test_info_has_remaining_included_calling_credit
+		sgx = Minitest::Mock.new
+		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.044.to_d }),
+			[String, "test"]
+		)
+
+		cust = customer(sgx: sgx, plan_name: "test_usd")
+
+		assert_equal(
+			"$1.0000",
+			CustomerInfo.for(cust).sync.form
+				.field("remaining_included_calling_credit").value
+		)
+		assert_mock sgx
+		assert_mock CustomerUsage::DB
+	end
+	em :test_info_has_remaining_included_calling_credit
+
+	def test_info_out_of_remaining_included_calling_credit
+		sgx = Minitest::Mock.new
+		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: 10.to_d }),
+			[String, "test"]
+		)
+
+		cust = customer(sgx: sgx, plan_name: "test_usd")
+
+		assert_equal(
+			"$0.0000",
+			CustomerInfo.for(cust).sync.form
+				.field("remaining_included_calling_credit").value
+		)
+		assert_mock sgx
+		assert_mock CustomerUsage::DB
+	end
+	em :test_info_out_of_remaining_included_calling_credit
+
 	def test_admin_info_does_not_crash
 		sgx = Minitest::Mock.new
 		sgx.expect(:registered?, false)