spec: simplify export template factory
This commit is contained in:
parent
5846fb4417
commit
06cbb65d4e
5 changed files with 31 additions and 19 deletions
|
@ -11,24 +11,36 @@ FactoryBot.define do
|
||||||
{ "type" => "paragraph", "content" => [{ "text" => "export_", "type" => "text" }, { "type" => "mention", "attrs" => { "id" => "dossier_id", "label" => "id dossier" } }, { "text" => " .pdf", "type" => "text" }] }
|
{ "type" => "paragraph", "content" => [{ "text" => "export_", "type" => "text" }, { "type" => "mention", "attrs" => { "id" => "dossier_id", "label" => "id dossier" } }, { "text" => " .pdf", "type" => "text" }] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"default_dossier_directory" =>
|
"default_dossier_directory" => {
|
||||||
{
|
"type" => "doc",
|
||||||
"type" => "doc",
|
"content" =>
|
||||||
"content" =>
|
[
|
||||||
[
|
{
|
||||||
{
|
"type" => "paragraph",
|
||||||
"type" => "paragraph",
|
"content" =>
|
||||||
"content" =>
|
[
|
||||||
[
|
{ "text" => "dossier_", "type" => "text" },
|
||||||
{ "text" => "dossier_", "type" => "text" },
|
{ "type" => "mention", "attrs" => { "id" => "dossier_number", "label" => "numéro du dossier" } },
|
||||||
{ "type" => "mention", "attrs" => { "id" => "dossier_number", "label" => "numéro du dossier" } },
|
{ "text" => " ", "type" => "text" }
|
||||||
{ "text" => " ", "type" => "text" }
|
]
|
||||||
]
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kind { "zip" }
|
kind { "zip" }
|
||||||
|
|
||||||
|
to_create do |export_template, _context|
|
||||||
|
export_template.set_default_values
|
||||||
|
export_template.save
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :with_custom_content do
|
||||||
|
to_create do |export_template, context|
|
||||||
|
export_template.set_default_values
|
||||||
|
export_template.content = context.content
|
||||||
|
export_template.save
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
describe ExportTemplate do
|
describe ExportTemplate do
|
||||||
let(:groupe_instructeur) { create(:groupe_instructeur, procedure:) }
|
let(:groupe_instructeur) { create(:groupe_instructeur, procedure:) }
|
||||||
let(:export_template) { create(:export_template, groupe_instructeur:, content:) }
|
let(:export_template) { create(:export_template, :with_custom_content, groupe_instructeur:, content:) }
|
||||||
let(:procedure) { create(:procedure_with_dossiers, types_de_champ_public:, for_individual:) }
|
let(:procedure) { create(:procedure_with_dossiers, types_de_champ_public:, for_individual:) }
|
||||||
let(:dossier) { procedure.dossiers.first }
|
let(:dossier) { procedure.dossiers.first }
|
||||||
let(:for_individual) { false }
|
let(:for_individual) { false }
|
||||||
|
|
|
@ -110,7 +110,7 @@ describe PiecesJustificativesService do
|
||||||
it { expect(subject).to match_array(pj_champ.call(dossier).piece_justificative_file.attachments) }
|
it { expect(subject).to match_array(pj_champ.call(dossier).piece_justificative_file.attachments) }
|
||||||
|
|
||||||
context 'with export_template' do
|
context 'with export_template' do
|
||||||
let(:export_template) { create(:export_template, groupe_instructeur: procedure.defaut_groupe_instructeur).tap(&:set_default_values) }
|
let(:export_template) { create(:export_template, groupe_instructeur: procedure.defaut_groupe_instructeur) }
|
||||||
it { expect(subject).to match_array(pj_champ.call(dossier).piece_justificative_file.attachments) }
|
it { expect(subject).to match_array(pj_champ.call(dossier).piece_justificative_file.attachments) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -529,7 +529,7 @@ describe ProcedureExportService do
|
||||||
context 'with export_template' do
|
context 'with export_template' do
|
||||||
let!(:dossier) { create(:dossier, :accepte, :with_populated_champs, :with_individual, procedure: procedure) }
|
let!(:dossier) { create(:dossier, :accepte, :with_populated_champs, :with_individual, procedure: procedure) }
|
||||||
let(:dossier_exports) { PiecesJustificativesService.new(user_profile: instructeur, export_template:).generate_dossiers_export(Dossier.where(id: dossier)) }
|
let(:dossier_exports) { PiecesJustificativesService.new(user_profile: instructeur, export_template:).generate_dossiers_export(Dossier.where(id: dossier)) }
|
||||||
let(:export_template) { create(:export_template, groupe_instructeur: procedure.defaut_groupe_instructeur).tap(&:set_default_values) }
|
let(:export_template) { create(:export_template, groupe_instructeur: procedure.defaut_groupe_instructeur) }
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(ActiveStorage::Attachment).to receive(:url).and_return("https://opengraph.githubassets.com/d0e7862b24d8026a3c03516d865b28151eb3859029c6c6c2e86605891fbdcd7a/socketry/async-io")
|
allow_any_instance_of(ActiveStorage::Attachment).to receive(:url).and_return("https://opengraph.githubassets.com/d0e7862b24d8026a3c03516d865b28151eb3859029c6c6c2e86605891fbdcd7a/socketry/async-io")
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ describe ProcedureExportService do
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :piece_justificative, libelle: 'pj' }, { type: :repetition, children: [{ type: :piece_justificative, libelle: 'repet_pj' }] }]) }
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :piece_justificative, libelle: 'pj' }, { type: :repetition, children: [{ type: :piece_justificative, libelle: 'repet_pj' }] }]) }
|
||||||
let(:dossiers) { create_list(:dossier, 10, procedure: procedure) }
|
let(:dossiers) { create_list(:dossier, 10, procedure: procedure) }
|
||||||
let(:export_template) { create(:export_template, groupe_instructeur: procedure.defaut_groupe_instructeur).tap(&:set_default_values) }
|
let(:export_template) { create(:export_template, groupe_instructeur: procedure.defaut_groupe_instructeur) }
|
||||||
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template) }
|
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template) }
|
||||||
|
|
||||||
def pj_champ(d) = d.champs_public.find_by(type: 'Champs::PieceJustificativeChamp')
|
def pj_champ(d) = d.champs_public.find_by(type: 'Champs::PieceJustificativeChamp')
|
||||||
|
|
Loading…
Reference in a new issue