~singpolyma/sgx-jmp

1c269719d83b57d0f6080c34092da6c0cbf7905f — Stephen Paul Weber 1 year, 2 months ago 1148e56
Show current balance in alt top up form
3 files changed, 24 insertions(+), 9 deletions(-)

M lib/alt_top_up_form.rb
M test/test_add_bitcoin_address.rb
M test/test_alt_top_up_form.rb
M lib/alt_top_up_form.rb => lib/alt_top_up_form.rb +11 -2
@@ 3,7 3,7 @@
class AltTopUpForm
	def self.for(customer)
		customer.btc_addresses.then do |addrs|
			AltTopUpForm.new(*[
			AltTopUpForm.new(customer, *[
				(IS_CAD if customer.currency == :CAD),
				(HasBitcoinAddresses.new(addrs) unless addrs.empty?),
				AddBtcAddressField.for(addrs)


@@ 11,8 11,9 @@ class AltTopUpForm
		end
	end

	def initialize(*fields)
	def initialize(customer, *fields)
		@fields = fields
		@balance = customer.balance
	end

	def form


@@ 35,6 36,13 @@ class AltTopUpForm
		}
	end

	def balance
		{
			type: "fixed",
			value: "Current balance: $#{'%.4f' % @balance}"
		}
	end

	MAILING_ADDRESS = {
		var: "adr",
		type: "fixed",


@@ 47,6 55,7 @@ class AltTopUpForm

	def fields
		Enumerator.new do |y|
			y << balance
			y << MAILING_ADDRESS
			@fields.each do |fs|
				fs.each { |f| y << f }

M test/test_add_bitcoin_address.rb => test/test_add_bitcoin_address.rb +4 -2
@@ 7,13 7,15 @@ require "add_bitcoin_address"
class AddBitcoinAddressTest < Minitest::Test
	def test_for
		iq = Blather::Stanza::Iq::Command.new
		AddBitcoinAddress.for(iq, AltTopUpForm.new, Customer.new("test"))
		customer = Customer.new("test")
		AddBitcoinAddress.for(iq, AltTopUpForm.new(customer), customer)
	end

	def test_for_add_bitcoin
		iq = Blather::Stanza::Iq::Command.new
		iq.form.fields = [{ var: "add_btc_address", value: "true" }]
		AddBitcoinAddress.for(iq, AltTopUpForm.new, Customer.new("test"))
		customer = Customer.new("test")
		AddBitcoinAddress.for(iq, AltTopUpForm.new(customer), customer)
	end

	def test_write

M test/test_alt_top_up_form.rb => test/test_alt_top_up_form.rb +9 -5
@@ 47,7 47,10 @@ class AltTopUpFormTest < Minitest::Test
	def test_form_addrs
		assert_kind_of(
			Blather::Stanza::X,
			AltTopUpForm.new(AltTopUpForm::AddBtcAddressField.new).form
			AltTopUpForm.new(
				Customer.new("test"),
				AltTopUpForm::AddBtcAddressField.new
			).form
		)
	end



@@ 55,6 58,7 @@ class AltTopUpFormTest < Minitest::Test
		assert_kind_of(
			Blather::Stanza::X,
			AltTopUpForm.new(
				Customer.new("test"),
				AltTopUpForm::AddBtcAddressField::AddNewBtcAddressField.new
			).form
		)


@@ 65,7 69,7 @@ class AltTopUpFormTest < Minitest::Test
		iq_form.fields = [
			{ var: "add_btc_address", value: "true" }
		]
		assert AltTopUpForm.new.parse(iq_form)[:add_btc_address]
		assert AltTopUpForm.new(Customer.new("t")).parse(iq_form)[:add_btc_address]
	end

	def test_parse_1


@@ 73,7 77,7 @@ class AltTopUpFormTest < Minitest::Test
		iq_form.fields = [
			{ var: "add_btc_address", value: "1" }
		]
		assert AltTopUpForm.new.parse(iq_form)[:add_btc_address]
		assert AltTopUpForm.new(Customer.new("t")).parse(iq_form)[:add_btc_address]
	end

	def test_parse_false


@@ 81,11 85,11 @@ class AltTopUpFormTest < Minitest::Test
		iq_form.fields = [
			{ var: "add_btc_address", value: "false" }
		]
		refute AltTopUpForm.new.parse(iq_form)[:add_btc_address]
		refute AltTopUpForm.new(Customer.new("t")).parse(iq_form)[:add_btc_address]
	end

	def test_parse_not_presend
		iq_form = Blather::Stanza::X.new
		refute AltTopUpForm.new.parse(iq_form)[:add_btc_address]
		refute AltTopUpForm.new(Customer.new("t")).parse(iq_form)[:add_btc_address]
	end
end