2022-11-21 18:32:17 +01:00
|
|
|
|
RSpec.describe Attachment::ShowComponent, type: :component do
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
|
|
|
|
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
|
|
|
|
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
|
|
|
|
let(:champ) { dossier.champs.first }
|
2022-11-21 18:32:17 +01:00
|
|
|
|
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:attachment) { champ.piece_justificative_file.attachments.first }
|
2022-11-22 15:47:28 +01:00
|
|
|
|
let(:filename) { attachment.filename.to_s }
|
|
|
|
|
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:virus_scan_result) { nil }
|
|
|
|
|
let(:component) { described_class.new(attachment:) }
|
2022-11-21 18:32:17 +01:00
|
|
|
|
|
|
|
|
|
subject { render_inline(component).to_html }
|
|
|
|
|
|
2019-02-20 14:08:53 +01:00
|
|
|
|
before do
|
2022-12-22 18:20:58 +01:00
|
|
|
|
attachment.blob.update(virus_scan_result:, metadata: attachment.blob.metadata.merge(virus_scan_result:))
|
2019-02-20 14:08:53 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when there is no anti-virus scan' do
|
2019-05-02 11:37:27 +02:00
|
|
|
|
let(:virus_scan_result) { nil }
|
2019-02-20 14:08:53 +01:00
|
|
|
|
|
|
|
|
|
it 'allows to download the file' do
|
2022-11-22 15:47:28 +01:00
|
|
|
|
expect(subject).to have_link(filename)
|
2019-02-20 14:08:53 +01:00
|
|
|
|
expect(subject).to have_text('ce fichier n’a pas été analysé par notre antivirus')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the anti-virus scan is pending' do
|
2019-05-02 11:37:27 +02:00
|
|
|
|
let(:virus_scan_result) { ActiveStorage::VirusScanner::PENDING }
|
2019-02-20 14:08:53 +01:00
|
|
|
|
|
|
|
|
|
it 'displays the filename, but doesn’t allow to download the file' do
|
2022-11-22 15:47:28 +01:00
|
|
|
|
expect(subject).to have_text(filename)
|
|
|
|
|
expect(subject).not_to have_link(filename)
|
2022-11-09 12:33:20 +01:00
|
|
|
|
expect(subject).to have_text('Analyse antivirus en cours')
|
2019-02-20 14:08:53 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the file is scanned and safe' do
|
2019-05-02 11:37:27 +02:00
|
|
|
|
let(:virus_scan_result) { ActiveStorage::VirusScanner::SAFE }
|
2019-02-20 14:08:53 +01:00
|
|
|
|
|
|
|
|
|
it 'allows to download the file' do
|
2022-11-22 15:47:28 +01:00
|
|
|
|
expect(subject).to have_link(filename)
|
2019-02-20 14:08:53 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the file is scanned and infected' do
|
2019-05-02 11:37:27 +02:00
|
|
|
|
let(:virus_scan_result) { ActiveStorage::VirusScanner::INFECTED }
|
2019-02-20 14:08:53 +01:00
|
|
|
|
|
|
|
|
|
it 'displays the filename, but doesn’t allow to download the file' do
|
2022-11-22 15:47:28 +01:00
|
|
|
|
expect(subject).to have_text(filename)
|
|
|
|
|
expect(subject).not_to have_link(filename)
|
2022-11-09 12:33:20 +01:00
|
|
|
|
expect(subject).to have_text('Virus détecté')
|
2019-02-20 14:08:53 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2021-04-06 16:32:45 +02:00
|
|
|
|
|
|
|
|
|
context 'when the file is corrupted' do
|
|
|
|
|
let(:virus_scan_result) { ActiveStorage::VirusScanner::INTEGRITY_ERROR }
|
|
|
|
|
|
|
|
|
|
it 'displays the filename, but doesn’t allow to download the file' do
|
2022-11-22 15:47:28 +01:00
|
|
|
|
expect(subject).to have_text(filename)
|
|
|
|
|
expect(subject).not_to have_link(filename)
|
2021-04-06 16:32:45 +02:00
|
|
|
|
expect(subject).to have_text('corrompu')
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-02-20 14:08:53 +01:00
|
|
|
|
end
|