fix(attestation): fix unspecified_attestation_champs for v2
This commit is contained in:
parent
a2c0379127
commit
f2669fbca8
3 changed files with 60 additions and 28 deletions
|
@ -210,7 +210,7 @@ class AttestationTemplate < ApplicationRecord
|
||||||
def used_tags
|
def used_tags
|
||||||
if version == 2
|
if version == 2
|
||||||
json = json_body&.deep_symbolize_keys
|
json = json_body&.deep_symbolize_keys
|
||||||
TiptapService.used_tags_and_libelle_for(json.deep_symbolize_keys)
|
TiptapService.used_tags_and_libelle_for(json.deep_symbolize_keys).map(&:first)
|
||||||
else
|
else
|
||||||
used_tags_for(title) + used_tags_for(body)
|
used_tags_for(title) + used_tags_for(body)
|
||||||
end
|
end
|
||||||
|
|
|
@ -685,35 +685,6 @@ describe Dossier, type: :model do
|
||||||
describe "#unspecified_attestation_champs" do
|
describe "#unspecified_attestation_champs" do
|
||||||
let(:procedure) { create(:procedure, attestation_template: attestation_template, types_de_champ_public: types_de_champ, types_de_champ_private: types_de_champ_private) }
|
let(:procedure) { create(:procedure, attestation_template: attestation_template, types_de_champ_public: types_de_champ, types_de_champ_private: types_de_champ_private) }
|
||||||
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
||||||
let(:types_de_champ) { [] }
|
|
||||||
let(:types_de_champ_private) { [] }
|
|
||||||
|
|
||||||
subject { dossier.unspecified_attestation_champs.map(&:libelle) }
|
|
||||||
|
|
||||||
context "without attestation template" do
|
|
||||||
let(:attestation_template) { nil }
|
|
||||||
|
|
||||||
it { is_expected.to eq([]) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with attestation template" do
|
|
||||||
# Test all combinations:
|
|
||||||
# - with tag specified and unspecified
|
|
||||||
# - with tag in body and tag in title
|
|
||||||
# - with tag correponsing to a champ and an annotation privée
|
|
||||||
# - with a dash in the champ libelle / tag
|
|
||||||
let(:title) { "voici --specified champ-in-title-- un --unspecified champ-in-title-- beau --specified annotation privée-in-title-- titre --unspecified annotation privée-in-title-- non --numéro du dossier--" }
|
|
||||||
let(:body) { "voici --specified champ-in-body-- un --unspecified champ-in-body-- beau --specified annotation privée-in-body-- body --unspecified annotation privée-in-body-- non ?" }
|
|
||||||
let(:attestation_template) { build(:attestation_template, title: title, body: body, activated: activated) }
|
|
||||||
|
|
||||||
context "which is disabled" do
|
|
||||||
let(:activated) { false }
|
|
||||||
|
|
||||||
it { is_expected.to eq([]) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "wich is enabled" do
|
|
||||||
let(:activated) { true }
|
|
||||||
|
|
||||||
let(:types_de_champ) { [tdc_1, tdc_2, tdc_3, tdc_4] }
|
let(:types_de_champ) { [tdc_1, tdc_2, tdc_3, tdc_4] }
|
||||||
let(:types_de_champ_private) { [tdc_5, tdc_6, tdc_7, tdc_8] }
|
let(:types_de_champ_private) { [tdc_5, tdc_6, tdc_7, tdc_8] }
|
||||||
|
@ -733,6 +704,33 @@ describe Dossier, type: :model do
|
||||||
.each { |c| c.update_attribute(:value, "specified") }
|
.each { |c| c.update_attribute(:value, "specified") }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
subject { dossier.unspecified_attestation_champs.map(&:libelle) }
|
||||||
|
|
||||||
|
context "without attestation template" do
|
||||||
|
let(:attestation_template) { nil }
|
||||||
|
|
||||||
|
it { is_expected.to eq([]) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with attestation template v1" do
|
||||||
|
# Test all combinations:
|
||||||
|
# - with tag specified and unspecified
|
||||||
|
# - with tag in body and tag in title
|
||||||
|
# - with tag correponding to a champ and an annotation privée
|
||||||
|
# - with a dash in the champ libelle / tag
|
||||||
|
let(:title) { "voici --specified champ-in-title-- un --unspecified champ-in-title-- beau --specified annotation privée-in-title-- titre --unspecified annotation privée-in-title-- non --numéro du dossier--" }
|
||||||
|
let(:body) { "voici --specified champ-in-body-- un --unspecified champ-in-body-- beau --specified annotation privée-in-body-- body --unspecified annotation privée-in-body-- non ?" }
|
||||||
|
let(:attestation_template) { build(:attestation_template, title: title, body: body, activated: activated) }
|
||||||
|
|
||||||
|
context "which is disabled" do
|
||||||
|
let(:activated) { false }
|
||||||
|
|
||||||
|
it { is_expected.to eq([]) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "which is enabled" do
|
||||||
|
let(:activated) { true }
|
||||||
|
|
||||||
it do
|
it do
|
||||||
is_expected.to eq([
|
is_expected.to eq([
|
||||||
"unspecified champ-in-title",
|
"unspecified champ-in-title",
|
||||||
|
@ -743,6 +741,40 @@ describe Dossier, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with attestation template v2" do
|
||||||
|
# Test all combinations:
|
||||||
|
# - with tag specified and unspecified
|
||||||
|
# - with tag correponding to a champ and an annotation privée
|
||||||
|
let(:body) {
|
||||||
|
[
|
||||||
|
{ "type" => "mention", "attrs" => { "id" => "tdc#{procedure.types_de_champ_for_tags.find { _1.libelle == "unspecified champ-in-body" }.stable_id}", "label" => "unspecified champ-in-body" } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
let(:attestation_template) { build(:attestation_template, :v2) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
tdc_content = (types_de_champ + types_de_champ_private).filter_map do |tdc_config|
|
||||||
|
next if tdc_config[:libelle].include?("in-title")
|
||||||
|
|
||||||
|
{
|
||||||
|
"type" => "mention",
|
||||||
|
"attrs" => { "id" => "tdc#{procedure.types_de_champ_for_tags.find { _1.libelle == tdc_config[:libelle] }.stable_id}", "label" => tdc_config[:libelle] }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
json_body = attestation_template.json_body["content"]
|
||||||
|
attestation_template.json_body["content"][-1]["content"].concat(tdc_content)
|
||||||
|
attestation_template.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to eq([
|
||||||
|
"unspecified champ-in-body",
|
||||||
|
"unspecified annotation privée-in-body"
|
||||||
|
])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#build_attestation' do
|
describe '#build_attestation' do
|
||||||
|
|
Loading…
Reference in a new issue