From a248eba6415112db1e51a3c4b37f901be41f00a7 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Sun, 3 Mar 2024 10:19:02 +0100 Subject: [PATCH] export template: set default values --- app/models/export_template.rb | 10 ++++++++++ spec/models/export_template_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/app/models/export_template.rb b/app/models/export_template.rb index 5345116bb..7016edac7 100644 --- a/app/models/export_template.rb +++ b/app/models/export_template.rb @@ -7,6 +7,16 @@ class ExportTemplate < ApplicationRecord DOSSIER_STATE = Dossier.states.fetch(:en_construction) + def set_default_values + content["default_dossier_directory"] = tiptap_json("dossier-") + content["pdf_name"] = tiptap_json("export_") + + content["pjs"] = [] + procedure.pieces_jointes_exportables_list.each do |pj| + content["pjs"] << { "stable_id" => pj.stable_id.to_s, "path" => tiptap_json("#{pj.libelle.parameterize}-") } + end + end + def tiptap_default_dossier_directory=(body) self.content["default_dossier_directory"] = JSON.parse(body) end diff --git a/spec/models/export_template_spec.rb b/spec/models/export_template_spec.rb index d8df04760..2aa74744d 100644 --- a/spec/models/export_template_spec.rb +++ b/spec/models/export_template_spec.rb @@ -37,6 +37,31 @@ describe ExportTemplate do { type: :piece_justificative, libelle: "Justificatif de domicile", mandatory: true, stable_id: 910 } ] end + it 'set default values' do + export_template.set_default_values + expect(export_template.content).to eq({ + "pdf_name" => { + "type" => "doc", + "content" => [ + { "type" => "paragraph", "content" => [{ "text" => "export_", "type" => "text" }, { "type" => "mention", "attrs" => ExportTemplate::DOSSIER_ID_TAG.stringify_keys }] } + ] + }, + "default_dossier_directory" => { + "type" => "doc", + "content" => [ + { "type" => "paragraph", "content" => [{ "text" => "dossier-", "type" => "text" }, { "type" => "mention", "attrs" => ExportTemplate::DOSSIER_ID_TAG.stringify_keys }] } + ] + }, + "pjs" => + [ + + { + "stable_id" => "910", + "path" => { "type" => "doc", "content" => [{ "type" => "paragraph", "content" => [{ "text" => "justificatif-de-domicile-", "type" => "text" }, { "type" => "mention", "attrs" => ExportTemplate::DOSSIER_ID_TAG.stringify_keys }] }] } + } + ] + }) + end end describe '#tiptap_default_dossier_directory' do