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 CustomerFinancials::REDIS.expect(
15 :smembers,
16 EMPromise.resolve([]),
17 ["jmp_customer_bch_addresses-test"]
18 )
19 assert_kind_of(
20 AltTopUpForm,
21 AltTopUpForm.for(customer).sync
22 )
23 end
24 em :test_for
25
26 def test_for_addresses
27 CustomerFinancials::REDIS.expect(
28 :smembers,
29 EMPromise.resolve(["testaddr"]),
30 ["jmp_customer_btc_addresses-test"]
31 )
32 CustomerFinancials::REDIS.expect(
33 :smembers,
34 EMPromise.resolve([]),
35 ["jmp_customer_bch_addresses-test"]
36 )
37 assert_kind_of(
38 AltTopUpForm,
39 AltTopUpForm.for(customer).sync
40 )
41 end
42 em :test_for_addresses
43
44 def test_for_cad
45 CustomerFinancials::REDIS.expect(
46 :smembers,
47 EMPromise.resolve([]),
48 ["jmp_customer_btc_addresses-test"]
49 )
50 CustomerFinancials::REDIS.expect(
51 :smembers,
52 EMPromise.resolve([]),
53 ["jmp_customer_bch_addresses-test"]
54 )
55 assert_kind_of(
56 AltTopUpForm,
57 AltTopUpForm.for(customer(plan_name: "test_cad")).sync
58 )
59 end
60 em :test_for_cad
61
62 def test_form_addrs
63 assert_kind_of(
64 Blather::Stanza::X,
65 AltTopUpForm.new(
66 customer, ["some_addr"], []
67 ).form
68 )
69 end
70
71 def test_form_new_addrs
72 assert_kind_of(
73 Blather::Stanza::X,
74 AltTopUpForm.new(
75 customer, [], []
76 ).form
77 )
78 end
79
80 def test_parse_complete
81 iq_form = Blather::Stanza::X.new
82 iq_form.fields = [
83 { var: "http://jabber.org/protocol/commands#actions", value: "complete" }
84 ]
85 assert_kind_of(
86 AltTopUpForm::NoOp,
87 AltTopUpForm.new(customer, [], []).parse(iq_form)
88 )
89 end
90
91 def test_parse_btc
92 iq_form = Blather::Stanza::X.new
93 iq_form.fields = [
94 { var: "http://jabber.org/protocol/commands#actions", value: "BTC" }
95 ]
96 assert_kind_of(
97 AltTopUpForm::BitcoinAddress,
98 AltTopUpForm.new(customer, [], []).parse(iq_form)
99 )
100 end
101
102 def test_parse_xmr
103 iq_form = Blather::Stanza::X.new
104 iq_form.fields = [
105 { var: "http://jabber.org/protocol/commands#actions", value: "XMR" }
106 ]
107 assert_kind_of(
108 AltTopUpForm::SimpleSwapAddress,
109 AltTopUpForm.new(customer, [], []).parse(iq_form)
110 )
111 end
112end