add pj for export template
This commit is contained in:
parent
d1c3b84ea2
commit
24922605cd
2 changed files with 71 additions and 0 deletions
|
@ -22,6 +22,15 @@ class ExportTemplate < ApplicationRecord
|
||||||
tiptap_content("pdf_name")
|
tiptap_content("pdf_name")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def content_for_pj(pj)
|
||||||
|
content_for_pj_id(pj.stable_id)&.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def content_for_pj_id(stable_id)
|
||||||
|
content_for_stable_id = content["pjs"].find { _1.symbolize_keys[:stable_id] == stable_id.to_s }
|
||||||
|
content_for_stable_id.symbolize_keys.fetch(:path)
|
||||||
|
end
|
||||||
|
|
||||||
def attachment_and_path(dossier, attachment, index: 0, row_index: nil)
|
def attachment_and_path(dossier, attachment, index: 0, row_index: nil)
|
||||||
[
|
[
|
||||||
attachment,
|
attachment,
|
||||||
|
|
|
@ -61,6 +61,22 @@ describe ExportTemplate do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#content_for_pj' do
|
||||||
|
let(:type_de_champ_pj) { create(:type_de_champ_piece_justificative, stable_id: 3, libelle: 'Justificatif de domicile', procedure:) }
|
||||||
|
let(:champ_pj) { create(:champ_piece_justificative, type_de_champ: type_de_champ_pj) }
|
||||||
|
|
||||||
|
let(:attachment) { ActiveStorage::Attachment.new(name: 'pj', record: champ_pj, blob: ActiveStorage::Blob.new(filename: "superpj.png")) }
|
||||||
|
|
||||||
|
it 'returns tiptap content for pj' do
|
||||||
|
expect(export_template.content_for_pj(type_de_champ_pj)).to eq({
|
||||||
|
"type"=>"doc",
|
||||||
|
"content"=> [
|
||||||
|
{"type"=>"paragraph", "content"=>[{"type"=>"mention", "attrs"=>{"id"=>"dossier_number", "label"=>"numéro du dossier"}}, {"text"=>" _justif", "type"=>"text"}]}
|
||||||
|
]
|
||||||
|
}.to_json)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#attachment_and_path' do
|
describe '#attachment_and_path' do
|
||||||
let(:dossier) { create(:dossier) }
|
let(:dossier) { create(:dossier) }
|
||||||
|
|
||||||
|
@ -72,5 +88,51 @@ describe ExportTemplate do
|
||||||
expect(export_template.attachment_and_path(dossier, attachment)).to eq([attachment, "DOSSIER_#{dossier.id}/mon_export_#{dossier.id}.pdf"])
|
expect(export_template.attachment_and_path(dossier, attachment)).to eq([attachment, "DOSSIER_#{dossier.id}/mon_export_#{dossier.id}.pdf"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'for pj' do
|
||||||
|
let(:dossier) { procedure.dossiers.first }
|
||||||
|
let(:type_de_champ_pj) { create(:type_de_champ_piece_justificative, stable_id: 3, procedure:) }
|
||||||
|
let(:champ_pj) { create(:champ_piece_justificative, type_de_champ: type_de_champ_pj) }
|
||||||
|
|
||||||
|
let(:attachment) { ActiveStorage::Attachment.new(name: 'pj', record: champ_pj, blob: ActiveStorage::Blob.new(filename: "superpj.png")) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
dossier.champs_public << champ_pj
|
||||||
|
end
|
||||||
|
it 'returns pj and custom name for pj' do
|
||||||
|
expect(export_template.attachment_and_path(dossier, attachment)).to eq([attachment, "DOSSIER_#{dossier.id}/#{dossier.id}_justif.png"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context 'pj repetable' do
|
||||||
|
let(:procedure) do
|
||||||
|
create(:procedure_with_dossiers, :for_individual, types_de_champ_public: [{ type: :repetition, mandatory: true, children: [{ libelle: 'sub type de champ' }] }])
|
||||||
|
end
|
||||||
|
let(:type_de_champ_repetition) do
|
||||||
|
repetition = draft.types_de_champ_public.repetition.first
|
||||||
|
repetition.update(stable_id: 3333)
|
||||||
|
repetition
|
||||||
|
end
|
||||||
|
let(:draft) { procedure.draft_revision }
|
||||||
|
let(:dossier) { procedure.dossiers.first }
|
||||||
|
|
||||||
|
let(:type_de_champ_pj) do
|
||||||
|
draft.add_type_de_champ({
|
||||||
|
type_champ: TypeDeChamp.type_champs.fetch(:piece_justificative),
|
||||||
|
libelle: "pj repet",
|
||||||
|
stable_id: 10,
|
||||||
|
parent_stable_id: type_de_champ_repetition.stable_id
|
||||||
|
})
|
||||||
|
end
|
||||||
|
let(:champ_pj) { create(:champ_piece_justificative, type_de_champ: type_de_champ_pj) }
|
||||||
|
|
||||||
|
let(:attachment) { ActiveStorage::Attachment.new(name: 'pj', record: champ_pj, blob: ActiveStorage::Blob.new(filename: "superpj.png")) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
dossier.champs_public << champ_pj
|
||||||
|
end
|
||||||
|
it 'rename repetable pj' do
|
||||||
|
expect(export_template.attachment_and_path(dossier, attachment)).to eq([attachment, "DOSSIER_#{dossier.id}/pj_repet_#{dossier.id}.png"])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue