require 'rails_helper' require 'webmock/rspec' RSpec.describe EjabberdManager::SetDefaultBookmarks, type: :model do let(:user) { create :user, cn: "willherschel", ou: "kosmos.org" } before do Setting.xmpp_default_rooms = [ "Welcome ", "Kosmos Dev " ] stub_request(:post, "http://xmpp.example.com/api/private_set") .to_return(status: 200, body: "", headers: {}) described_class.call(user:) end it "posts a private_set command to the ejabberd API" do expect(WebMock).to have_requested(:post, "http://xmpp.example.com/api/private_set") .with { |req| req.body == '{"user":"willherschel","host":"kosmos.org","element":"\u003cstorage xmlns=\'storage:bookmarks\'\u003e\u003cconference jid=\'welcome@kosmos.chat\' name=\'Welcome\' autojoin=\'false\'\u003e\u003cnick\u003ewillherschel\u003c/nick\u003e\u003c/conference\u003e\u003cconference jid=\'kosmos-dev@kosmos.chat\' name=\'Kosmos Dev\' autojoin=\'false\'\u003e\u003cnick\u003ewillherschel\u003c/nick\u003e\u003c/conference\u003e\u003c/storage\u003e"}' } end end