-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7593de5
commit 79ab31e
Showing
8 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Users::NoReplyMailer < ApplicationMailer | ||
class UnrecognizableEmailAddressError < StandardError; end | ||
|
||
# @param [Mail::Message] source_mail : le mail initial envoyé par l’usager et transféré par Brevo à notre serveur | ||
def no_reply | ||
mail( | ||
from: no_reply_from, | ||
to: params[:source_mail].from.first, | ||
subject: "Mail non reçu" | ||
) | ||
end | ||
|
||
private | ||
|
||
def domain | ||
@domain ||= begin | ||
reply_email_domain = params[:source_mail].to.first.split("@").last | ||
case reply_email_domain | ||
when /rdv-solidarites/ | ||
Domain::RDV_SOLIDARITES | ||
when /rdv-service-public/ || /rdv\.anct\.gouv/ || /rdv-mairie/ | ||
Domain::RDV_MAIRIE | ||
when /rdv-aide-numerique/ | ||
Domain::RDV_AIDE_NUMERIQUE | ||
else | ||
raise UnrecognizableEmailAddressError, params[:source_mail].to.to_s | ||
end | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
app/views/mailers/users/no_reply_mailer/no_reply.html.slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
div | ||
p | ||
' Votre réponse email n’a pas pu être délivrée. | ||
| Cette adresse n’est pas destinée à recevoir des réponses. | ||
p | ||
' Si vous souhaitez annuler ou décaler un RDV, vous pouvez cliquer sur les liens reçus dans les précédents emails ou bien | ||
= link_to "retrouver tous vos RDV en vous connectant ici", new_user_session_url(host: domain.host_name) | ||
'. | ||
.btn-wrapper | ||
= link_to("J’ai besoin d’aide", contact_url(host: domain.host_name), class: "btn btn-primary") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
end | ||
end | ||
|
||
describe "#perform" do | ||
describe "#perform - pour des réponses à des mails transactionnels de RDV" do | ||
subject(:perform_job) { described_class.perform_now(sendinblue_payload) } | ||
|
||
before do | ||
|
@@ -158,4 +158,36 @@ | |
end | ||
end | ||
end | ||
|
||
describe "#perform - pour des réponses au emails ne-pas-repondre" do | ||
subject(:perform_job) { described_class.perform_now(sendinblue_payload) } | ||
|
||
let(:sendinblue_payload) do | ||
{ | ||
Cc: [], | ||
ReplyTo: nil, | ||
Subject: "", | ||
Attachments: [], | ||
Headers: { | ||
"Message-ID": "<[email protected]>", | ||
Subject: "", | ||
From: "Bénédicte Ficiaire <[email protected]>", | ||
To: "[email protected]", | ||
Date: "Thu, 12 May 2022 12:22:15 +0200", | ||
}, | ||
ExtractedMarkdownMessage: "Je souhaite annuler mon RDV", | ||
ExtractedMarkdownSignature: nil, | ||
RawHtmlBody: %(<html dir="ltr"><head></head><body style="text-align:left; direction:ltr;"><div>Je souhaite annuler mon RDV</div>\n</body></html>\n), | ||
RawTextBody: "Je souhaite annuler mon RDV\n", | ||
} | ||
end | ||
|
||
it "répond automatiquement à l’usager" 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.from).to eq(["[email protected]"]) | ||
expect(transferred_email.html_part.body.to_s).to include(%(Votre réponse email n’a pas pu être délivrée)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Users::NoReplyMailerPreview < ActionMailer::Preview | ||
def no_reply | ||
source_mail = Mail.new do | ||
from "[email protected]" | ||
to "[email protected]" | ||
end | ||
|
||
Users::NoReplyMailer.with(source_mail:).no_reply | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
RSpec.describe Users::NoReplyMailer, type: :mailer do | ||
describe "#no_reply" do | ||
context "l’usager a répondu à l’adresse no-reply du même environnement" do | ||
let(:source_mail) do | ||
Mail.new do | ||
from "[email protected]" | ||
to "[email protected]" | ||
end | ||
end | ||
|
||
it "répond depuis la même adresse no-reply" do | ||
mail = described_class.with(source_mail:).no_reply | ||
expect(mail[:from].to_s).to eq(%("Ne pas répondre - RDV Solidarités" <[email protected]>)) | ||
expect(mail.to).to eq(["[email protected]"]) | ||
end | ||
end | ||
|
||
context "l’usager a répondu à une adresse no-reply d’un autre environnement" do | ||
let(:source_mail) do | ||
Mail.new do | ||
from "[email protected]" | ||
to "[email protected]" | ||
end | ||
end | ||
|
||
it "répond depuis l’adresse no-reply de l’environnement courant" do | ||
mail = described_class.with(source_mail:).no_reply | ||
expect(mail[:from].to_s).to eq(%("Ne pas répondre - RDV Solidarités" <[email protected]>)) | ||
expect(mail.to).to eq(["[email protected]"]) | ||
end | ||
end | ||
|
||
context "l’adresse n’est pas reconnaissable" do | ||
let(:source_mail) do | ||
Mail.new do | ||
from "[email protected]" | ||
to "[email protected]" | ||
end | ||
end | ||
|
||
it "répond depuis l’adresse no-reply de l’environnement courant" do | ||
expect { described_class.with(source_mail:).no_reply.deliver_now }.to raise_exception Users::NoReplyMailer::UnrecognizableEmailAddressError | ||
end | ||
end | ||
end | ||
end |