fixup! tests
This commit is contained in:
parent
77b57edb2f
commit
9c976c6b71
3 changed files with 58 additions and 3 deletions
|
@ -489,4 +489,48 @@ describe Instructeurs::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -26,11 +26,23 @@ RSpec.describe DossierMailer, type: :mailer do
|
||||||
it_behaves_like 'a dossier notification'
|
it_behaves_like 'a dossier notification'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.notify_new_answer' do
|
describe '.notify_new_answer with dossier brouillon' do
|
||||||
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
|
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
|
||||||
|
|
||||||
subject { described_class.notify_new_answer(dossier) }
|
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("Nouveau message") }
|
||||||
it { expect(subject.subject).to include(dossier.id.to_s) }
|
it { expect(subject.subject).to include(dossier.id.to_s) }
|
||||||
it { expect(subject.body).to include(messagerie_dossier_url(dossier)) }
|
it { expect(subject.body).to include(messagerie_dossier_url(dossier)) }
|
||||||
|
|
|
@ -3,7 +3,6 @@ describe Commentaire do
|
||||||
it { is_expected.to have_db_column(:body) }
|
it { is_expected.to have_db_column(:body) }
|
||||||
it { is_expected.to have_db_column(:created_at) }
|
it { is_expected.to have_db_column(:created_at) }
|
||||||
it { is_expected.to have_db_column(:updated_at) }
|
it { is_expected.to have_db_column(:updated_at) }
|
||||||
it { is_expected.to belong_to(:dossier) }
|
|
||||||
|
|
||||||
describe 'messagerie_available validation' do
|
describe 'messagerie_available validation' do
|
||||||
subject { commentaire.valid?(:create) }
|
subject { commentaire.valid?(:create) }
|
||||||
|
@ -18,7 +17,7 @@ describe Commentaire do
|
||||||
let(:dossier) { create :dossier, :archived }
|
let(:dossier) { create :dossier, :archived }
|
||||||
let(:commentaire) { build :commentaire, dossier: dossier }
|
let(:commentaire) { build :commentaire, dossier: dossier }
|
||||||
|
|
||||||
it { is_expected.to be_falsey }
|
it { is_expected.to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on a dossier en_construction' do
|
context 'on a dossier en_construction' do
|
||||||
|
|
Loading…
Reference in a new issue