Merge pull request #6377 from betagouv/6374-add-bugreport-to-archive
add bug report to archive
This commit is contained in:
commit
ce317d04c6
3 changed files with 57 additions and 1 deletions
|
@ -95,6 +95,10 @@ class PiecesJustificativesService
|
||||||
def attached?
|
def attached?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def record_type
|
||||||
|
'Fake'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generate_dossier_export(dossier)
|
def self.generate_dossier_export(dossier)
|
||||||
|
|
|
@ -25,14 +25,19 @@ class ProcedureArchiveService
|
||||||
tmp_file = Tempfile.new(['tc', '.zip'])
|
tmp_file = Tempfile.new(['tc', '.zip'])
|
||||||
|
|
||||||
Zip::OutputStream.open(tmp_file) do |zipfile|
|
Zip::OutputStream.open(tmp_file) do |zipfile|
|
||||||
|
bug_reports = ''
|
||||||
files.each do |attachment, pj_filename|
|
files.each do |attachment, pj_filename|
|
||||||
zipfile.put_next_entry("procedure-#{@procedure.id}/#{pj_filename}")
|
zipfile.put_next_entry("procedure-#{@procedure.id}/#{pj_filename}")
|
||||||
begin
|
begin
|
||||||
zipfile.puts(attachment.download)
|
zipfile.puts(attachment.download)
|
||||||
rescue
|
rescue
|
||||||
raise "Problem while trying to attach #{pj_filename}"
|
bug_reports += "Impossible de récupérer le fichier #{pj_filename}\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if !bug_reports.empty?
|
||||||
|
zipfile.put_next_entry("LISEZMOI.txt")
|
||||||
|
zipfile.puts(bug_reports)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
archive.file.attach(io: File.open(tmp_file), filename: archive.filename(@procedure))
|
archive.file.attach(io: File.open(tmp_file), filename: archive.filename(@procedure))
|
||||||
|
|
|
@ -53,6 +53,48 @@ describe ProcedureArchiveService do
|
||||||
end
|
end
|
||||||
expect(archive.file.attached?).to be_truthy
|
expect(archive.file.attached?).to be_truthy
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'for all months' do
|
context 'for all months' do
|
||||||
|
@ -80,4 +122,9 @@ describe ProcedureArchiveService do
|
||||||
Timecop.freeze(Time.zone.local(year, month, 5))
|
Timecop.freeze(Time.zone.local(year, month, 5))
|
||||||
create(:dossier, :accepte, :with_attestation, procedure: procedure)
|
create(:dossier, :accepte, :with_attestation, procedure: procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extract(zip_file, zip_entry)
|
||||||
|
extractor = zip_entry.extractor_from(zip_file)
|
||||||
|
extractor.extract
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue