~singpolyma/sgx-jmp

ref: 22b1197950d1d80422c61982f060ae0c20c87a8c sgx-jmp/test/test_buy_account_credit_form.rb -rw-r--r-- 1.8 KiB
22b11979Stephen Paul Weber Fix sentry issue SGX-JMP-4 2 years 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true

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")
		@form = BuyAccountCreditForm.new(
			BigDecimal.new("12.1234"),
			PaymentMethods.new([@payment_method])
		)
	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" },
			@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