diff --git a/spec/components/attachment/edit_component_spec.rb b/spec/components/attachment/edit_component_spec.rb index 3ce2e9535..c9298f9ff 100644 --- a/spec/components/attachment/edit_component_spec.rb +++ b/spec/components/attachment/edit_component_spec.rb @@ -66,8 +66,8 @@ RSpec.describe Attachment::EditComponent, type: :component do ) end - it 'does not render an empty file' do # (is is rendered by MultipleComponent) - expect(subject).not_to have_selector('input[type=file]') + it 'does render an empty file' do # (is is rendered by MultipleComponent) + expect(subject).to have_selector('input[type=file]') end it 'renders max size for first index' do diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 4f1aef223..4805df781 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -432,6 +432,12 @@ describe API::V2::GraphqlController do byteSize contentType } + attachments { + filename + checksum + byteSize + contentType + } } avis { expert { @@ -519,11 +525,19 @@ describe API::V2::GraphqlController do { body: commentaire.body, attachment: { - filename: commentaire.piece_jointe.filename.to_s, - contentType: commentaire.piece_jointe.content_type, - checksum: commentaire.piece_jointe.checksum, - byteSize: commentaire.piece_jointe.byte_size + filename: commentaire.piece_jointe.first.filename.to_s, + contentType: commentaire.piece_jointe.first.content_type, + checksum: commentaire.piece_jointe.first.checksum, + byteSize: commentaire.piece_jointe.first.byte_size }, + attachments: commentaire.piece_jointe.map do |pj| + { + filename: pj.filename.to_s, + contentType: pj.content_type, + checksum: pj.checksum, + byteSize: pj.byte_size + } + end, email: commentaire.email } end diff --git a/spec/controllers/experts/avis_controller_spec.rb b/spec/controllers/experts/avis_controller_spec.rb index 5d5786ddf..7a4029eed 100644 --- a/spec/controllers/experts/avis_controller_spec.rb +++ b/spec/controllers/experts/avis_controller_spec.rb @@ -321,7 +321,7 @@ describe Experts::AvisController, type: :controller do let(:now) { Time.zone.parse("14/07/1789") } let(:avis) { avis_without_answer } - subject { post :create_commentaire, params: { id: avis.id, procedure_id:, commentaire: { body: 'commentaire body', piece_jointe: file } } } + subject { post :create_commentaire, params: { id: avis.id, procedure_id:, commentaire: { body: 'commentaire body', piece_jointe: [file] } } } before do allow(ClamavService).to receive(:safe_file?).and_return(scan_result) @@ -343,7 +343,7 @@ describe Experts::AvisController, type: :controller do it do expect { subject }.to change(Commentaire, :count).by(1) - expect(Commentaire.last.piece_jointe.filename).to eq("piece_justificative_0.pdf") + expect(Commentaire.last.piece_jointe.first.filename).to eq("piece_justificative_0.pdf") end end diff --git a/spec/factories/commentaire.rb b/spec/factories/commentaire.rb index 395859b11..13aaf74a7 100644 --- a/spec/factories/commentaire.rb +++ b/spec/factories/commentaire.rb @@ -2,11 +2,16 @@ FactoryBot.define do factory :commentaire do association :dossier, :en_construction email { generate(:user_email) } - body { 'plop' } trait :with_file do - piece_jointe { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') } + after(:build) do |commentaire| + commentaire.piece_jointe.attach( + io: File.open('spec/fixtures/files/logo_test_procedure.png'), + filename: 'logo_test_procedure.png', + content_type: 'image/png' + ) + end end end end diff --git a/spec/services/commentaire_service_spec.rb b/spec/services/commentaire_service_spec.rb index a84bb8500..e3441b10f 100644 --- a/spec/services/commentaire_service_spec.rb +++ b/spec/services/commentaire_service_spec.rb @@ -26,11 +26,20 @@ describe CommentaireService do end end - context 'when it has a file' do - let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') } + context 'when it has multiple files' do + let(:files) do + [ + fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') + ] + end - it 'attaches the file' do + before do + commentaire.piece_jointe.attach(files) + end + + it 'attaches the files' do expect(commentaire.piece_jointe.attached?).to be_truthy + expect(commentaire.piece_jointe.count).to eq(1) end end end diff --git a/spec/services/pieces_justificatives_service_spec.rb b/spec/services/pieces_justificatives_service_spec.rb index eaf7a919d..7a212912e 100644 --- a/spec/services/pieces_justificatives_service_spec.rb +++ b/spec/services/pieces_justificatives_service_spec.rb @@ -69,7 +69,7 @@ describe PiecesJustificativesService do attach_file(witness_commentaire.piece_jointe) end - it { expect(subject).to match_array(dossier.commentaires.first.piece_jointe.attachment) } + it { expect(subject).to match_array(dossier.commentaires.first.piece_jointe.attachments) } end context 'with a pj not safe on a commentaire' do diff --git a/spec/system/users/en_construction_spec.rb b/spec/system/users/en_construction_spec.rb index 0444caba9..f0fd43acf 100644 --- a/spec/system/users/en_construction_spec.rb +++ b/spec/system/users/en_construction_spec.rb @@ -31,7 +31,7 @@ describe "Dossier en_construction" do click_on "Supprimer le fichier toto.txt" - input_selector = "#attachment-multiple-empty-#{champ.public_id} " + input_selector = "#attachment-multiple-empty-#{champ.public_id}" expect(page).to have_selector(input_selector) find(input_selector).attach_file(Rails.root.join('spec/fixtures/files/file.pdf'))