Add email service and settings

This commit is contained in:
2023-12-23 12:26:34 +01:00
parent aab6793b86
commit 958d18d61a
24 changed files with 506 additions and 35 deletions

View File

@@ -0,0 +1,62 @@
require 'rails_helper'
RSpec.describe 'E-Mail settings', type: :feature do
let(:user) { create :user }
feature "Reset email password" do
before do
login_as user, :scope => :user
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
.with("invalid password").and_return(false)
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
.with("valid password").and_return(true)
end
scenario 'fails with invalid password' do
expect(LdapManager::UpdateEmailPassword).not_to receive(:call)
expect(LdapManager::UpdateEmailMaildrop).not_to receive(:call)
visit setting_path(:email)
fill_in 'Current account password', with: "invalid password"
click_button "Create new email password"
within ".error-msg" do
expect(page).to have_content("Wrong password")
end
end
scenario 'works with valid password' do
allow_any_instance_of(User).to receive(:dn)
.and_return("cn=#{user.cn},ou=kosmos.org,cn=users,dc=kosmos,dc=org")
allow_any_instance_of(User).to receive(:ldap_entry)
.and_return({ uid: user.cn, ou: user.ou, email_maildrop: user.address })
expect(LdapManager::UpdateEmailPassword).to receive(:call).and_return(true)
expect(LdapManager::UpdateEmailMaildrop).not_to receive(:call)
visit setting_path(:email)
fill_in 'Current account password', with: "valid password"
click_button "Create new email password"
expect(current_url).to eq(new_password_services_email_url)
end
scenario 'updates the maildrop attribute if necessary' do
allow_any_instance_of(User).to receive(:dn)
.and_return("cn=#{user.cn},ou=kosmos.org,cn=users,dc=kosmos,dc=org")
allow_any_instance_of(User).to receive(:ldap_entry)
.and_return({ uid: user.cn, ou: user.ou, email_maildrop: "mahafaly@example.com" })
expect(LdapManager::UpdateEmailPassword).to receive(:call).and_return(true)
expect(LdapManager::UpdateEmailMaildrop).to receive(:call)
.with(user.dn, user.address).and_return(true)
visit setting_path(:email)
fill_in 'Current account password', with: "valid password"
click_button "Create new email password"
expect(current_url).to eq(new_password_services_email_url)
end
end
end

View File

@@ -66,9 +66,9 @@ RSpec.describe User, type: :model do
it "returns the entries from the LDAP service attribute" do
expect(user).to receive(:ldap_entry).and_return({
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
service: ["discourse", "gitea", "wiki", "xmpp"]
service: ["discourse", "email", "gitea", "wiki", "xmpp"]
})
expect(user.services_enabled).to eq(["discourse", "gitea", "wiki", "xmpp"])
expect(user.services_enabled).to eq(["discourse", "email", "gitea", "wiki", "xmpp"])
end
end
@@ -147,7 +147,7 @@ RSpec.describe User, type: :model do
after { clear_enqueued_jobs }
it "enables default services" do
expect(user).to receive(:enable_service).with(%w[ discourse gitea mediawiki xmpp ])
expect(user).to receive(:enable_service).with(%w[ discourse email gitea mediawiki xmpp ])
user.send :devise_after_confirmation
end