test_buy_account_credit_form.rb

 1# frozen_string_literal: true
 2
 3require "test_helper"
 4require "buy_account_credit_form"
 5require "customer"
 6
 7class BuyAccountCreditFormTest < Minitest::Test
 8	def setup
 9		@customer = Minitest::Mock.new(Customer.new(
10			1,
11			plan_name: "test_usd",
12			balance: BigDecimal.new("12.1234")
13		))
14		@customer.expect(
15			:payment_methods,
16			EMPromise.resolve(PaymentMethods.new([
17				OpenStruct.new(card_type: "Test", last_4: "1234")
18			]))
19		)
20		@form = BuyAccountCreditForm.new(@customer)
21	end
22
23	def test_balance
24		assert_equal(
25			{ type: "fixed", value: "Current balance: $12.12" },
26			@form.balance
27		)
28	end
29
30	def test_add_to_form
31		iq_form = Blather::Stanza::X.new
32		@form.add_to_form(iq_form).sync
33		assert_equal :form, iq_form.type
34		assert_equal "Buy Account Credit", iq_form.title
35		assert_equal(
36			[
37				Blather::Stanza::X::Field.new(
38					type: "fixed",
39					value: "Current balance: $12.12"
40				),
41				Blather::Stanza::X::Field.new(
42					type: "list-single",
43					var: "payment_method",
44					label: "Credit card to pay with",
45					required: true,
46					options: [{ label: "Test 1234", value: "0" }]
47				),
48				BuyAccountCreditForm::AMOUNT_FIELD
49			],
50			iq_form.fields
51		)
52	end
53	em :test_add_to_form
54end