~singpolyma/sgx-jmp

ref: 6665370def4be4097eda0de37d29c288954936ed sgx-jmp/test/test_payment_methods.rb -rw-r--r-- 1.9 KiB
6665370dStephen Paul Weber No low balance if not registered 8 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true

require "test_helper"
require "payment_methods"

class PaymentMethodsTest < Minitest::Test
	def test_for_braintree_customer
		braintree_customer = Minitest::Mock.new
		braintree_customer.expect(:payment_methods, [
			OpenStruct.new(card_type: "Test", last_4: "1234")
		])
		methods = PaymentMethods.for_braintree_customer(braintree_customer)
		assert_kind_of PaymentMethods, methods
	end

	def test_for_braintree_customer_no_methods
		braintree_customer = Minitest::Mock.new
		braintree_customer.expect(:payment_methods, [])
		methods = PaymentMethods.for_braintree_customer(braintree_customer)
		assert_raises do
			methods.to_list_single
		end
	end

	def test_default_payment_method
		methods = PaymentMethods.new([
			OpenStruct.new(card_type: "Test", last_4: "1234"),
			OpenStruct.new(card_type: "Test", last_4: "1234", default?: true)
		])
		assert_equal methods.fetch(1), methods.default_payment_method
	end

	def test_default_payment_method_index
		methods = PaymentMethods.new([
			OpenStruct.new(card_type: "Test", last_4: "1234"),
			OpenStruct.new(card_type: "Test", last_4: "1234", default?: true)
		])
		assert_equal "1", methods.default_payment_method_index
	end

	def test_to_options
		methods = PaymentMethods.new([
			OpenStruct.new(card_type: "Test", last_4: "1234")
		])
		assert_equal(
			[
				{ value: "0", label: "Test 1234" }
			],
			methods.to_options
		)
	end

	def test_to_list_single
		methods = PaymentMethods.new([
			OpenStruct.new(card_type: "Test", last_4: "1234")
		])
		assert_equal(
			{
				var: "payment_method",
				type: "list-single",
				label: "Credit card to pay with",
				required: true,
				value: nil,
				options: [
					{ value: "0", label: "Test 1234" }
				]
			},
			methods.to_list_single
		)
	end

	class EmptyTest < Minitest::Test
		def test_to_list_single
			assert_raises do
				PaymentMethods::Empty.new.to_list_single
			end
		end
	end
end