2022-01-05 16:19:26 +01:00
|
|
|
describe Administrateurs::ProcedureAdministrateursController, type: :controller do
|
2024-06-01 22:50:48 +02:00
|
|
|
let(:signed_in_admin) { administrateurs(:default_admin).tap { _1.user.update(last_sign_in_at: Time.zone.now) } }
|
2022-11-21 15:19:02 +01:00
|
|
|
let(:other_admin) { create(:administrateur).tap { _1.user.update(last_sign_in_at: Time.zone.now) } }
|
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 }
|
2024-06-01 22:50:48 +02:00
|
|
|
subject { post :create, params: { procedure_id: procedure.id, administrateur: { email: administrateurs(:default_admin).email } }, format: :turbo_stream }
|
2022-07-21 16:52:31 +02:00
|
|
|
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-11-21 12:29:12 +01:00
|
|
|
|
|
|
|
def destroy_admin(admin_to_remove)
|
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
|
2022-11-21 12:29:12 +01:00
|
|
|
before do
|
|
|
|
destroy_admin(other_admin)
|
|
|
|
end
|
2022-01-05 16:19:26 +01:00
|
|
|
|
|
|
|
it 'removes the admin from the procedure' do
|
2022-11-21 12:29:12 +01:00
|
|
|
expect(response.body).to include('alert-success')
|
|
|
|
expect(other_admin.procedures.reload).not_to include(procedure)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'then removing oneself' do
|
|
|
|
before do
|
|
|
|
destroy_admin(signed_in_admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes the admin from the procedure' do
|
|
|
|
expect(response.body).to include('alert-danger')
|
|
|
|
expect(signed_in_admin.procedures.reload).to include(procedure)
|
|
|
|
end
|
2022-01-05 16:21:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when removing oneself from a procedure' do
|
2022-11-21 12:29:12 +01:00
|
|
|
before do
|
|
|
|
destroy_admin(signed_in_admin)
|
|
|
|
end
|
2022-01-05 16:21:59 +01:00
|
|
|
|
2022-11-21 12:29:12 +01:00
|
|
|
it 'removes the admin from the procedure' do
|
|
|
|
expect(response).to redirect_to admin_procedures_path
|
|
|
|
expect(signed_in_admin.procedures.reload).not_to include(procedure)
|
2022-01-05 16:19:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|