Merge branch 'chore/update_dependencies' into bugfix/local_web_app_icons
This commit is contained in:
55
spec/features/admin/users_spec.rb
Normal file
55
spec/features/admin/users_spec.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Admin: User management", type: :feature do
|
||||
let(:admin) { create :user }
|
||||
let(:user) { create :user, id: 2, cn: "alfred", email: "alfred@example.com" }
|
||||
|
||||
before do
|
||||
user.save!
|
||||
|
||||
allow(Devise::LDAP::Adapter).to receive(:get_ldap_param)
|
||||
.with(admin.cn, :admin).and_return(["true"])
|
||||
allow(Devise::LDAP::Adapter).to receive(:get_ldap_param)
|
||||
.with(user.cn, :admin).and_return(nil)
|
||||
allow_any_instance_of(User).to receive(:ldap_entry)
|
||||
.and_return({ uid: user.cn, mail: user.email, display_name: "Freddy" })
|
||||
allow_any_instance_of(LdapManager::FetchAvatar).to receive(:call)
|
||||
.and_return(nil)
|
||||
|
||||
login_as admin, :scope => :user
|
||||
end
|
||||
|
||||
describe "User details page" do
|
||||
before do
|
||||
visit admin_user_path("alfred")
|
||||
end
|
||||
|
||||
it "shows the user info" do
|
||||
within "h1" do
|
||||
expect(page).to have_content("User: alfred")
|
||||
end
|
||||
expect(page).to have_content("alfred@example.com")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Add invitations to account' do
|
||||
visit admin_user_path("alfred")
|
||||
find("#add-invitations").click
|
||||
|
||||
select "5", :from => "amount"
|
||||
uncheck "notify_user"
|
||||
click_button "Add"
|
||||
|
||||
expect(user.invitations.count).to eq(5)
|
||||
end
|
||||
|
||||
scenario 'Remove invitations from account' do
|
||||
3.times { Invitation.create(user: user) }
|
||||
expect(user.invitations.count).to eq(3)
|
||||
|
||||
visit admin_user_path("alfred")
|
||||
find("#remove-invitations").click
|
||||
|
||||
expect(user.invitations.count).to eq(0)
|
||||
end
|
||||
end
|
||||
40
spec/services/create_invitations_spec.rb
Normal file
40
spec/services/create_invitations_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CreateInvitations, type: :model do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let(:user) { create :user }
|
||||
|
||||
describe "#call" do
|
||||
before do
|
||||
CreateInvitations.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
|
||||
CreateInvitations.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