~singpolyma/sgx-jmp

ref: 4be555de103e992ee7e03feb48b45c1eca917c45 sgx-jmp/test/test_buy_account_credit_form.rb -rw-r--r-- 1.2 KiB
4be555deStephen Paul Weber Split logic out into testable objects 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

require "test_helper"
require "buy_account_credit_form"
require "customer"

class BuyAccountCreditFormTest < Minitest::Test
	def setup
		@customer = Customer.new(
			1,
			plan_name: "test_usd",
			balance: BigDecimal.new("12.1234")
		)
		@customer.instance_variable_set(
			:@payment_methods,
			EMPromise.resolve(PaymentMethods.new([
				OpenStruct.new(card_type: "Test", last_4: "1234")
			]))
		)
		@form = BuyAccountCreditForm.new(@customer)
	end

	def test_balance
		assert_equal(
			{ type: "fixed", value: "Current balance: $12.12" },
			@form.balance
		)
	end

	def test_add_to_form
		iq_form = Blather::Stanza::X.new
		@form.add_to_form(iq_form).sync
		assert_equal :form, iq_form.type
		assert_equal "Buy Account Credit", iq_form.title
		assert_equal(
			[
				Blather::Stanza::X::Field.new(
					type: "fixed",
					value: "Current balance: $12.12"
				),
				Blather::Stanza::X::Field.new(
					type: "list-single",
					var: "payment_method",
					label: "Credit card to pay with",
					value: "",
					required: true,
					options: [{ label: "Test 1234", value: "0" }]
				),
				BuyAccountCreditForm::AMOUNT_FIELD
			],
			iq_form.fields
		)
	end
	em :test_add_to_form
end