@@ -102,8 +102,12 @@ class AdminCommand
def new_context(q, command_action=:execute)
CustomerInfoForm.new(@customer_repo)
.parse_something(q).then do |new_customer|
- AdminCommand.for(new_customer, @customer_repo, @admin_action_repo, @snikket_repo)
- .then { |ac| ac.start(command_action) }
+ AdminCommand.for(
+ new_customer,
+ @customer_repo,
+ @admin_action_repo,
+ @snikket_repo
+ ).then { |ac| ac.start(command_action) }
end
end
@@ -4,17 +4,96 @@ require "test_helper"
require "admin_command"
BackendSgx::IQ_MANAGER = Minitest::Mock.new
+AdminAction::LaunchSnikket::IQ_MANAGER = Minitest::Mock.new
Customer::BLATHER = Minitest::Mock.new
AdminActionRepo::REDIS = Minitest::Mock.new
+DB = FakeDB.new
class AdminCommandTest < Minitest::Test
def admin_command(tel="+15556667777")
sgx = Minitest::Mock.new(OpenStruct.new(
registered?: OpenStruct.new(phone: tel)
))
- [sgx, AdminCommand.new(customer(sgx: sgx), CustomerRepo.new)]
+ [
+ sgx,
+ AdminCommand.new(customer(sgx: sgx), CustomerRepo.new, Snikket::Repo.new)
+ ]
end
+ def test_action_launch_snikket
+ sgx, admin = admin_command
+ domain_form = Blather::Stanza::Iq::Command.new
+ domain_form.form.fields = [
+ { var: "domain", value: "test.snikket.chat" }
+ ]
+
+ launched = Snikket::Launched.new
+ launched << Niceogiri::XML::Node.new(
+ :launched, launched.document, "xmpp:snikket.org/hosting/v1"
+ ).tap { |inner|
+ inner << Niceogiri::XML::Node.new(
+ :'instance-id', launched.document, "xmpp:snikket.org/hosting/v1"
+ ).tap { |id|
+ id.content = "si-1234"
+ }
+ inner << Niceogiri::XML::Node.new(
+ :bootstrap, launched.document, "xmpp:snikket.org/hosting/v1"
+ ).tap { |bootstrap|
+ bootstrap << Niceogiri::XML::Node.new(
+ :token, launched.document, "xmpp:snikket.org/hosting/v1"
+ ).tap { |token|
+ token.content = "TOKEN"
+ }
+ }
+ }
+
+ result = execute_command {
+ Command::COMMAND_MANAGER.expect(
+ :write,
+ EMPromise.resolve(domain_form),
+ [Matching.new do |iq|
+ assert_equal :form, iq.form.type
+ assert iq.form.field("domain")
+ end]
+ )
+ Command::COMMAND_MANAGER.expect(
+ :write,
+ EMPromise.reject(:test_result),
+ [Matching.new do |iq|
+ assert :result, iq.type
+ assert(
+ "https://test.snikket.chat/invites_bootstrap?token=TOKEN",
+ iq.form.field("bootstrap-uri").value
+ )
+ end]
+ )
+
+ AdminAction::LaunchSnikket::IQ_MANAGER.expect(
+ :write,
+ EMPromise.resolve(launched),
+ [Matching.new do |iq|
+ assert_equal :set, iq.type
+ assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s
+ assert_equal(
+ "test.snikket.chat",
+ iq.xpath(
+ "./ns:launch/ns:domain",
+ ns: "xmpp:snikket.org/hosting/v1"
+ ).text
+ )
+ end]
+ )
+
+ admin.action_launch_snikket.catch { |e| e }
+ }
+
+ assert_equal :test_result, result
+ assert_mock sgx
+ assert_mock AdminAction::LaunchSnikket::IQ_MANAGER
+ assert_mock Customer::BLATHER
+ end
+ em :test_action_launch_snikket
+
def test_action_cancel_account
sgx, admin = admin_command