From d96fba1341114d9c1b8124373243bc7938468702 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 6 Dec 2022 15:03:31 +0100 Subject: [PATCH 1/2] bug(export.pjs): sur l'export, les champs de type piece justificative devraient renvoyer un tableau de la meme dimension quelque soit le nombre de pj joint --- spec/services/procedure_export_service_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index a0e737a7d..43c9c517a 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -98,6 +98,7 @@ describe ProcedureExportService do offset = dossier.depose_at.utc_offset depose_at = Time.zone.at(dossiers_sheet.data[0][8] - offset.seconds) en_instruction_at = Time.zone.at(dossiers_sheet.data[0][9] - offset.seconds) + expect(dossiers_sheet.data.first.size).to eq(nominal_headers.size) expect(depose_at).to eq(dossier.depose_at.round) expect(en_instruction_at).to eq(dossier.en_instruction_at.round) end @@ -119,6 +120,17 @@ describe ProcedureExportService do it { expect(dossiers_sheet.headers).to match(routee_headers) } it { expect(dossiers_sheet.data[0][dossiers_sheet.headers.index('Groupe instructeur')]).to eq('défaut') } end + + context 'with a dossier having multiple pjs' do + let!(:dossier_2) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) } + before do + dossier_2.champs_public + .find { _1.is_a? Champs::PieceJustificativeChamp } + .piece_justificative_file + .attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain") + end + it { expect(dossiers_sheet.data.first.size).to eq(nominal_headers.size) } + end end describe 'Etablissement sheet' do From 2eaa06b22b6d4e57981e514e4e5369af2fb61bf7 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 6 Dec 2022 15:05:37 +0100 Subject: [PATCH 2/2] correctif(export.pjs): sur l'export, les champs de type piece justificative renvoyent un tableau de la meme dimension quelque soit le nombre de pj joint --- app/models/champs/piece_justificative_champ.rb | 2 +- spec/models/champs/piece_justificative_champ_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index 708f17d24..eed62083b 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -43,7 +43,7 @@ class Champs::PieceJustificativeChamp < Champ end def for_export - piece_justificative_file.map { _1.filename.to_s } + piece_justificative_file.map { _1.filename.to_s }.join(', ') end def for_api diff --git a/spec/models/champs/piece_justificative_champ_spec.rb b/spec/models/champs/piece_justificative_champ_spec.rb index 1e0c9c80c..7861ad09a 100644 --- a/spec/models/champs/piece_justificative_champ_spec.rb +++ b/spec/models/champs/piece_justificative_champ_spec.rb @@ -43,11 +43,11 @@ describe Champs::PieceJustificativeChamp do let(:champ_pj) { create(:champ_piece_justificative) } subject { champ_pj.for_export } - it { is_expected.to match_array(['toto.txt']) } + it { is_expected.to eq('toto.txt') } context 'without attached file' do before { champ_pj.piece_justificative_file.purge } - it { is_expected.to eq([]) } + it { is_expected.to eq('') } end end