2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-02 22:13:09 +01:00
|
|
|
describe ExportTemplate do
|
|
|
|
let(:groupe_instructeur) { create(:groupe_instructeur, procedure:) }
|
2024-07-23 17:05:16 +02:00
|
|
|
let(:export_template) { build(:export_template, groupe_instructeur:) }
|
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public:, for_individual:) }
|
2024-03-20 16:02:34 +01:00
|
|
|
let(:for_individual) { false }
|
|
|
|
let(:types_de_champ_public) do
|
|
|
|
[
|
|
|
|
{ type: :piece_justificative, libelle: "Justificatif de domicile", mandatory: true, stable_id: 3 },
|
|
|
|
{ type: :titre_identite, libelle: "CNI", mandatory: true, stable_id: 5 }
|
|
|
|
]
|
|
|
|
end
|
2024-03-02 22:13:09 +01:00
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
describe '.default' do
|
2024-03-03 10:19:02 +01:00
|
|
|
it 'set default values' do
|
2024-07-23 17:05:16 +02:00
|
|
|
expect(export_template.export_pdf).to eq(ExportItem.default(prefix: "export", enabled: true))
|
|
|
|
expect(export_template.dossier_folder).to eq(ExportItem.default(prefix: "dossier", enabled: true))
|
|
|
|
expect(export_template.pjs).to eq([ExportItem.default(stable_id: 3, prefix: "justificatif-de-domicile", enabled: false)])
|
2024-05-29 11:08:46 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
describe '#pj' do
|
|
|
|
context 'when pj exists' do
|
|
|
|
subject { export_template.pj(double(stable_id: 3)) }
|
2024-03-02 22:13:09 +01:00
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
it { is_expected.to eq(ExportItem.default(stable_id: 3, prefix: "justificatif-de-domicile", enabled: false)) }
|
2024-03-02 22:13:09 +01:00
|
|
|
end
|
2024-03-03 10:03:12 +01:00
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
context 'when pj does not exist' do
|
|
|
|
subject { export_template.pj(TypeDeChamp.new(libelle: 'hi', stable_id: 10)) }
|
2024-03-03 10:03:12 +01:00
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
it { is_expected.to eq(ExportItem.default(stable_id: 10, prefix: "hi", enabled: false)) }
|
2024-03-03 10:03:12 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
describe '#attachment_path' do
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure:) }
|
2024-03-02 22:13:09 +01:00
|
|
|
|
|
|
|
context 'for export pdf' do
|
2024-07-23 17:05:16 +02:00
|
|
|
let(:export_template) do
|
|
|
|
build(:export_template, groupe_instructeur:, dossier_folder: ExportItem.default(prefix: "DOSSIER"), export_pdf: ExportItem.default(prefix: "mon_export"))
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:attachment) { ActiveStorage::Attachment.new(name: 'pdf_export_for_instructeur', blob: ActiveStorage::Blob.new(filename: "export.pdf")) }
|
2024-03-02 22:13:09 +01:00
|
|
|
|
|
|
|
it 'gives absolute filename for export of specific dossier' do
|
2024-07-23 17:05:16 +02:00
|
|
|
expect(export_template.attachment_path(dossier, attachment)).to eq("DOSSIER-#{dossier.id}/mon_export-#{dossier.id}.pdf")
|
2024-03-02 22:13:09 +01:00
|
|
|
end
|
|
|
|
end
|
2024-03-03 10:03:12 +01:00
|
|
|
|
|
|
|
context 'for pj' do
|
2024-07-23 17:05:16 +02:00
|
|
|
let(:champ_pj) { dossier.champs_public.first }
|
|
|
|
let(:export_template) { create(:export_template, groupe_instructeur:, pjs: [ExportItem.default(stable_id: 3, prefix: "justif", enabled: true)]) }
|
2024-03-03 10:03:12 +01:00
|
|
|
|
|
|
|
let(:attachment) { ActiveStorage::Attachment.new(name: 'pj', record: champ_pj, blob: ActiveStorage::Blob.new(filename: "superpj.png")) }
|
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
it 'returns pj and custom name for pj' do
|
|
|
|
expect(export_template.attachment_path(dossier, attachment, champ: champ_pj)).to eq("dossier-#{dossier.id}/justif-#{dossier.id}-01.png")
|
2024-06-04 10:19:15 +02:00
|
|
|
end
|
|
|
|
end
|
2024-03-20 16:02:34 +01:00
|
|
|
end
|
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
describe '#tags and #pj_tags' do
|
|
|
|
let(:procedure) { build(:procedure, for_individual:) }
|
2024-03-20 16:02:34 +01:00
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
context 'for entreprise procedure' do
|
|
|
|
let(:for_individual) { false }
|
|
|
|
let(:expected_tags) do
|
2024-09-12 17:08:20 +02:00
|
|
|
[
|
|
|
|
'entreprise_siren', 'entreprise_numero_tva_intracommunautaire', 'entreprise_siret_siege_social', 'entreprise_raison_sociale', 'entreprise_adresse',
|
|
|
|
'dossier_depose_at', 'dossier_procedure_libelle', 'dossier_service_name', 'dossier_number', 'dossier_groupe_instructeur', 'dossier_last_champ_updated_at'
|
|
|
|
]
|
2024-03-20 16:02:34 +01:00
|
|
|
end
|
|
|
|
|
2024-05-29 11:08:46 +02:00
|
|
|
it do
|
2024-09-12 17:08:20 +02:00
|
|
|
expect(export_template.tags.map { _1[:id] }).to match_array(expected_tags)
|
|
|
|
expect(export_template.pj_tags.map { _1[:id] }).to match_array(expected_tags + ['original-filename'])
|
2024-05-29 11:08:46 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-23 17:05:16 +02:00
|
|
|
context 'for individual procedure' do
|
|
|
|
let(:for_individual) { true }
|
|
|
|
let(:expected_tags) do
|
2024-09-12 17:08:20 +02:00
|
|
|
[
|
|
|
|
'individual_gender', 'individual_last_name', 'individual_first_name',
|
|
|
|
'dossier_depose_at', 'dossier_procedure_libelle', 'dossier_service_name', 'dossier_number', 'dossier_groupe_instructeur', 'dossier_last_champ_updated_at'
|
|
|
|
]
|
2024-03-20 16:02:34 +01:00
|
|
|
end
|
2024-05-29 11:08:46 +02:00
|
|
|
|
|
|
|
it do
|
2024-09-12 17:08:20 +02:00
|
|
|
expect(export_template.tags.map { _1[:id] }).to match_array(expected_tags)
|
|
|
|
expect(export_template.pj_tags.map { _1[:id] }).to match_array(expected_tags + ['original-filename'])
|
2024-05-29 11:08:46 +02:00
|
|
|
end
|
|
|
|
end
|
2024-03-20 16:02:34 +01:00
|
|
|
end
|
2024-03-02 22:13:09 +01:00
|
|
|
end
|