Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Réapplique "Utiliser l’adresse de réponse magique comme adresse d’envoi des emails de RDV adressés aux usagers" #4825

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/jobs/transfer_email_reply_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion app/mailers/users/rdv_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -53,4 +53,8 @@ def save_receipt(subject)
def domain
@rdv.domain
end

def default_from
TransferEmailReplyJob.reply_address_for_rdv(@rdv)
end
end
11 changes: 11 additions & 0 deletions spec/jobs/transfer_email_reply_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(["[email protected]"])
expect(transferred_email.html_part.body.to_s).to include(%(L'usager⋅e "Bénédicte Ficiaire" &lt;[email protected]&gt; a répondu))
end
end
end
end
23 changes: 11 additions & 12 deletions spec/mailers/users/rdv_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" <support@rdv-solidarites.fr>))
expect(mail[:from].to_s).to match(/"RDV Solidarités" <rdv\+[a-z0-9\-]+@reply\.rdv-solidarites-test\.localhost>/)
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
Expand Down Expand Up @@ -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" <[email protected]>))

expect(mail[:from].to_s).to match(/"RDV Solidarités" <rdv\+[a-z0-9\-]+@reply\.rdv-solidarites-test\.localhost/)
expect(mail.to).to eq([user.email])
expect(mail.reply_to).to eq(["rdv+#{rdv.uuid}@reply.rdv-solidarites-test.localhost"])
end

it "indicates the previous and current values" do
Expand Down Expand Up @@ -116,9 +116,8 @@
user = rdv.users.first
mail = described_class.with(rdv: rdv, user: user, token: token).rdv_cancelled

expect(mail[:from].to_s).to eq(%("RDV Solidarités" <support@rdv-solidarites.fr>))
expect(mail[:from].to_s).to match(/"RDV Solidarités" <rdv\+[a-z0-9\-]+@reply\.rdv-solidarites-test\.localhost>/)
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
Expand Down Expand Up @@ -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" <support@rdv-solidarites.fr>))
expect(mail[:from].to_s).to match(/"RDV Solidarités" <rdv\+[a-z0-9\-]+@reply\.rdv-solidarites-test\.localhost>/)
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
Expand All @@ -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" <support@rdv-solidarites.fr>))
expect(mail[:from].to_s).to match(/"RDV Solidarités" <rdv\+[a-z0-9\-]+@reply\.rdv-solidarites-test\.localhost>/)
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))
Expand All @@ -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" <support@rdv-solidarites.fr>))
expect(mail[:from].to_s).to match(/"RDV Solidarités" <rdv\+[a-z0-9\-]+@reply\.rdv-solidarites-test\.localhost/)
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))
Expand All @@ -218,7 +216,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 Aide Numérique" <support@rdv-aide-numerique.fr>))
expect(mail[:from].to_s).to match(/"RDV Aide Numérique" <rdv\+[a-z0-9\-]+@reply\.rdv-aide-numerique-test\.localhost>/)
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))
Expand All @@ -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 <[email protected]>))
expect(mail[:from].to_s).to match(/RDV Service Public <rdv\+[a-z0-9\-]+@reply\.rdv-mairie-test\.localhost>/)
# 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))
Expand Down
Loading