fix(apiv1): piece_justificative continue to returns a single attachment
This commit is contained in:
parent
342a7b8ee4
commit
f4d403a81c
4 changed files with 16 additions and 16 deletions
|
@ -49,10 +49,12 @@ class Champs::PieceJustificativeChamp < Champ
|
|||
def for_api
|
||||
return nil unless piece_justificative_file.attached?
|
||||
|
||||
piece_justificative_file.filter_map do |attachment|
|
||||
if attachment.virus_scanner.safe? || attachment.virus_scanner.pending?
|
||||
attachment.service_url
|
||||
end
|
||||
# API v1 don't support multiple PJ
|
||||
attachment = piece_justificative_file.first
|
||||
return nil if attachment.nil?
|
||||
|
||||
if attachment.virus_scanner.safe? || attachment.virus_scanner.pending?
|
||||
attachment.service_url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,14 +46,12 @@ class PiecesJustificativesService
|
|||
|
||||
def self.serialize_champs_as_pjs(dossier)
|
||||
dossier.champs_public.filter { |champ| champ.type_de_champ.old_pj }.map do |champ|
|
||||
champ.for_api&.map do |content_url|
|
||||
{
|
||||
created_at: champ.created_at&.in_time_zone('UTC'),
|
||||
type_de_piece_justificative_id: champ.type_de_champ.old_pj[:stable_id],
|
||||
content_url:,
|
||||
user: champ.dossier.user
|
||||
}
|
||||
end
|
||||
{
|
||||
created_at: champ.created_at&.in_time_zone('UTC'),
|
||||
type_de_piece_justificative_id: champ.type_de_champ.old_pj[:stable_id],
|
||||
content_url: champ.for_api,
|
||||
user: champ.dossier.user
|
||||
}
|
||||
end.flatten
|
||||
end
|
||||
|
||||
|
|
|
@ -61,17 +61,17 @@ describe Champs::PieceJustificativeChamp do
|
|||
|
||||
context 'when file is safe' do
|
||||
let(:status) { ActiveStorage::VirusScanner::SAFE }
|
||||
it { is_expected.to match_array([include("/rails/active_storage/disk/")]) }
|
||||
it { is_expected.to include("/rails/active_storage/disk/") }
|
||||
end
|
||||
|
||||
context 'when file is not scanned' do
|
||||
let(:status) { ActiveStorage::VirusScanner::PENDING }
|
||||
it { is_expected.to match_array([include("/rails/active_storage/disk/")]) }
|
||||
it { is_expected.to include("/rails/active_storage/disk/") }
|
||||
end
|
||||
|
||||
context 'when file is infected' do
|
||||
let(:status) { ActiveStorage::VirusScanner::INFECTED }
|
||||
it { is_expected.to eq([]) }
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ describe ChampSerializer do
|
|||
let(:champ) { create(:champ_piece_justificative) }
|
||||
|
||||
it {
|
||||
expect(subject[:value]).to match_array([a_string_matching('/rails/active_storage/disk/')])
|
||||
expect(subject[:value]).to a_string_matching('/rails/active_storage/disk/')
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue