2021-11-25 16:26:55 +01:00
|
|
|
describe Administrateurs::ExpertsProceduresController, type: :controller do
|
2024-06-01 22:50:48 +02:00
|
|
|
let(:admin) { administrateurs(:default_admin) }
|
2021-04-06 13:55:43 +02:00
|
|
|
let(:procedure) { create :procedure, administrateur: admin }
|
2021-03-30 17:55:35 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin.user)
|
|
|
|
end
|
2021-04-06 13:42:21 +02:00
|
|
|
|
2021-04-06 13:55:43 +02:00
|
|
|
describe '#index' do
|
|
|
|
subject do
|
|
|
|
get :index, params: { procedure_id: procedure.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.status).to eq 200 }
|
|
|
|
end
|
|
|
|
|
2021-04-06 13:42:21 +02:00
|
|
|
describe '#create' do
|
2021-03-30 17:55:35 +02:00
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
let(:expert2) { create(:expert) }
|
2024-06-14 11:36:58 +02:00
|
|
|
let(:procedure) { create :procedure, administrateur: admin, experts_require_administrateur_invitation: true }
|
2021-03-30 17:55:35 +02:00
|
|
|
|
2024-06-14 11:36:58 +02:00
|
|
|
subject { post :create, params: params }
|
|
|
|
|
|
|
|
context 'when inviting multiple valid experts' do
|
2024-05-07 21:37:54 +02:00
|
|
|
let(:params) { { procedure_id: procedure.id, emails: [expert.email, "new@expert.fr"] } }
|
2024-06-14 11:36:58 +02:00
|
|
|
|
|
|
|
it 'creates experts' do
|
2024-07-02 16:10:06 +02:00
|
|
|
subject
|
|
|
|
expect(procedure.experts.map(&:email)).to match_array([expert.email, "new@expert.fr"])
|
2024-06-14 11:36:58 +02:00
|
|
|
expect(flash.notice).to be_present
|
2024-07-01 10:41:16 +02:00
|
|
|
expect(assigns(:maybe_typos)).to eq([])
|
2024-06-14 11:36:58 +02:00
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
end
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
|
2024-06-14 11:36:58 +02:00
|
|
|
context 'when inviting expert using an email with typos' do
|
2024-05-07 21:37:54 +02:00
|
|
|
let(:params) { { procedure_id: procedure.id, emails: ['martin@oraneg.fr'] } }
|
2024-06-14 11:36:58 +02:00
|
|
|
render_views
|
|
|
|
it 'warns' do
|
2024-07-02 16:10:06 +02:00
|
|
|
subject
|
2024-06-14 11:36:58 +02:00
|
|
|
expect(flash.alert).to be_present
|
2024-07-01 10:41:16 +02:00
|
|
|
expect(assigns(:maybe_typos)).to eq([['martin@oraneg.fr', 'martin@orange.fr']])
|
2024-06-14 11:36:58 +02:00
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
end
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
|
2024-06-14 11:36:58 +02:00
|
|
|
context 'when forcing email with typos' do
|
2024-07-01 10:41:16 +02:00
|
|
|
render_views
|
|
|
|
let(:final_email) { 'martin@oraneg.fr' }
|
|
|
|
let(:params) { { procedure_id: procedure.id, final_email: } }
|
2024-06-14 11:36:58 +02:00
|
|
|
|
|
|
|
it 'works' do
|
2024-07-02 16:10:06 +02:00
|
|
|
subject
|
2024-07-01 10:41:16 +02:00
|
|
|
created_user = User.where(email: final_email).first
|
2024-06-14 11:36:58 +02:00
|
|
|
expect(created_user).to be_an_instance_of(User)
|
|
|
|
expect(created_user.expert).to be_an_instance_of(Expert)
|
|
|
|
expect(procedure.experts.include?(created_user.expert)).to be_truthy
|
|
|
|
expect(flash.notice).to be_present
|
|
|
|
expect(response).to have_http_status(:success)
|
2024-07-01 10:41:16 +02:00
|
|
|
expect(response.body).to have_content(final_email)
|
2024-06-14 11:36:58 +02:00
|
|
|
end
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-06 14:25:41 +02:00
|
|
|
describe '#update' do
|
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
let(:expert_procedure) { create(:experts_procedure, procedure: procedure, expert: expert) }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
put :update, params: {
|
|
|
|
id: expert_procedure.id,
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
experts_procedure: {
|
|
|
|
allow_decision_access: true
|
|
|
|
}
|
|
|
|
}, format: :js
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the record' do
|
|
|
|
expect(expert_procedure.allow_decision_access).to be false
|
|
|
|
subject
|
|
|
|
expect(expert_procedure.reload.allow_decision_access).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-06 13:42:21 +02:00
|
|
|
describe '#delete' do
|
2021-03-30 17:55:35 +02:00
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
let(:expert_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) }
|
|
|
|
|
|
|
|
subject do
|
2021-04-06 13:42:21 +02:00
|
|
|
delete :destroy, params: { procedure_id: procedure.id, id: expert_procedure.id }
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
expert_procedure.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'of multiple experts' do
|
|
|
|
it { expect(expert_procedure.revoked_at).to be_present }
|
|
|
|
it { expect(flash.notice).to be_present }
|
2021-04-06 13:55:43 +02:00
|
|
|
it { expect(response).to redirect_to(admin_procedure_experts_path(procedure)) }
|
2021-03-30 17:55:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|