M lib/buy_account_credit_form.rb => lib/buy_account_credit_form.rb +1 -1
@@ 4,7 4,7 @@ require_relative "./xep0122_field"
class BuyAccountCreditForm
def self.for(customer)
- @customer.payment_methods.then do |payment_methods|
+ customer.payment_methods.then do |payment_methods|
new(customer.balance, payment_methods)
end
end
M test/test_buy_account_credit_form.rb => test/test_buy_account_credit_form.rb +16 -0
@@ 4,6 4,8 @@ require "test_helper"
require "buy_account_credit_form"
require "customer"
+Customer::BRAINTREE = Minitest::Mock.new
+
class BuyAccountCreditFormTest < Minitest::Test
def setup
@payment_method = OpenStruct.new(card_type: "Test", last_4: "1234")
@@ 13,6 15,20 @@ class BuyAccountCreditFormTest < Minitest::Test
)
end
+ def test_for
+ braintree_customer = Minitest::Mock.new
+ Customer::BRAINTREE.expect(:customer, braintree_customer)
+ braintree_customer.expect(:find, EMPromise.resolve(
+ OpenStruct.new(payment_methods: [])
+ ), ["test"])
+
+ assert_kind_of(
+ BuyAccountCreditForm,
+ BuyAccountCreditForm.for(Customer.new("test")).sync
+ )
+ end
+ em :test_for
+
def test_balance
assert_equal(
{ type: "fixed", value: "Current balance: $12.12" },