2019-05-02 11:37:35 +02:00
|
|
|
RSpec.describe VirusScannerJob, type: :job do
|
2020-07-13 14:29:29 +02:00
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
2018-05-11 14:59:20 +02:00
|
|
|
let(:champ) do
|
2020-07-20 17:18:44 +02:00
|
|
|
champ = create(:champ_piece_justificative)
|
2018-05-11 14:59:20 +02:00
|
|
|
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
2020-07-13 14:29:29 +02:00
|
|
|
champ.save
|
2018-05-11 14:59:20 +02:00
|
|
|
champ
|
|
|
|
end
|
|
|
|
|
2020-07-13 14:29:29 +02:00
|
|
|
subject do
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
VirusScannerJob.perform_later(champ.piece_justificative_file.blob)
|
|
|
|
end
|
|
|
|
end
|
2018-05-11 14:59:20 +02:00
|
|
|
|
|
|
|
context "when no virus is found" do
|
|
|
|
let(:virus_found?) { true }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(virus_found?)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2020-07-13 14:29:29 +02:00
|
|
|
it { expect(champ.reload.piece_justificative_file.virus_scanner.safe?).to be_truthy }
|
2018-05-11 14:59:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when a virus is found" do
|
|
|
|
let(:virus_found?) { false }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(virus_found?)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2020-07-13 14:29:29 +02:00
|
|
|
it { expect(champ.reload.piece_justificative_file.virus_scanner.infected?).to be_truthy }
|
2018-05-11 14:59:20 +02:00
|
|
|
end
|
2020-07-13 14:31:21 +02:00
|
|
|
|
|
|
|
context "when the blob has been deleted" do
|
|
|
|
before do
|
|
|
|
Champ.find(champ.id).piece_justificative_file.purge
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores the error" do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2018-05-11 14:59:20 +02:00
|
|
|
end
|