When a new PJ is uploaded enqueue a anti virus scan job

This commit is contained in:
Mathieu Magnin 2018-05-11 14:59:20 +02:00
parent 927cd3c6f4
commit cd4615b10d
8 changed files with 105 additions and 0 deletions

View file

@ -0,0 +1,32 @@
RSpec.describe AntiVirusJob, type: :job do
let(:champ) do
champ = create(:champ, :piece_justificative)
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
champ
end
let(:virus_scan) { create(:virus_scan, status: "pending", champ: champ, blob_key: champ.piece_justificative_file.blob.key) }
subject { AntiVirusJob.new.perform(virus_scan) }
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
it { expect(virus_scan.reload.status).to eq("safe") }
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
it { expect(virus_scan.reload.status).to eq("infected") }
end
end