feat(piece_justificative): allow user to replace a PJ for dossier en_construction

This commit is contained in:
Colin Darie 2022-12-13 15:22:18 +01:00
parent 93de4cf821
commit 4049240c2c
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
12 changed files with 108 additions and 14 deletions

View file

@ -5,6 +5,8 @@ describe Champs::PieceJustificativeController, type: :controller do
let(:champ) { dossier.champs_public.first }
describe '#update' do
let(:replace_attachment_id) { nil }
render_views
before { sign_in user }
@ -12,8 +14,9 @@ describe Champs::PieceJustificativeController, type: :controller do
put :update, params: {
position: '1',
champ_id: champ.id,
blob_signed_id: file
}, format: :turbo_stream
blob_signed_id: file,
replace_attachment_id:
}.compact, format: :turbo_stream
end
context 'when the file is valid' do
@ -65,6 +68,33 @@ describe Champs::PieceJustificativeController, type: :controller do
expect(JSON.parse(response.body)).to eq({ 'errors' => ['La pièce justificative nest pas dun type accepté'] })
end
end
context 'replace an attachment' do
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
before { subject }
context "attachment associated to dossier" do
let(:champ) { create(:champ, :with_piece_justificative_file, dossier:) }
let(:replace_attachment_id) { champ.piece_justificative_file.first.id }
it "replaces an existing attachment" do
champ.reload
expect(champ.piece_justificative_file.attachments.count).to eq(1)
expect(champ.piece_justificative_file.attachments.first.filename).to eq("piece_justificative_0.pdf")
end
end
context "attachment not associated to dossier" do
let(:other_champ) { create(:champ, :with_piece_justificative_file) }
let(:replace_attachment_id) { other_champ.piece_justificative_file.first.id }
it "add attachment, don't replace attachment" do
expect(champ.reload.piece_justificative_file.attachments.count).to eq(1)
expect(other_champ.reload.piece_justificative_file.attachments.count).to eq(1)
end
end
end
end
describe '#template' do