1# frozen_string_literal: true
2
3require "snikket"
4
5class TestSnikket < Minitest::Test
6 NS = "xmpp:snikket.org/hosting/v1"
7
8 def test_launch
9 launch = Snikket::Launch.new(domain: "example.com")
10 assert_equal :set, launch.type
11 assert_equal NS, launch.query.namespace.href
12 assert_equal "launch", launch.query.node_name
13 assert_equal(
14 "example.com",
15 launch.query.at_xpath("./ns:domain", ns: NS).content
16 )
17 end
18
19 def test_launched
20 launched = Blather::XMPPNode.parse(<<~XML)
21 <iq type="result" from="hosting-api.snikket.net" id="123">
22 <launched xmlns="xmpp:snikket.org/hosting/v1">
23 <bootstrap>
24 <token>fZLy6iTh</token>
25 </bootstrap>
26 <instance-id>si-12345</instance-id>
27 </launched>
28 </iq>
29 XML
30 assert_equal :result, launched.type
31 assert_equal NS, launched.query.namespace.href
32 assert_equal "launched", launched.query.node_name
33 assert_equal "si-12345", launched.instance_id
34 end
35
36 def test_instance_get
37 instance = Snikket::Instance.new(instance_id: "si-1234")
38 assert_equal :get, instance.type
39 assert_equal NS, instance.query.namespace.href
40 assert_equal "instance", instance.query.node_name
41 assert_equal(
42 "si-1234",
43 instance.query.at_xpath("./ns:instance-id", ns: NS).content
44 )
45 end
46
47 def test_instance_result
48 instance = Blather::XMPPNode.parse(<<~XML)
49 <iq type="result" from="hosting-api.snikket.net" id="000">
50 <instance xmlns="xmpp:snikket.org/hosting/v1">
51 <update-needed/>
52 <instance-id>si-1234</instance-id>
53 <operation>
54 <progress>50</progress>
55 <status>running</status>
56 </operation>
57 <status>up</status>
58 </instance>
59 </iq>
60 XML
61 assert_equal :result, instance.type
62 assert_equal NS, instance.query.namespace.href
63 assert_equal "instance", instance.query.node_name
64 assert_equal "si-1234", instance.instance_id
65 assert instance.update_needed?
66 assert_kind_of Nokogiri::XML::Element, instance.operation
67 assert_equal :up, instance.status
68 end
69
70 def test_bootstrap_uri
71 instance = Snikket::CustomerInstance.new(
72 instance_id: "si-1234",
73 bootstrap_token: "fZLy6iTh",
74 customer_id: "test",
75 domain: "example.com"
76 )
77
78 assert_equal(
79 "https://example.com/invites_bootstrap?token=fZLy6iTh",
80 instance.bootstrap_uri
81 )
82 end
83end