Skip to content

Commit

Permalink
fix(sva): add sva/svr decision date tag for relevant template emails
Browse files Browse the repository at this point in the history
Closes #10033
  • Loading branch information
colinux committed Sep 17, 2024
1 parent 8a6e522 commit e6d2f02
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/mail_template_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ def default_template_name_for_procedure(procedure)
end

def dossier_tags
TagsSubstitutionConcern::DOSSIER_TAGS + TagsSubstitutionConcern::DOSSIER_TAGS_FOR_MAIL
super + TagsSubstitutionConcern::DOSSIER_TAGS_FOR_MAIL
end
end
16 changes: 15 additions & 1 deletion app/models/concerns/tags_substitution_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ def self.normalize(str)
}
]

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) },

Check warning on line 165 in app/models/concerns/tags_substitution_concern.rb

View check run for this annotation

Codecov / codecov/patch

app/models/concerns/tags_substitution_concern.rb#L165

Added line #L165 was not covered by tests
available_for_states: Dossier::EN_CONSTRUCTION_OU_INSTRUCTION
}

INDIVIDUAL_TAGS = [
{
id: 'individual_gender',
Expand Down Expand Up @@ -335,7 +343,13 @@ def url_for_justificatif_motivation(dossier)

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 procedure.sva_svr_enabled?
tags
end

def tags_for_dossier_state(tags)
Expand Down
8 changes: 8 additions & 0 deletions spec/models/concerns/mail_template_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@
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
Expand Down
14 changes: 14 additions & 0 deletions spec/models/concerns/tags_substitution_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,20 @@ def procedure
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--' }

Expand Down

0 comments on commit e6d2f02

Please sign in to comment.