mailers: add deposit receipt to initiated_mail

See #6146
This commit is contained in:
Pierre de La Morinerie 2022-05-10 14:23:22 +00:00
parent e8b6731af8
commit 0063b68689
4 changed files with 50 additions and 0 deletions

View file

@ -21,6 +21,7 @@ class NotificationMailer < ApplicationMailer
@service = @dossier.procedure.service
@logo_url = attach_logo(@dossier.procedure)
@rendered_template = sanitize(@body)
attachments[@attachment[:filename]] = @attachment[:content] if @attachment.present?
I18n.with_locale(@dossier.user_locale) do
mail(subject: @subject, to: @email, template_name: 'send_notification')
@ -62,6 +63,7 @@ class NotificationMailer < ApplicationMailer
@subject = mail_template.subject_for_dossier(@dossier)
@body = mail_template.body_for_dossier(@dossier)
@actions = mail_template.actions_for_dossier(@dossier)
@attachment = mail_template.attachment_for_dossier(@dossier)
end
end
end

View file

@ -21,6 +21,10 @@ module MailTemplateConcern
[MailTemplateConcern::Actions::SHOW, MailTemplateConcern::Actions::ASK_QUESTION]
end
def attachment_for_dossier(dossier)
nil
end
def update_rich_body
self.rich_body = self.body
end

View file

@ -20,5 +20,24 @@ module Mails
DISPLAYED_NAME = I18n.t('activerecord.models.mail.initiated_mail.proof_of_receipt')
DEFAULT_SUBJECT = I18n.t('activerecord.models.mail.initiated_mail.default_subject', dossier_number: '--numéro du dossier--', procedure_libelle: '--libellé démarche--')
DOSSIER_STATE = Dossier.states.fetch(:en_construction)
def attachment_for_dossier(dossier)
if procedure.feature_enabled?(:procedure_dossier_papertrail)
{
filename: I18n.t('users.dossiers.show.papertrail.filename'),
content: deposit_receipt_for_dossier(dossier)
}
end
end
private
def deposit_receipt_for_dossier(dossier)
ApplicationController.render(
template: 'users/dossiers/papertrail',
formats: [:pdf],
assigns: { dossier: dossier }
)
end
end
end

View file

@ -3,6 +3,31 @@ RSpec.describe NotificationMailer, type: :mailer do
let(:user) { create(:user) }
let(:procedure) { create(:simple_procedure) }
describe 'send_en_construction_notification' do
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
let(:email_template) { create(:initiated_mail, subject: 'Email subject', body: 'Your dossier was received. Thanks.') }
before do
dossier.procedure.initiated_mail = email_template
end
subject(:mail) { described_class.send_en_construction_notification(dossier) }
it 'renders the template' do
expect(mail.subject).to eq('Email subject')
expect((mail.html_part || mail).body).to include('Your dossier was received')
end
context 'when the deposit receipt feature is enabled' do
before { Flipper.enable(:procedure_dossier_papertrail, procedure) }
after { Flipper.disable(:procedure_dossier_papertrail, procedure) }
it 'attaches the deposit receipt' do
expect(mail.attachments.first.filename).to eq("attestation-de-depot.pdf")
end
end
end
describe 'send_en_instruction_notification' do
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
let(:email_template) { create(:received_mail, subject: 'Email subject', body: 'Your dossier was processed. Thanks.') }