2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-10-04 12:17:07 +02:00
|
|
|
|
describe Manager::UsersController, type: :controller do
|
2020-11-05 15:09:11 +01:00
|
|
|
|
let(:super_admin) { create(:super_admin) }
|
2020-01-08 10:50:16 +01:00
|
|
|
|
|
2021-10-04 13:10:14 +02:00
|
|
|
|
before { sign_in super_admin }
|
|
|
|
|
|
2020-03-26 16:17:07 +01:00
|
|
|
|
describe '#show' do
|
|
|
|
|
render_views
|
|
|
|
|
|
2020-11-05 15:09:11 +01:00
|
|
|
|
let(:super_admin) { create(:super_admin) }
|
2020-03-26 16:17:07 +01:00
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
get :show, params: { id: user.id }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(response.body).to include(user.email) }
|
|
|
|
|
end
|
|
|
|
|
|
2020-01-13 14:35:25 +01:00
|
|
|
|
describe '#update' do
|
2021-10-18 15:09:09 +02:00
|
|
|
|
let(:user) { create(:user, email: 'ancien.email@domaine.fr', password: '{My-$3cure-p4ssWord}') }
|
2020-01-13 14:35:25 +01:00
|
|
|
|
|
|
|
|
|
subject { patch :update, params: { id: user.id, user: { email: nouvel_email } } }
|
|
|
|
|
|
2021-10-04 14:00:32 +02:00
|
|
|
|
context 'when the targeted email does not exist' do
|
|
|
|
|
describe 'with a valid email' do
|
|
|
|
|
let(:nouvel_email) { 'nouvel.email@domaine.fr' }
|
2020-01-13 14:35:25 +01:00
|
|
|
|
|
2021-10-04 14:00:32 +02:00
|
|
|
|
it 'updates the user email' do
|
|
|
|
|
subject
|
2020-01-13 14:35:25 +01:00
|
|
|
|
|
2021-10-04 14:00:32 +02:00
|
|
|
|
expect(User.find_by(id: user.id).email).to eq(nouvel_email)
|
2021-11-29 13:47:45 +01:00
|
|
|
|
expect(response).to redirect_to(edit_manager_user_path(user))
|
2021-10-04 14:00:32 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'with an invalid email' do
|
|
|
|
|
let(:nouvel_email) { 'plop' }
|
|
|
|
|
|
|
|
|
|
it 'does not update the user email' do
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
expect(User.find_by(id: user.id).email).not_to eq(nouvel_email)
|
2024-07-25 12:14:52 +02:00
|
|
|
|
expect(flash[:error]).to match("Le champ « Adresse électronique » est invalide. Saisir une adresse électronique valide, exemple : adresse@mail.com")
|
2021-10-04 14:00:32 +02:00
|
|
|
|
end
|
2020-01-13 14:35:25 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-10-04 14:00:32 +02:00
|
|
|
|
context 'when the targeted email exists' do
|
2021-10-18 15:09:09 +02:00
|
|
|
|
let(:targeted_user) { create(:user, email: 'email.existant@domaine.fr', password: '{My-$3cure-p4ssWord}') }
|
|
|
|
|
let(:nouvel_email) { targeted_user.email }
|
2021-10-04 14:00:32 +02:00
|
|
|
|
|
2021-10-22 15:17:25 +02:00
|
|
|
|
it 'launches the merge process' do
|
|
|
|
|
expect_any_instance_of(User).to receive(:merge).with(user)
|
2021-10-04 14:00:32 +02:00
|
|
|
|
|
2021-10-22 15:17:25 +02:00
|
|
|
|
subject
|
2020-01-13 14:35:25 +01:00
|
|
|
|
|
2021-10-22 15:17:25 +02:00
|
|
|
|
expect(flash[:notice]).to match("Le compte « email.existant@domaine.fr » a absorbé le compte « ancien.email@domaine.fr ».")
|
2021-11-29 13:47:45 +01:00
|
|
|
|
expect(response).to redirect_to(edit_manager_user_path(targeted_user))
|
2020-01-13 14:35:25 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-01-08 10:50:16 +01:00
|
|
|
|
describe '#delete' do
|
2021-10-04 13:10:14 +02:00
|
|
|
|
let(:user) { create(:user) }
|
2020-01-08 10:50:16 +01:00
|
|
|
|
|
|
|
|
|
subject { delete :delete, params: { id: user.id } }
|
|
|
|
|
|
|
|
|
|
it 'deletes the user' do
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
expect(User.find_by(id: user.id)).to be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|