From 9c976c6b716cc910612b97accfdf2d3bc905f310 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Thu, 22 Jul 2021 14:33:39 +0200 Subject: [PATCH] fixup! tests --- .../procedures_controller_spec.rb | 44 +++++++++++++++++++ spec/mailers/dossier_mailer_spec.rb | 14 +++++- spec/models/commentaire_spec.rb | 3 +- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index aa5b23ab0..3df4b1fa4 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -489,4 +489,48 @@ describe Instructeurs::ProceduresController, type: :controller do end end end + + describe '#create_multiple_commentaire' do + let(:instructeur) { create(:instructeur) } + let!(:gi_p1_1) { GroupeInstructeur.create(label: '1', procedure: procedure) } + let!(:gi_p1_2) { GroupeInstructeur.create(label: '2', procedure: procedure) } + let(:body) { "avant\napres" } + let!(:dossier) { create(:dossier, state: "brouillon", procedure: procedure, groupe_instructeur: procedure.groupe_instructeurs.first) } + let!(:dossier_2) { create(:dossier, state: "brouillon", procedure: procedure, groupe_instructeur: gi_p1_1) } + let!(:dossier_3) { create(:dossier, state: "brouillon", procedure: procedure, groupe_instructeur: gi_p1_2) } + let!(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } + + before do + sign_in(instructeur.user) + instructeur.groupe_instructeurs << gi_p1_1 + procedure + post :create_multiple_commentaire, + params: { + procedure_id: procedure.id, + commentaire: { body: body } + } + end + + it "creates a commentaire for 2 dossiers" do + expect(Commentaire.all.count).to eq(2) + expect(dossier.commentaires.first.body).to eq("avant\napres") + expect(dossier_2.commentaires.first.body).to eq("avant\napres") + expect(dossier_3.commentaires).to eq([]) + end + + it "creates a Bulk Message for 2 groupes instructeurs" do + expect(BulkMessage.all.count).to eq(1) + expect(BulkMessage.all.first.body).to eq("avant\napres") + expect(BulkMessage.all.first.groupe_instructeurs.sort).to match([procedure.groupe_instructeurs.first, gi_p1_1]) + end + + it "creates a flash notice" do + expect(flash.notice).to be_present + expect(flash.notice).to eq("Tous les messages ont été envoyés avec succès") + end + + it "redirect to instructeur_procedure_path" do + expect(response).to redirect_to instructeur_procedure_path(procedure) + end + end end diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index 2448ca693..db4598fa7 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -26,11 +26,23 @@ RSpec.describe DossierMailer, type: :mailer do it_behaves_like 'a dossier notification' end - describe '.notify_new_answer' do + describe '.notify_new_answer with dossier brouillon' do let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) } subject { described_class.notify_new_answer(dossier) } + it { expect(subject.subject).to include("Nouveau message") } + it { expect(subject.subject).to include(dossier.id.to_s) } + it { expect(subject.body).not_to include(messagerie_dossier_url(dossier)) } + + it_behaves_like 'a dossier notification' + end + + describe '.notify_new_answer with dossier en construction' do + let(:dossier) { create(:dossier, state: "en_construction", procedure: build(:simple_procedure)) } + + subject { described_class.notify_new_answer(dossier) } + it { expect(subject.subject).to include("Nouveau message") } it { expect(subject.subject).to include(dossier.id.to_s) } it { expect(subject.body).to include(messagerie_dossier_url(dossier)) } diff --git a/spec/models/commentaire_spec.rb b/spec/models/commentaire_spec.rb index 4e33eb5c9..ac7a2cab8 100644 --- a/spec/models/commentaire_spec.rb +++ b/spec/models/commentaire_spec.rb @@ -3,7 +3,6 @@ describe Commentaire do it { is_expected.to have_db_column(:body) } it { is_expected.to have_db_column(:created_at) } it { is_expected.to have_db_column(:updated_at) } - it { is_expected.to belong_to(:dossier) } describe 'messagerie_available validation' do subject { commentaire.valid?(:create) } @@ -18,7 +17,7 @@ describe Commentaire do let(:dossier) { create :dossier, :archived } let(:commentaire) { build :commentaire, dossier: dossier } - it { is_expected.to be_falsey } + it { is_expected.to be_truthy } end context 'on a dossier en_construction' do