diff --git a/app/jobs/transfer_email_reply_job.rb b/app/jobs/transfer_email_reply_job.rb index 6299703759..e41e143f9e 100644 --- a/app/jobs/transfer_email_reply_job.rb +++ b/app/jobs/transfer_email_reply_job.rb @@ -21,7 +21,7 @@ def self.uuid_from_email_address(email_address) def perform(sendinblue_hash) @sendinblue_hash = sendinblue_hash.with_indifferent_access - if rdv + if rdv&.agents&.pluck(:email)&.compact&.any? notify_agents else forward_to_default_mailbox diff --git a/app/mailers/users/rdv_mailer.rb b/app/mailers/users/rdv_mailer.rb index ce45d2e691..57e627983f 100644 --- a/app/mailers/users/rdv_mailer.rb +++ b/app/mailers/users/rdv_mailer.rb @@ -11,7 +11,7 @@ class Users::RdvMailer < ApplicationMailer @token = params[:token] end - default to: -> { @user.email }, reply_to: -> { TransferEmailReplyJob.reply_address_for_rdv(@rdv) } + default to: -> { @user.email } def rdv_created self.ics_payload = @rdv.payload(:create, @user) @@ -53,4 +53,8 @@ def save_receipt(subject) def domain @rdv.domain end + + def default_from + TransferEmailReplyJob.reply_address_for_rdv(@rdv) + end end diff --git a/spec/jobs/transfer_email_reply_job_spec.rb b/spec/jobs/transfer_email_reply_job_spec.rb index 7bea4286d5..98ec2a8c7a 100644 --- a/spec/jobs/transfer_email_reply_job_spec.rb +++ b/spec/jobs/transfer_email_reply_job_spec.rb @@ -146,5 +146,16 @@ expect(transferred_email.html_part.body.to_s).to include(%(Le mail de l'usager⋅e avait en pièce jointe "mon_scan.pdf".)) end end + + context "quand le RDV est avec un agent intervenant sans email" do + let!(:agent) { create(:agent, :intervenant) } + + it "transfère le mail à notre support" do + expect { perform_job }.to change { ActionMailer::Base.deliveries.size }.by(1) + transferred_email = ActionMailer::Base.deliveries.last + expect(transferred_email.to).to eq(["support@rdv-solidarites.fr"]) + expect(transferred_email.html_part.body.to_s).to include(%(L'usager⋅e "Bénédicte Ficiaire" <bene_ficiaire@lapin.fr> a répondu)) + end + end end end diff --git a/spec/mailers/users/rdv_mailer_spec.rb b/spec/mailers/users/rdv_mailer_spec.rb index 83cebcbcf5..a8cb8d21aa 100644 --- a/spec/mailers/users/rdv_mailer_spec.rb +++ b/spec/mailers/users/rdv_mailer_spec.rb @@ -6,9 +6,9 @@ let(:mail) { described_class.with(rdv: rdv, user: user, token: token).rdv_created } it "renders the headers" do - expect(mail[:from].to_s).to eq(%("RDV Solidarités" )) + expect(mail[:from].to_s).to match(/"RDV Solidarités" /) expect(mail.to).to eq([user.email]) - expect(mail.reply_to).to eq(["rdv+#{rdv.uuid}@reply.rdv-solidarites-test.localhost"]) + expect(mail.reply_to).to be_nil end it "renders the subject" do @@ -80,9 +80,9 @@ it "renders the headers" do mail = described_class.with(rdv: rdv, user: user, token: token).rdv_updated(old_starts_at: previous_starting_time, lieu_id: nil) - expect(mail[:from].to_s).to eq(%("RDV Solidarités" )) + + expect(mail[:from].to_s).to match(/"RDV Solidarités" )) + expect(mail[:from].to_s).to match(/"RDV Solidarités" /) expect(mail.to).to eq([user.email]) - expect(mail.reply_to).to eq(["rdv+#{rdv.uuid}@reply.rdv-solidarites-test.localhost"]) end it "subject contains date of cancelled rdv" do @@ -174,9 +173,8 @@ it "send mail to user" do mail = described_class.with(rdv: rdv, user: user, token: token).rdv_upcoming_reminder - expect(mail[:from].to_s).to eq(%("RDV Solidarités" )) + expect(mail[:from].to_s).to match(/"RDV Solidarités" /) expect(mail.to).to eq([user.email]) - expect(mail.reply_to).to eq(["rdv+#{rdv.uuid}@reply.rdv-solidarites-test.localhost"]) expect(mail.html_part.body).to include("Nous vous rappellons que vous avez un RDV prévu") expect(mail.html_part.body.raw_source).to include("/users/rdvs/#{rdv.id}?invitation_token=12345") end @@ -194,7 +192,7 @@ it "works" do mail = described_class.with(rdv: rdv, user: rdv.users.first, token: "12345").send(action) - expect(mail[:from].to_s).to eq(%("RDV Solidarités" )) + expect(mail[:from].to_s).to match(/"RDV Solidarités" /) expect(mail.html_part.body.to_s).to include(%(src="/logo_solidarites.png)) expect(mail.html_part.body.to_s).to include(%(href="http://www.rdv-solidarites-test.localhost)) expect(mail.html_part.body.to_s).to include(%(L’équipe RDV Solidarités)) @@ -206,7 +204,7 @@ it "works" do mail = described_class.with(rdv: rdv, user: rdv.users.first, token: "12345").send(action) - expect(mail[:from].to_s).to eq(%("RDV Solidarités" )) + expect(mail[:from].to_s).to match(/"RDV Solidarités" )) + expect(mail[:from].to_s).to match(/"RDV Aide Numérique" /) expect(mail.html_part.body.to_s).to include(%(src="/logo_aide_numerique.png)) expect(mail.html_part.body.to_s).to include(%(href="http://www.rdv-aide-numerique-test.localhost)) expect(mail.html_part.body.to_s).to include(%(L’équipe RDV Aide Numérique)) @@ -230,7 +228,8 @@ it "works" do mail = described_class.with(rdv: rdv, user: rdv.users.first, token: "12345").send(action) - expect(mail[:from].to_s).to eq(%(RDV Service Public )) + expect(mail[:from].to_s).to match(/RDV Service Public /) + # les guillemets autour de "RDV Service Public" disparaissent probablement ici car il n’y a que des caractères ASCII expect(mail.html_part.body.to_s).to include(%(src="/logo_rdv_service_public.png)) expect(mail.html_part.body.to_s).to include(%(href="http://www.rdv-mairie-test.localhost)) expect(mail.html_part.body.to_s).to include(%(L’équipe RDV Service Public))