demarches-normaliennes/spec/controllers/instructeurs/avis_controller_spec.rb

58 lines
2.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
describe Instructeurs::AvisController, type: :controller do
context 'with a instructeur signed in' do
render_views
2017-09-06 11:21:29 +02:00
let(:now) { Time.zone.parse('01/02/2345') }
2021-02-28 22:20:24 +01:00
let(:expert) { create(:expert) }
let(:claimant) { create(:instructeur) }
2024-03-15 17:41:59 +01:00
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure, notify_on_new_avis: false) }
let(:instructeur) { create(:instructeur) }
2021-02-28 22:20:24 +01:00
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let!(:avis_without_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) }
2017-09-06 11:21:29 +02:00
2019-08-07 11:15:16 +02:00
before { sign_in(instructeur.user) }
2017-09-06 11:21:29 +02:00
2021-02-28 22:20:24 +01:00
describe "#revoker" do
let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) }
before do
2021-02-28 22:20:24 +01:00
patch :revoquer, params: { procedure_id: procedure.id, id: avis.id }
end
2020-07-16 11:14:37 +02:00
it "revoke the dossier" do
2021-02-28 22:20:24 +01:00
expect(flash.notice).to eq("#{avis.expert.email} ne peut plus donner son avis sur ce dossier.")
2020-07-16 11:14:37 +02:00
end
end
2020-07-20 16:26:16 +02:00
describe 'remind' do
2020-07-20 16:26:16 +02:00
before do
2024-08-22 11:27:28 +02:00
allow(AvisMailer).to receive(:avis_invitation_and_confirm_email).and_return(double(deliver_later: nil))
2020-07-20 16:26:16 +02:00
end
context 'without question' do
let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) }
it 'sends a reminder to the expert' do
get :remind, params: { procedure_id: procedure.id, id: avis.id }
2024-08-22 11:27:28 +02:00
expect(AvisMailer).to have_received(:avis_invitation_and_confirm_email)
expect(flash.notice).to eq("Un mail de relance a été envoyé à #{avis.expert.email}")
expect(avis.reload.reminded_at).to be_present
end
end
context 'with question' do
let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, question_label: '123') }
2020-07-20 16:26:16 +02:00
it 'sends a reminder to the expert' do
get :remind, params: { procedure_id: procedure.id, id: avis.id }
2024-08-22 11:27:28 +02:00
expect(AvisMailer).to have_received(:avis_invitation_and_confirm_email)
expect(flash.notice).to eq("Un mail de relance a été envoyé à #{avis.expert.email}")
expect(avis.reload.reminded_at).to be_present
end
end
end
end
2017-09-06 11:21:29 +02:00
end