From 2b0782620240480efa187d767783898659cbf2b2 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 17 Sep 2024 18:04:41 +0200 Subject: [PATCH] fix(sva): add sva/svr decision date tag for relevant template emails Closes #10033 --- app/models/concerns/mail_template_concern.rb | 2 +- app/models/concerns/tags_substitution_concern.rb | 16 +++++++++++++++- .../concerns/mail_template_concern_spec.rb | 8 ++++++++ .../concerns/tags_substitution_concern_spec.rb | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index ecc582f85..0325d7239 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -50,6 +50,6 @@ module MailTemplateConcern end def dossier_tags - TagsSubstitutionConcern::DOSSIER_TAGS + TagsSubstitutionConcern::DOSSIER_TAGS_FOR_MAIL + super + TagsSubstitutionConcern::DOSSIER_TAGS_FOR_MAIL end end diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index 3648aab2d..d24f945e8 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -158,6 +158,14 @@ module TagsSubstitutionConcern } ] + DOSSIER_SVA_SVR_DECISION_DATE_TAG = { + id: 'dossier_sva_svr_decision_on', + libelle: 'date prévisionnelle SVA/SVR', + description: 'Date prévisionnelle de décision automatique par le SVA/SVR', + lambda: -> (d) { format_date(d.sva_svr_decision_on) }, + available_for_states: Dossier.states.fetch(:en_instruction) + } + INDIVIDUAL_TAGS = [ { id: 'individual_gender', @@ -335,7 +343,13 @@ module TagsSubstitutionConcern def dossier_tags # Overridden by MailTemplateConcern - DOSSIER_TAGS + DOSSIER_TAGS + contextual_dossier_tags + end + + def contextual_dossier_tags + tags = [] + tags << DOSSIER_SVA_SVR_DECISION_DATE_TAG if respond_to?(:procedure) && procedure.sva_svr_enabled? + tags end def tags_for_dossier_state(tags) diff --git a/spec/models/concerns/mail_template_concern_spec.rb b/spec/models/concerns/mail_template_concern_spec.rb index d7ba3a69a..c7a249a9a 100644 --- a/spec/models/concerns/mail_template_concern_spec.rb +++ b/spec/models/concerns/mail_template_concern_spec.rb @@ -141,6 +141,14 @@ describe MailTemplateConcern do let(:mail) { create(:without_continuation_mail, procedure: procedure) } it_behaves_like 'inserting the --lien document justificatif-- tag' end + + context 'sva/svr' do + let(:procedure) { create(:procedure, :sva) } + let(:received_mail) { create(:received_mail, procedure:) } + it "treats date de passage en instruction as a tag" do + expect(received_mail.tags).to include(include({ libelle: 'date prévisionnelle SVA/SVR' })) + end + end end describe '#replace_tags' do diff --git a/spec/models/concerns/tags_substitution_concern_spec.rb b/spec/models/concerns/tags_substitution_concern_spec.rb index e0c67b1a2..742532c97 100644 --- a/spec/models/concerns/tags_substitution_concern_spec.rb +++ b/spec/models/concerns/tags_substitution_concern_spec.rb @@ -413,6 +413,20 @@ describe TagsSubstitutionConcern, type: :model do end end + context "with date decision sva/svr" do + let(:template) { '--date prévisionnelle SVA/SVR--' } + let(:procedure) { create(:procedure, :published, :sva) } + let(:state) { dossier.state } + + before do + dossier.passer_en_construction! + dossier.process_sva_svr! + dossier.update(sva_svr_decision_on: Date.parse("2024-09-20")) + end + + it { is_expected.to eq('20/09/2024') } + end + context "when the template has a libellé démarche tag" do let(:template) { 'body --libellé démarche--' }