Move some Rails app services to UserManager namespace
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
111
spec/services/user_manager/create_account_spec.rb
Normal file
111
spec/services/user_manager/create_account_spec.rb
Normal file
@@ -0,0 +1,111 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UserManager::CreateAccount, type: :model do
|
||||
describe "#create_user_in_database" do
|
||||
let(:service) { described_class.new(account: {
|
||||
username: 'isaacnewton',
|
||||
email: 'isaacnewton@example.com',
|
||||
password: 'bright-ideas-in-autumn'
|
||||
})}
|
||||
|
||||
it "creates a new user record in the akkounts database" do
|
||||
expect(User.count).to eq(0)
|
||||
service.send(:create_user_in_database)
|
||||
expect(User.count).to eq(1)
|
||||
expect(User.last.cn).to eq("isaacnewton")
|
||||
expect(User.last.email).to eq("isaacnewton@example.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update_invitation" do
|
||||
let(:invitation) { create :invitation }
|
||||
let(:service) { described_class.new(account: {
|
||||
username: 'isaacnewton',
|
||||
email: 'isaacnewton@example.com',
|
||||
password: 'bright-ideas-in-autumn',
|
||||
invitation: invitation
|
||||
})}
|
||||
|
||||
before(:each) do
|
||||
service.send(:update_invitation, 23)
|
||||
end
|
||||
|
||||
it "marks the invitation as used" do
|
||||
expect(invitation.used_at).not_to be_nil
|
||||
end
|
||||
|
||||
it "saves the invited user's ID" do
|
||||
expect(invitation.invited_user_id).to eq(23)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_ldap_document" do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let(:service) { described_class.new(account: {
|
||||
username: 'halfinney',
|
||||
email: 'halfinney@example.com',
|
||||
password: 'remember-remember-the-5th-of-november'
|
||||
})}
|
||||
|
||||
it "enqueues a job to create the LDAP user document" do
|
||||
service.send(:add_ldap_document)
|
||||
|
||||
expect(enqueued_jobs.size).to eq(1)
|
||||
|
||||
args = enqueued_jobs.first['arguments'][0]
|
||||
expect(args["username"]).to eq('halfinney')
|
||||
expect(args["domain"]).to eq('kosmos.org')
|
||||
expect(args["email"]).to eq('halfinney@example.com')
|
||||
expect(args["hashed_pw"]).to match(/^{SSHA512}.{171}=/)
|
||||
end
|
||||
|
||||
after do
|
||||
clear_enqueued_jobs
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_ldap_document for pre-confirmed account" do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let(:service) { described_class.new(account: {
|
||||
username: 'halfinney',
|
||||
email: 'halfinney@example.com',
|
||||
password: 'remember-remember-the-5th-of-november',
|
||||
confirmed: true
|
||||
})}
|
||||
|
||||
it "enqueues a job to create the LDAP user document" do
|
||||
service.send(:add_ldap_document)
|
||||
args = enqueued_jobs.first['arguments'][0]
|
||||
expect(args["confirmed"]).to be(true)
|
||||
end
|
||||
|
||||
after do
|
||||
clear_enqueued_jobs
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create_lndhub_account" do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let(:service) { described_class.new(account: {
|
||||
username: 'halfinney', email: 'halfinney@example.com',
|
||||
password: 'bright-ideas-in-winter'
|
||||
})}
|
||||
let(:new_user) { create :user, cn: "halfinney", ou: "kosmos.org" }
|
||||
|
||||
it "enqueues a job to create an LndHub account" do
|
||||
service.send(:create_lndhub_account, new_user)
|
||||
|
||||
expect(enqueued_jobs.size).to eq(1)
|
||||
|
||||
args = enqueued_jobs.first['arguments']
|
||||
expect(args[0]['_aj_globalid']).to match('gid://akkounts/User')
|
||||
end
|
||||
|
||||
after do
|
||||
clear_enqueued_jobs
|
||||
end
|
||||
end
|
||||
end
|
||||
40
spec/services/user_manager/create_invitations_spec.rb
Normal file
40
spec/services/user_manager/create_invitations_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UserManager::CreateInvitations, type: :model do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let(:user) { create :user }
|
||||
|
||||
describe "#call" do
|
||||
before do
|
||||
described_class.call(user: user, amount: 5)
|
||||
end
|
||||
|
||||
after(:each) { clear_enqueued_jobs }
|
||||
|
||||
it "creates the right amount of invitations for the given user" do
|
||||
expect(user.invitations.count).to eq(5)
|
||||
end
|
||||
|
||||
it "sends an email notification to the user" do
|
||||
expect(enqueued_jobs.size).to eq(1)
|
||||
expect(enqueued_jobs.first["job_class"]).to eq("ActionMailer::MailDeliveryJob")
|
||||
args = enqueued_jobs.first['arguments']
|
||||
expect(args[0]).to eq("NotificationMailer")
|
||||
expect(args[1]).to eq("new_invitations_available")
|
||||
expect(args[3]["params"]["user"]["_aj_globalid"]).to eq("gid://akkounts/User/1")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#call with notification disabled" do
|
||||
before do
|
||||
described_class.call(user: user, amount: 3, notify: false)
|
||||
end
|
||||
|
||||
after(:each) { clear_enqueued_jobs }
|
||||
|
||||
it "does not send an email notification to the user" do
|
||||
expect(enqueued_jobs.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user