1# frozen_string_literal: true
2
3require "test_helper"
4require "alt_top_up_form"
5require "customer"
6
7class AltTopUpFormTest < Minitest::Test
8 def test_for
9 CustomerFinancials::REDIS.expect(
10 :smembers,
11 EMPromise.resolve([]),
12 ["jmp_customer_btc_addresses-test"]
13 )
14 assert_kind_of(
15 AltTopUpForm,
16 AltTopUpForm.for(customer).sync
17 )
18 end
19 em :test_for
20
21 def test_for_addresses
22 CustomerFinancials::REDIS.expect(
23 :smembers,
24 EMPromise.resolve(["testaddr"]),
25 ["jmp_customer_btc_addresses-test"]
26 )
27 assert_kind_of(
28 AltTopUpForm,
29 AltTopUpForm.for(customer).sync
30 )
31 end
32 em :test_for_addresses
33
34 def test_for_cad
35 CustomerFinancials::REDIS.expect(
36 :smembers,
37 EMPromise.resolve([]),
38 ["jmp_customer_btc_addresses-test"]
39 )
40 assert_kind_of(
41 AltTopUpForm,
42 AltTopUpForm.for(customer(plan_name: "test_cad")).sync
43 )
44 end
45 em :test_for_cad
46
47 def test_form_addrs
48 assert_kind_of(
49 Blather::Stanza::X,
50 AltTopUpForm.new(
51 customer, ["some_addr"]
52 ).form
53 )
54 end
55
56 def test_form_new_addrs
57 assert_kind_of(
58 Blather::Stanza::X,
59 AltTopUpForm.new(
60 customer, []
61 ).form
62 )
63 end
64
65 def test_parse_true
66 iq_form = Blather::Stanza::X.new
67 iq_form.fields = [
68 { var: "add_btc_address", value: "true" }
69 ]
70 assert AltTopUpForm.new(customer, []).parse(iq_form)[:add_btc_address]
71 end
72
73 def test_parse_1
74 iq_form = Blather::Stanza::X.new
75 iq_form.fields = [
76 { var: "add_btc_address", value: "1" }
77 ]
78 assert AltTopUpForm.new(customer, []).parse(iq_form)[:add_btc_address]
79 end
80
81 def test_parse_false
82 iq_form = Blather::Stanza::X.new
83 iq_form.fields = [
84 { var: "add_btc_address", value: "false" }
85 ]
86 refute AltTopUpForm.new(customer, []).parse(iq_form)[:add_btc_address]
87 end
88
89 def test_parse_not_presend
90 iq_form = Blather::Stanza::X.new
91 refute AltTopUpForm.new(customer, []).parse(iq_form)[:add_btc_address]
92 end
93end