~singpolyma/sgx-jmp

ref: 023c87a11bbaa6bd3eaeb3977330b8ea80ded0cd sgx-jmp/test/test_alt_top_up_form.rb -rw-r--r-- 1.9 KiB
023c87a1Stephen Paul Weber Quieter voicemail beep 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# frozen_string_literal: true

require "test_helper"
require "alt_top_up_form"
require "customer"

class AltTopUpFormTest < Minitest::Test
	def test_for
		Customer::REDIS.expect(
			:smembers,
			EMPromise.resolve([]),
			["jmp_customer_btc_addresses-test"]
		)
		assert_kind_of(
			AltTopUpForm,
			AltTopUpForm.for(customer).sync
		)
	end
	em :test_for

	def test_for_addresses
		Customer::REDIS.expect(
			:smembers,
			EMPromise.resolve(["testaddr"]),
			["jmp_customer_btc_addresses-test"]
		)
		assert_kind_of(
			AltTopUpForm,
			AltTopUpForm.for(customer).sync
		)
	end
	em :test_for_addresses

	def test_for_cad
		Customer::REDIS.expect(
			:smembers,
			EMPromise.resolve([]),
			["jmp_customer_btc_addresses-test"]
		)
		assert_kind_of(
			AltTopUpForm,
			AltTopUpForm.for(customer(plan_name: "test_cad")).sync
		)
	end
	em :test_for_cad

	def test_form_addrs
		assert_kind_of(
			Blather::Stanza::X,
			AltTopUpForm.new(
				customer,
				AltTopUpForm::AddBtcAddressField.new
			).form
		)
	end

	def test_form_new_addrs
		assert_kind_of(
			Blather::Stanza::X,
			AltTopUpForm.new(
				customer,
				AltTopUpForm::AddBtcAddressField::AddNewBtcAddressField.new
			).form
		)
	end

	def test_parse_true
		iq_form = Blather::Stanza::X.new
		iq_form.fields = [
			{ var: "add_btc_address", value: "true" }
		]
		assert AltTopUpForm.new(customer).parse(iq_form)[:add_btc_address]
	end

	def test_parse_1
		iq_form = Blather::Stanza::X.new
		iq_form.fields = [
			{ var: "add_btc_address", value: "1" }
		]
		assert AltTopUpForm.new(customer).parse(iq_form)[:add_btc_address]
	end

	def test_parse_false
		iq_form = Blather::Stanza::X.new
		iq_form.fields = [
			{ var: "add_btc_address", value: "false" }
		]
		refute AltTopUpForm.new(customer).parse(iq_form)[:add_btc_address]
	end

	def test_parse_not_presend
		iq_form = Blather::Stanza::X.new
		refute AltTopUpForm.new(customer).parse(iq_form)[:add_btc_address]
	end
end