2020-03-26 17:28:24 +01:00
|
|
|
require 'active_storage_validations/matchers'
|
|
|
|
|
2019-02-05 20:57:58 +01:00
|
|
|
describe Champs::PieceJustificativeChamp do
|
2020-03-26 17:28:24 +01:00
|
|
|
include ActiveStorageValidations::Matchers
|
|
|
|
|
|
|
|
# TODO: once we're running on Rails 6, re-enable the PieceJustificativeChamp validator,
|
|
|
|
# and re-enable this spec.
|
|
|
|
#
|
|
|
|
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
|
|
|
|
describe "validations", pending: true do
|
|
|
|
subject(:champ_pj) { build(:champ_piece_justificative) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_size_of(:piece_justificative_file).less_than(Champs::PieceJustificativeChamp::MAX_SIZE) }
|
|
|
|
it { is_expected.to validate_content_type_of(:piece_justificative_file).allowing(Champs::PieceJustificativeChamp::ACCEPTED_FORMATS) }
|
|
|
|
end
|
|
|
|
|
2020-05-13 16:24:35 +02:00
|
|
|
describe "#for_export" do
|
|
|
|
let(:champ_pj) { create(:champ_piece_justificative) }
|
|
|
|
subject { champ_pj.for_export }
|
|
|
|
|
|
|
|
it { is_expected.to eq('toto.txt') }
|
|
|
|
|
|
|
|
context 'without attached file' do
|
|
|
|
before { champ_pj.piece_justificative_file.purge }
|
|
|
|
it { is_expected.to eq(nil) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 20:57:58 +01:00
|
|
|
describe '#for_api' do
|
|
|
|
let(:champ_pj) { create(:champ_piece_justificative) }
|
2019-05-02 11:37:35 +02:00
|
|
|
let(:metadata) { champ_pj.piece_justificative_file.blob.metadata }
|
2019-02-05 20:57:58 +01:00
|
|
|
|
2019-05-02 11:37:35 +02:00
|
|
|
before { champ_pj.piece_justificative_file.blob.update(metadata: metadata.merge(virus_scan_result: status)) }
|
2019-02-05 20:57:58 +01:00
|
|
|
|
|
|
|
subject { champ_pj.for_api }
|
|
|
|
|
|
|
|
context 'when file is safe' do
|
2019-05-02 11:37:35 +02:00
|
|
|
let(:status) { ActiveStorage::VirusScanner::SAFE }
|
2019-12-19 18:29:01 +01:00
|
|
|
it { is_expected.to include("/rails/active_storage/disk/") }
|
2019-02-05 20:57:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when file is not scanned' do
|
2019-05-02 11:37:35 +02:00
|
|
|
let(:status) { ActiveStorage::VirusScanner::PENDING }
|
2019-12-19 18:29:01 +01:00
|
|
|
it { is_expected.to include("/rails/active_storage/disk/") }
|
2019-02-05 20:57:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when file is infected' do
|
2019-05-02 11:37:35 +02:00
|
|
|
let(:status) { ActiveStorage::VirusScanner::INFECTED }
|
2019-02-05 20:57:58 +01:00
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|