diff --git a/forms/plan_info.rb b/forms/plan_info.rb index bbc3ddb7ad55862c2f449d7d842f35d13852d5ec..1e148ea6241d0ca74fb612b7e042cc1f7fc627bc 100644 --- a/forms/plan_info.rb +++ b/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", diff --git a/test/test_customer_info.rb b/test/test_customer_info.rb index efe50f8d4faf9a3b706f34463a4f89f1e8626dfb..c8d1094c354918c386fe02de29017a58bc86e145 100644 --- a/test/test_customer_info.rb +++ b/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)