2019-07-01 15:55:37 +02:00
|
|
|
describe ActiveStorage::DownloadableFile do
|
2021-06-24 21:01:59 +02:00
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
2019-07-25 15:57:00 +02:00
|
|
|
|
|
|
|
subject(:list) { ActiveStorage::DownloadableFile.create_list_from_dossier(dossier) }
|
2019-07-01 15:55:37 +02:00
|
|
|
|
|
|
|
describe 'create_list_from_dossier' do
|
|
|
|
context 'when no piece_justificative is present' do
|
2021-03-08 11:35:20 +01:00
|
|
|
it { expect(list.length).to eq 1 }
|
2021-06-24 21:01:59 +02:00
|
|
|
it { expect(list.first[0].name).to eq "pdf_export_for_instructeur" }
|
2019-07-01 15:55:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a piece_justificative' do
|
|
|
|
before do
|
2020-07-20 17:18:44 +02:00
|
|
|
dossier.champs << create(:champ_piece_justificative, :with_piece_justificative_file, dossier: dossier)
|
2019-07-01 15:55:37 +02:00
|
|
|
end
|
|
|
|
|
2021-03-08 11:35:20 +01:00
|
|
|
it { expect(list.length).to eq 2 }
|
2019-07-01 15:55:37 +02:00
|
|
|
end
|
2019-09-03 15:17:19 +02:00
|
|
|
|
2020-06-24 15:21:51 +02:00
|
|
|
context 'when there is a private piece_justificative' do
|
|
|
|
before do
|
2020-07-20 17:18:44 +02:00
|
|
|
dossier.champs_private << create(:champ_piece_justificative, :with_piece_justificative_file, private: true, dossier: dossier)
|
2020-06-24 15:21:51 +02:00
|
|
|
end
|
|
|
|
|
2021-03-08 11:35:20 +01:00
|
|
|
it { expect(list.length).to eq 2 }
|
2020-06-24 15:21:51 +02:00
|
|
|
end
|
|
|
|
|
2019-09-03 15:17:19 +02:00
|
|
|
context 'when there is a repetition bloc' do
|
2020-07-20 17:18:44 +02:00
|
|
|
before do
|
2021-03-30 16:32:15 +02:00
|
|
|
dossier.champs << create(:champ_repetition_with_piece_jointe, dossier: dossier)
|
2020-07-20 17:18:44 +02:00
|
|
|
end
|
2019-09-03 15:17:19 +02:00
|
|
|
|
|
|
|
it 'should have 4 piece_justificatives' do
|
2021-03-08 11:35:20 +01:00
|
|
|
expect(list.size).to eq 5
|
2019-09-03 15:17:19 +02:00
|
|
|
end
|
|
|
|
end
|
2019-11-20 15:54:53 +01:00
|
|
|
|
|
|
|
context 'when there is a message with no attachment' do
|
2020-07-20 16:34:42 +02:00
|
|
|
before do
|
2020-07-20 17:18:44 +02:00
|
|
|
dossier.commentaires << create(:commentaire, dossier: dossier)
|
2020-07-20 16:34:42 +02:00
|
|
|
end
|
2019-11-20 15:54:53 +01:00
|
|
|
|
2021-03-08 11:35:20 +01:00
|
|
|
it { expect(list.length).to eq 1 }
|
2019-11-20 15:54:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a message with an attachment' do
|
2020-07-20 16:34:42 +02:00
|
|
|
before do
|
2020-07-20 17:18:44 +02:00
|
|
|
dossier.commentaires << create(:commentaire, :with_file, dossier: dossier)
|
2020-07-20 16:34:42 +02:00
|
|
|
end
|
2019-11-20 15:54:53 +01:00
|
|
|
|
2021-03-08 11:35:20 +01:00
|
|
|
it { expect(list.length).to eq 2 }
|
2019-11-20 15:54:53 +01:00
|
|
|
end
|
2021-09-27 15:07:56 +02:00
|
|
|
|
|
|
|
context 'when the files are asked by an expert with piece justificative and private piece justificative' do
|
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
let(:procedure) { create(:procedure, :published, :with_piece_justificative, instructeurs: [instructeur]) }
|
|
|
|
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
|
|
|
let(:champ) { dossier.champs.first }
|
|
|
|
let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }
|
|
|
|
|
|
|
|
subject(:list) { ActiveStorage::DownloadableFile.create_list_from_dossier(dossier, true) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
dossier.champs_private << create(:champ_piece_justificative, :with_piece_justificative_file, private: true, dossier: dossier)
|
|
|
|
|
|
|
|
dossier.champs << create(:champ_piece_justificative, :with_piece_justificative_file, dossier: dossier)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(list.length).to eq 2 }
|
|
|
|
end
|
2019-07-01 15:55:37 +02:00
|
|
|
end
|
|
|
|
end
|