~singpolyma/sgx-jmp

ref: 4be555de103e992ee7e03feb48b45c1eca917c45 sgx-jmp/test/test_payment_methods.rb -rw-r--r-- 1.6 KiB
4be555deStephen Paul Weber Split logic out into testable objects 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
# 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 "1", methods.default_payment_method
	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: "",
				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