add bug report to archive
This commit is contained in:
parent
aa0bd47269
commit
38e3469e9a
3 changed files with 57 additions and 1 deletions
|
@ -95,6 +95,10 @@ class PiecesJustificativesService
|
|||
def attached?
|
||||
true
|
||||
end
|
||||
|
||||
def record_type
|
||||
'Fake'
|
||||
end
|
||||
end
|
||||
|
||||
def self.generate_dossier_export(dossier)
|
||||
|
|
|
@ -25,14 +25,19 @@ class ProcedureArchiveService
|
|||
tmp_file = Tempfile.new(['tc', '.zip'])
|
||||
|
||||
Zip::OutputStream.open(tmp_file) do |zipfile|
|
||||
bug_reports = ''
|
||||
files.each do |attachment, pj_filename|
|
||||
zipfile.put_next_entry("procedure-#{@procedure.id}/#{pj_filename}")
|
||||
begin
|
||||
zipfile.puts(attachment.download)
|
||||
rescue
|
||||
raise "Problem while trying to attach #{pj_filename}"
|
||||
bug_reports += "Impossible de récupérer le fichier #{pj_filename}\n"
|
||||
end
|
||||
end
|
||||
if !bug_reports.empty?
|
||||
zipfile.put_next_entry("LISEZMOI.txt")
|
||||
zipfile.puts(bug_reports)
|
||||
end
|
||||
end
|
||||
|
||||
archive.file.attach(io: File.open(tmp_file), filename: archive.filename(@procedure))
|
||||
|
|
|
@ -53,6 +53,48 @@ describe ProcedureArchiveService do
|
|||
end
|
||||
expect(archive.file.attached?).to be_truthy
|
||||
end
|
||||
|
||||
context 'with a missing file' do
|
||||
let(:pj) do
|
||||
PiecesJustificativesService::FakeAttachment.new(
|
||||
file: StringIO.new('coucou'),
|
||||
filename: "export-dossier.pdf",
|
||||
name: 'pdf_export_for_instructeur',
|
||||
id: 1,
|
||||
created_at: Time.zone.now
|
||||
)
|
||||
end
|
||||
|
||||
let(:bad_pj) do
|
||||
PiecesJustificativesService::FakeAttachment.new(
|
||||
file: nil,
|
||||
filename: "cni.png",
|
||||
name: 'cni.png',
|
||||
id: 2,
|
||||
created_at: Time.zone.now
|
||||
)
|
||||
end
|
||||
|
||||
let(:documents) { [pj, bad_pj] }
|
||||
before do
|
||||
allow(PiecesJustificativesService).to receive(:liste_documents).and_return(documents)
|
||||
end
|
||||
|
||||
it 'collect files without raising exception' do
|
||||
expect { service.collect_files_archive(archive, instructeur) }.not_to raise_exception
|
||||
end
|
||||
|
||||
it 'add bug report to archive' do
|
||||
service.collect_files_archive(archive, instructeur)
|
||||
|
||||
archive.file.open do |f|
|
||||
files = ZipTricks::FileReader.read_zip_structure(io: f)
|
||||
expect(files.size).to be 4
|
||||
expect(files.last.filename).to include("LISEZMOI")
|
||||
expect(extract(f, files.last)).to match(/Impossible de .*cni.*png/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'for all months' do
|
||||
|
@ -80,4 +122,9 @@ describe ProcedureArchiveService do
|
|||
Timecop.freeze(Time.zone.local(year, month, 5))
|
||||
create(:dossier, :accepte, :with_attestation, procedure: procedure)
|
||||
end
|
||||
|
||||
def extract(zip_file, zip_entry)
|
||||
extractor = zip_entry.extractor_from(zip_file)
|
||||
extractor.extract
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue