diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index ec35af0bc..6ee751b10 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -75,7 +75,7 @@ class Commentaire < ApplicationRecord end def sent_by?(someone) - email == someone.email + email == someone&.email end def file_url diff --git a/app/views/shared/dossiers/messages/_message.html.haml b/app/views/shared/dossiers/messages/_message.html.haml index 2d62f2fdd..70694f0c3 100644 --- a/app/views/shared/dossiers/messages/_message.html.haml +++ b/app/views/shared/dossiers/messages/_message.html.haml @@ -11,6 +11,8 @@ .rich-text= pretty_commentaire(commentaire) .message-extras.flex.justify-start + - if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur? + %div{"data-test-delete-id" => 1} Suppr - if commentaire.piece_jointe.attached? .attachment-link = render partial: "shared/attachment/show", locals: { attachment: commentaire.piece_jointe.attachment } diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index ad9756998..6c7a8720e 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -382,6 +382,11 @@ describe Instructeurs::DossiersController, type: :controller do end end + describe '#messagerie' do + subject { get :messagerie, params: { procedure_id: procedure.id, dossier_id: dossier.id } } + it { expect(response).to have_http_status(:ok) } + end + describe "#create_commentaire" do let(:saved_commentaire) { dossier.commentaires.first } let(:body) { "avant\napres" } diff --git a/spec/views/shared/dossiers/messages/message.html.haml_spec.rb b/spec/views/shared/dossiers/messages/message.html.haml_spec.rb index 010de240a..c162b3338 100644 --- a/spec/views/shared/dossiers/messages/message.html.haml_spec.rb +++ b/spec/views/shared/dossiers/messages/message.html.haml_spec.rb @@ -46,5 +46,36 @@ describe 'shared/dossiers/messages/message.html.haml', type: :view do it { is_expected.not_to have_text(instructeur.email) } end end + + describe 'delete message button for instructeur' do + let(:instructeur) { create(:instructeur) } + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) } + subject { render 'shared/dossiers/messages/message.html.haml', commentaire: commentaire, messagerie_seen_at: seen_at, connected_user: instructeur, show_reply_button: true } + + context 'on a procedure where commentaire had been written by connected instructeur' do + let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') } + + it { is_expected.to have_css("div[data-test-delete-id=1]")} + end + + context 'on a procedure where commentaire had been written by connected an user' do + let(:commentaire) { create(:commentaire, email: create(:user).email, body: 'Second message') } + + it { is_expected.not_to have_css("div[data-test-delete-id=1]")} + end + + context 'on a procedure where commentaire had been written by connected an expert' do + let(:commentaire) { create(:commentaire, expert: create(:expert), body: 'Second message') } + + it { is_expected.not_to have_css("div[data-test-delete-id=1]")} + end + + context 'on a procedure where commentaire had been written another instructeur' do + let(:commentaire) { create(:commentaire, instructeur: create(:instructeur), body: 'Second message') } + + it { is_expected.not_to have_css("div[data-test-delete-id=1]")} + end + end end end