2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-11-25 16:26:55 +01:00
|
|
|
|
describe Administrateurs::MailTemplatesController, type: :controller do
|
2019-03-27 12:32:38 +01:00
|
|
|
|
render_views
|
2020-08-06 16:32:51 +02:00
|
|
|
|
let(:procedure) { create :procedure }
|
|
|
|
|
let(:initiated_mail) { Mails::InitiatedMail.default_for_procedure(procedure) }
|
2019-03-27 12:32:38 +01:00
|
|
|
|
|
2024-06-01 22:50:48 +02:00
|
|
|
|
let(:admin) { administrateurs(:default_admin) }
|
2019-03-27 12:32:38 +01:00
|
|
|
|
|
2020-08-06 16:32:51 +02:00
|
|
|
|
before do
|
|
|
|
|
sign_in(procedure.administrateurs.first.user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'GET index' do
|
|
|
|
|
render_views
|
|
|
|
|
|
|
|
|
|
subject { get :index, params: { procedure_id: procedure.id } }
|
|
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 200 }
|
|
|
|
|
it { expect(subject.body).to include("Configuration des emails") }
|
|
|
|
|
it { expect(subject.body).to include(Mails::InitiatedMail::DISPLAYED_NAME) }
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-27 12:32:38 +01:00
|
|
|
|
describe '#preview' do
|
|
|
|
|
let(:procedure) { create(:procedure, :with_logo, :with_service, administrateur: admin) }
|
|
|
|
|
|
|
|
|
|
before do
|
2019-08-09 10:46:39 +02:00
|
|
|
|
sign_in(admin.user)
|
2019-03-27 12:32:38 +01:00
|
|
|
|
get :preview, params: { id: "initiated_mail", procedure_id: procedure.id }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
|
|
2019-07-23 15:26:55 +02:00
|
|
|
|
it 'displays the procedure logo' do
|
2019-12-19 18:29:01 +01:00
|
|
|
|
expect(response.body).to have_css("img[src*='/rails/active_storage/blobs/']")
|
2019-07-23 15:26:55 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'displays the action buttons' do
|
|
|
|
|
expect(response.body).to have_link('Consulter mon dossier')
|
|
|
|
|
end
|
2019-03-27 12:32:38 +01:00
|
|
|
|
|
2019-07-23 15:26:55 +02:00
|
|
|
|
it 'displays the service in the footer' do
|
|
|
|
|
expect(response.body).to include(procedure.service.nom)
|
|
|
|
|
expect(response.body).to include(procedure.service.telephone)
|
|
|
|
|
end
|
2019-03-27 12:32:38 +01:00
|
|
|
|
end
|
2020-08-25 11:40:24 +02:00
|
|
|
|
|
|
|
|
|
describe 'PATCH update' do
|
|
|
|
|
let(:mail_subject) { 'Mise à jour de votre démarche' }
|
2022-11-02 10:03:10 +01:00
|
|
|
|
let(:mail_body) { '<div>Une mise à jour a été effectuée sur votre démarche n° --numéro du dossier--.</div>' }
|
2020-08-25 11:40:24 +02:00
|
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
|
patch :update,
|
|
|
|
|
params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
id: initiated_mail.class.const_get(:SLUG),
|
|
|
|
|
mails_initiated_mail: { subject: mail_subject, rich_body: mail_body }
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(response).to redirect_to edit_admin_procedure_mail_template_path(procedure, initiated_mail.class.const_get(:SLUG)) }
|
|
|
|
|
|
2022-11-02 10:03:10 +01:00
|
|
|
|
context 'with valid email template' do
|
2023-11-29 12:59:55 +01:00
|
|
|
|
subject { procedure.reload; procedure.passer_en_construction_email_template }
|
2020-08-25 11:40:24 +02:00
|
|
|
|
|
2022-11-02 10:03:10 +01:00
|
|
|
|
it do
|
|
|
|
|
expect(subject.subject).to eq(mail_subject)
|
|
|
|
|
expect(subject.body).to eq(mail_body)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with invalid email template' do
|
2023-11-29 12:59:55 +01:00
|
|
|
|
subject { procedure.reload; procedure.passer_en_construction_email_template }
|
2022-11-02 10:03:10 +01:00
|
|
|
|
let(:mail_body) { '<div>Une mise à jour a été effectuée sur votre démarche n° --numéro--.</div>' }
|
|
|
|
|
|
|
|
|
|
it do
|
|
|
|
|
expect(subject.body).not_to eq(mail_body)
|
2022-12-16 14:56:46 +01:00
|
|
|
|
expect(response.body).to match("Le champ « Corps de l’email » contient la balise "numéro" qui n’existe pas. Supprimer la balise")
|
2022-11-02 10:03:10 +01:00
|
|
|
|
end
|
2020-08-25 11:40:24 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-03-27 12:32:38 +01:00
|
|
|
|
end
|