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 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