This commit is contained in:
Kara Diaby 2024-02-21 02:01:24 +00:00
parent 5488067801
commit 2612b0a2d1
7 changed files with 43 additions and 15 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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'))