~singpolyma/sgx-jmp

ref: a9ebca9a66da1fa0e10bee066a6ba71fe31177a3 sgx-jmp/test/test_buy_account_credit_form.rb -rw-r--r-- 1.4 KiB
a9ebca9aStephen Paul Weber Usage command 1 year, 5 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
56
57
58
# frozen_string_literal: true

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

class BuyAccountCreditFormTest < Minitest::Test
	def setup
		@payment_method = OpenStruct.new(card_type: "Test", last_4: "1234")
		@form = BuyAccountCreditForm.new(
			BigDecimal.new("12.1234"),
			PaymentMethods.new([@payment_method])
		)
	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)
		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",
					required: true,
					options: [{ label: "Test 1234", value: "0" }]
				),
				BuyAccountCreditForm::AMOUNT_FIELD
			],
			iq_form.fields
		)
	end

	def test_parse_amount
		iq_form = Blather::Stanza::X.new
		iq_form.fields = [{ var: "amount", value: "123" }]
		assert_equal "123", @form.parse(iq_form)[:amount]
	end

	def test_parse_payment_method
		iq_form = Blather::Stanza::X.new
		iq_form.fields = [{ var: "payment_method", value: "0" }]
		assert_equal @payment_method, @form.parse(iq_form)[:payment_method]
	end
end