1# frozen_string_literal: true
2
3require "test_helper"
4require_relative "../../sgx-bwmsgsv2"
5require "rantly/minitest_extensions"
6require_relative "generators/disco_info_iq"
7
8def panic(e)
9 $panic = e
10end
11
12class DiscoInfoPropertyTest < Minitest::Test
13 def setup
14 reset_stanzas!
15 reset_redis!
16 end
17
18 def test_disco_info_get_for_user_returns_user_caps
19 property_of {
20 DiscoInfoIQ
21 .new(REDIS)
22 .target_node { nanpa_phone }
23 .generate
24 }.check { |_metadata, example|
25 process_stanza(example['stanza'])
26
27 assert_equal 1, written.length
28 reply = written.shift
29
30 assert_equal example['jid'], reply.to.to_s
31
32 ns = 'http://jabber.org/protocol/disco#info'
33 ids = reply.query.find('.//ns:identity', ns: ns)
34 assert_equal 1, ids.length
35 assert_equal 'client', ids.first[:category]
36 assert_equal 'sms', ids.first[:type]
37
38 feats = reply.query.find('.//ns:feature', ns: ns).map { |f| f[:var] }
39 assert_includes feats, 'urn:xmpp:receipts'
40 }
41 end
42 em :test_disco_info_get_for_user_returns_user_caps
43
44 def test_disco_info_get_for_gateway_returns_gateway_identity
45 property_of {
46 DiscoInfoIQ
47 .new(REDIS)
48 .target_node { nil }
49 .generate
50 }.check { |_metadata, example|
51 process_stanza(example['stanza'])
52
53 assert_equal 1, written.length
54 reply = written.shift
55
56 assert_equal example['jid'], reply.to.to_s
57
58 ns = 'http://jabber.org/protocol/disco#info'
59 ids = reply.query.find('.//ns:identity', ns: ns)
60 gateway_id = ids.find { |i| i[:category] == 'gateway' }
61 assert gateway_id, 'Should include gateway identity'
62 assert_equal 'sms', gateway_id[:type]
63
64 feats = reply.query.find('.//ns:feature', ns: ns).map { |f| f[:var] }
65 assert_includes feats, 'http://jabber.org/protocol/disco#info'
66 assert_includes feats, 'jabber:iq:register'
67 assert_includes feats, 'http://jabber.org/protocol/commands'
68 }
69 end
70 em :test_disco_info_get_for_gateway_returns_gateway_identity
71
72 def test_disco_info_non_get_produces_no_output
73 property_of {
74 DiscoInfoIQ
75 .new(REDIS)
76 .stanza { |target_node, jid|
77 iq = Blather::Stanza::DiscoInfo.new(choose(:set, :result))
78 iq.to = target_node ? "#{target_node}@component" : "component"
79 iq.from = jid
80 iq
81 }
82 .generate
83 }.check { |_metadata, example|
84 process_stanza(example['stanza'])
85
86 assert_empty written
87 }
88 end
89 em :test_disco_info_non_get_produces_no_output
90end