2022-01-05 16:19:26 +01:00
|
|
|
describe Administrateurs::ProcedureAdministrateursController, type: :controller do
|
|
|
|
let(:signed_in_admin) { create(:administrateur) }
|
|
|
|
let(:other_admin) { create(:administrateur) }
|
2022-07-21 16:52:31 +02:00
|
|
|
let!(:administrateurs_procedure) { create(:administrateurs_procedure, administrateur: signed_in_admin, procedure: procedure, manager: manager) }
|
|
|
|
let!(:procedure) { create(:procedure, administrateurs: [other_admin]) }
|
2022-04-19 12:28:29 +02:00
|
|
|
render_views
|
2022-01-05 16:19:26 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(signed_in_admin.user)
|
|
|
|
end
|
|
|
|
|
2022-07-21 16:52:31 +02:00
|
|
|
describe '#create' do
|
|
|
|
context 'as manager' do
|
|
|
|
let(:manager) { true }
|
|
|
|
subject { post :create, params: { procedure_id: procedure.id, administrateur: { email: create(:administrateur).email } }, format: :turbo_stream }
|
|
|
|
it { is_expected.to have_http_status(:forbidden) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-05 16:19:26 +01:00
|
|
|
describe '#destroy' do
|
2022-07-21 16:52:31 +02:00
|
|
|
let(:manager) { false }
|
2022-01-05 16:19:26 +01:00
|
|
|
subject do
|
2022-04-19 12:28:29 +02:00
|
|
|
delete :destroy, params: { procedure_id: procedure.id, id: admin_to_remove.id }, format: :turbo_stream
|
2022-01-05 16:19:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when removing another admin' do
|
|
|
|
let(:admin_to_remove) { other_admin }
|
|
|
|
|
|
|
|
it 'removes the admin from the procedure' do
|
|
|
|
subject
|
2022-04-19 12:28:29 +02:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(subject.body).to include('alert-success')
|
2022-01-05 16:21:59 +01:00
|
|
|
expect(admin_to_remove.procedures.reload).not_to include(procedure)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when removing oneself from a procedure' do
|
|
|
|
let(:admin_to_remove) { signed_in_admin }
|
|
|
|
|
|
|
|
it 'denies the right for an admin to remove itself' do
|
|
|
|
subject
|
2022-04-19 12:28:29 +02:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(subject.body).to include('alert-danger')
|
2022-01-05 16:21:59 +01:00
|
|
|
expect(admin_to_remove.procedures.reload).to include(procedure)
|
2022-01-05 16:19:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|