2017-03-06 11:51:34 +01:00
|
|
|
|
describe MailTemplateConcern do
|
2018-01-15 21:54:40 +01:00
|
|
|
|
let(:procedure) { create(:procedure) }
|
2017-12-22 21:37:08 +01:00
|
|
|
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
let(:dossier2) { create(:dossier, procedure: procedure) }
|
2018-01-09 18:08:05 +01:00
|
|
|
|
let(:initiated_mail) { create(:initiated_mail, procedure: procedure) }
|
2020-06-30 17:53:54 +02:00
|
|
|
|
let(:justificatif) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
|
2017-10-20 10:32:28 +02:00
|
|
|
|
|
|
|
|
|
shared_examples "can replace tokens in template" do
|
|
|
|
|
describe 'with no token to replace' do
|
2018-02-28 16:01:20 +01:00
|
|
|
|
let(:template) { '[demarches-simplifiees.fr] rien à remplacer' }
|
2017-10-20 10:32:28 +02:00
|
|
|
|
it do
|
2018-02-28 16:01:20 +01:00
|
|
|
|
is_expected.to eq("[demarches-simplifiees.fr] rien à remplacer")
|
2017-10-20 10:32:28 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'with one token to replace' do
|
2018-02-28 16:01:20 +01:00
|
|
|
|
let(:template) { '[demarches-simplifiees.fr] Dossier : --numéro du dossier--' }
|
2017-10-20 10:32:28 +02:00
|
|
|
|
it do
|
2018-02-28 16:01:20 +01:00
|
|
|
|
is_expected.to eq("[demarches-simplifiees.fr] Dossier : #{dossier.id}")
|
2017-10-20 10:32:28 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-03-06 11:51:34 +01:00
|
|
|
|
|
2017-10-20 10:32:28 +02:00
|
|
|
|
describe 'with multiples tokens to replace' do
|
2018-09-05 14:48:42 +02:00
|
|
|
|
let(:template) { '[demarches-simplifiees.fr] --numéro du dossier-- --libellé démarche-- --lien dossier--' }
|
2017-10-20 10:32:28 +02:00
|
|
|
|
it do
|
2017-03-06 11:51:34 +01:00
|
|
|
|
expected =
|
2018-02-28 16:01:20 +01:00
|
|
|
|
"[demarches-simplifiees.fr] #{dossier.id} #{dossier.procedure.libelle} " +
|
2024-03-27 09:06:42 +01:00
|
|
|
|
"<a target=\"_blank\" rel=\"noopener\" href=\"http://test.host/dossiers/#{dossier.id}\">http://test.host/dossiers/#{dossier.id}</a>"
|
2017-03-06 11:51:34 +01:00
|
|
|
|
|
2017-10-20 10:32:28 +02:00
|
|
|
|
is_expected.to eq(expected)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-03-20 16:00:30 +01:00
|
|
|
|
describe '#subject_for_dossier' do
|
2018-01-08 17:26:13 +01:00
|
|
|
|
before { initiated_mail.subject = template }
|
|
|
|
|
subject { initiated_mail.subject_for_dossier(dossier) }
|
2017-10-20 10:32:28 +02:00
|
|
|
|
|
|
|
|
|
it_behaves_like "can replace tokens in template"
|
|
|
|
|
end
|
|
|
|
|
|
2018-03-20 16:00:30 +01:00
|
|
|
|
describe '#body_for_dossier' do
|
2017-10-20 10:32:28 +02:00
|
|
|
|
before { initiated_mail.body = template }
|
|
|
|
|
subject { initiated_mail.body_for_dossier(dossier) }
|
|
|
|
|
|
|
|
|
|
it_behaves_like "can replace tokens in template"
|
|
|
|
|
end
|
|
|
|
|
|
2018-01-11 11:28:41 +01:00
|
|
|
|
describe 'tags' do
|
|
|
|
|
describe 'in initiated mail' do
|
|
|
|
|
it "does not treat date de passage en instruction as a tag" do
|
|
|
|
|
expect(initiated_mail.tags).not_to include(include({ libelle: 'date de passage en instruction' }))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'in received mail' do
|
|
|
|
|
let(:received_mail) { create(:received_mail, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
it "treats date de passage en instruction as a tag" do
|
|
|
|
|
expect(received_mail.tags).to include(include({ libelle: 'date de passage en instruction' }))
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-03-16 17:17:26 +01:00
|
|
|
|
|
|
|
|
|
describe '--lien attestation--' do
|
|
|
|
|
let(:attestation_template) { AttestationTemplate.new(activated: true) }
|
|
|
|
|
let(:procedure) { create(:procedure, attestation_template: attestation_template) }
|
|
|
|
|
|
|
|
|
|
subject { mail.body_for_dossier(dossier) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
dossier.attestation = dossier.build_attestation
|
|
|
|
|
dossier.reload
|
|
|
|
|
mail.body = "--lien attestation--"
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-06 15:30:42 +01:00
|
|
|
|
describe "in closed mail without justificatif" do
|
2018-03-16 17:17:26 +01:00
|
|
|
|
let(:mail) { create(:closed_mail, procedure: procedure) }
|
2024-03-27 09:06:42 +01:00
|
|
|
|
it { is_expected.to eq("<a target=\"_blank\" rel=\"noopener\" href=\"http://test.host/dossiers/#{dossier.id}/attestation\">http://test.host/dossiers/#{dossier.id}/attestation</a>") }
|
2019-04-29 11:33:59 +02:00
|
|
|
|
it { is_expected.to_not include("Télécharger le justificatif") }
|
2019-03-06 15:30:42 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "in closed mail with justificatif" do
|
|
|
|
|
before do
|
|
|
|
|
dossier.justificatif_motivation.attach(justificatif)
|
|
|
|
|
end
|
|
|
|
|
let(:mail) { create(:closed_mail, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
it { expect(dossier.justificatif_motivation).to be_attached }
|
2024-03-27 09:06:42 +01:00
|
|
|
|
it { is_expected.to include("<a target=\"_blank\" rel=\"noopener\" href=\"http://test.host/dossiers/#{dossier.id}/attestation\">http://test.host/dossiers/#{dossier.id}/attestation</a>") }
|
2019-07-15 20:51:03 +02:00
|
|
|
|
it { is_expected.to_not include("Télécharger le justificatif") }
|
2018-03-16 17:17:26 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "in refuse mail" do
|
|
|
|
|
let(:mail) { create(:refused_mail, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to eq("--lien attestation--") }
|
|
|
|
|
end
|
2019-03-06 11:50:17 +01:00
|
|
|
|
|
|
|
|
|
describe "in without continuation mail" do
|
|
|
|
|
let(:mail) { create(:without_continuation_mail, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to eq("--lien attestation--") }
|
|
|
|
|
end
|
2018-03-16 17:17:26 +01:00
|
|
|
|
end
|
2019-07-15 20:51:03 +02:00
|
|
|
|
|
2019-07-16 12:14:07 +02:00
|
|
|
|
shared_examples 'inserting the --lien document justificatif-- tag' do
|
2019-07-15 20:51:03 +02:00
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
|
|
|
|
|
|
subject { mail.body_for_dossier(dossier) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
mail.body = "--lien document justificatif--"
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-16 12:14:07 +02:00
|
|
|
|
describe 'without justificatif' do
|
2021-05-26 15:16:30 +02:00
|
|
|
|
it { is_expected.to include("[l’instructeur n’a pas joint de document supplémentaire]") }
|
2019-07-15 20:51:03 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-07-16 12:14:07 +02:00
|
|
|
|
describe 'with justificatif' do
|
|
|
|
|
before do
|
|
|
|
|
dossier.justificatif_motivation.attach(justificatif)
|
2019-07-15 20:51:03 +02:00
|
|
|
|
end
|
2019-07-16 12:14:07 +02:00
|
|
|
|
it { expect(dossier.justificatif_motivation).to be_attached }
|
|
|
|
|
it { is_expected.to include("Télécharger le document justificatif") }
|
2019-07-15 20:51:03 +02:00
|
|
|
|
end
|
2019-07-16 12:14:07 +02:00
|
|
|
|
end
|
2019-07-15 20:51:03 +02:00
|
|
|
|
|
2019-07-16 12:14:07 +02:00
|
|
|
|
context 'in closed mail' do
|
|
|
|
|
let(:mail) { create(:closed_mail, procedure: procedure) }
|
|
|
|
|
it_behaves_like 'inserting the --lien document justificatif-- tag'
|
|
|
|
|
end
|
2019-07-15 20:51:03 +02:00
|
|
|
|
|
2019-07-16 12:14:07 +02:00
|
|
|
|
context 'in refused mail' do
|
|
|
|
|
let(:mail) { create(:refused_mail, procedure: procedure) }
|
|
|
|
|
it_behaves_like 'inserting the --lien document justificatif-- tag'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'in without continuation mail' do
|
|
|
|
|
let(:mail) { create(:without_continuation_mail, procedure: procedure) }
|
|
|
|
|
it_behaves_like 'inserting the --lien document justificatif-- tag'
|
2019-07-15 20:51:03 +02:00
|
|
|
|
end
|
2018-01-11 11:28:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-03-20 16:00:30 +01:00
|
|
|
|
describe '#replace_tags' do
|
2017-12-22 19:34:40 +01:00
|
|
|
|
before { initiated_mail.body = "n --numéro du dossier--" }
|
2017-10-20 10:32:28 +02:00
|
|
|
|
it "avoids side effects" do
|
2017-12-22 19:34:40 +01:00
|
|
|
|
expect(initiated_mail.body_for_dossier(dossier)).to eq("n #{dossier.id}")
|
|
|
|
|
expect(initiated_mail.body_for_dossier(dossier2)).to eq("n #{dossier2.id}")
|
2017-03-06 11:51:34 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-04-10 15:21:08 +02:00
|
|
|
|
|
|
|
|
|
describe '#update_rich_body' do
|
|
|
|
|
before { initiated_mail.update(body: "Voici le corps du mail") }
|
|
|
|
|
|
|
|
|
|
it { expect(initiated_mail.rich_body.to_plain_text).to eq(initiated_mail.body) }
|
|
|
|
|
end
|
2017-03-06 11:51:34 +01:00
|
|
|
|
end
|