2019-05-21 14:21:13 +02:00
|
|
|
|
describe 'shared/attachment/_show.html.haml', type: :view do
|
2019-05-02 11:37:27 +02:00
|
|
|
|
let(:champ) { create(:champ_piece_justificative) }
|
|
|
|
|
let(:virus_scan_result) { nil }
|
2019-02-20 14:08:53 +01:00
|
|
|
|
|
|
|
|
|
before do
|
2019-05-02 11:37:27 +02:00
|
|
|
|
champ.piece_justificative_file.blob.update(metadata: champ.piece_justificative_file.blob.metadata.merge(virus_scan_result: virus_scan_result))
|
2019-02-20 14:08:53 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-05-21 14:21:13 +02:00
|
|
|
|
subject { render 'shared/attachment/show', attachment: champ.piece_justificative_file.attachment }
|
2019-02-20 14:08:53 +01:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
expect(subject).to have_link(champ.piece_justificative_file.filename.to_s)
|
|
|
|
|
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
|
|
|
|
|
expect(subject).to have_text(champ.piece_justificative_file.filename.to_s)
|
|
|
|
|
expect(subject).not_to have_link(champ.piece_justificative_file.filename.to_s)
|
|
|
|
|
expect(subject).to have_text('analyse antivirus en cours')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-10 12:50:40 +01:00
|
|
|
|
context 'when watermark is pending' do
|
|
|
|
|
let(:champ) { create(:champ_titre_identite) }
|
|
|
|
|
|
|
|
|
|
it 'displays the filename, but doesn’t allow to download the file' do
|
|
|
|
|
pp champ.piece_justificative_file.attachment.watermark_pending?
|
|
|
|
|
expect(subject).to have_text(champ.piece_justificative_file.filename.to_s)
|
|
|
|
|
expect(subject).not_to have_link(champ.piece_justificative_file.filename.to_s)
|
|
|
|
|
expect(subject).to have_text('traitement de la pièce en cours')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-20 14:08:53 +01:00
|
|
|
|
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
|
|
|
|
|
expect(subject).to have_link(champ.piece_justificative_file.filename.to_s)
|
|
|
|
|
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
|
|
|
|
|
expect(subject).to have_text(champ.piece_justificative_file.filename.to_s)
|
|
|
|
|
expect(subject).not_to have_link(champ.piece_justificative_file.filename.to_s)
|
|
|
|
|
expect(subject).to have_text('virus détecté')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|