Refactor ejabberd API integration
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Release Drafter / Update release notes draft (pull_request) Successful in 2s

This commit is contained in:
2025-05-26 14:10:27 +04:00
parent 4bf6985b87
commit d737d9f6b8
19 changed files with 307 additions and 167 deletions

View File

@@ -1,5 +1,4 @@
require 'rails_helper'
require 'webmock/rspec'
RSpec.describe XmppExchangeContactsJob, type: :job do
let(:user) { create :user, cn: "willherschel", ou: "kosmos.org" }
@@ -10,19 +9,11 @@ RSpec.describe XmppExchangeContactsJob, type: :job do
described_class.perform_later(user, guest)
}
before do
stub_request(:post, "http://xmpp.example.com/api/add_rosteritem")
.to_return(status: 200, body: "", headers: {})
allow_any_instance_of(User).to receive(:services_enabled).and_return(["ejabberd"])
end
it "calls the service for exchanging contacts" do
expect(EjabberdManager::ExchangeContacts).to receive(:call)
.with(inviter: user, invitee: guest).and_return(true)
it "posts add_rosteritem commands to the ejabberd API" do
perform_enqueued_jobs { job }
expect(WebMock).to have_requested(:post, "http://xmpp.example.com/api/add_rosteritem")
.with { |req| req.body == '{"localuser":"isaacnewton","localhost":"kosmos.org","user":"willherschel","host":"kosmos.org","nick":"willherschel","group":"Buddies","subs":"both"}' }
expect(WebMock).to have_requested(:post, "http://xmpp.example.com/api/add_rosteritem")
.with { |req| req.body == '{"localuser":"willherschel","localhost":"kosmos.org","user":"isaacnewton","host":"kosmos.org","nick":"isaacnewton","group":"Buddies","subs":"both"}' }
end
after do

View File

@@ -0,0 +1,25 @@
require 'rails_helper'
RSpec.describe XmppSendMessageJob, type: :job do
let(:payload) {{
type: "normal",
from: "kosmos.org", to: "willherschel@kosmos.org",
body: "This is a test message"
}}
subject(:job) {
described_class.perform_later(payload)
}
it "calls the service for exchanging contacts" do
expect(EjabberdManager::SendMessage).to receive(:call)
.with(payload: payload).and_return(true)
perform_enqueued_jobs { job }
end
after do
clear_enqueued_jobs
clear_performed_jobs
end
end

View File

@@ -1,30 +1,17 @@
require 'rails_helper'
require 'webmock/rspec'
RSpec.describe XmppSetDefaultBookmarksJob, type: :job do
let(:user) { create :user, cn: "willherschel", ou: "kosmos.org" }
before do
Setting.xmpp_default_rooms = [
"Welcome <welcome@kosmos.chat>",
"Kosmos Dev <kosmos-dev@kosmos.chat>"
]
end
subject(:job) {
described_class.perform_later(user)
}
before do
stub_request(:post, "http://xmpp.example.com/api/private_set")
.to_return(status: 200, body: "", headers: {})
end
it "calls the service for setting default bookmarks" do
expect(EjabberdManager::SetDefaultBookmarks).to receive(:call)
.with(user: user).and_return(true)
it "posts a private_set command to the ejabberd API" do
perform_enqueued_jobs { job }
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
after do