spec: fix

This commit is contained in:
simon lehericey 2024-05-21 17:05:34 +02:00
parent e38999efda
commit d3b700326d
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 8 additions and 9 deletions

View file

@ -130,7 +130,7 @@ describe ExportTemplate do
dossier.champs_public << champ_pj dossier.champs_public << champ_pj
end end
it 'returns pj and custom name for pj' do it 'returns pj and custom name for pj' do
expect(export_template.attachment_and_path(dossier, attachment)).to eq([attachment, "DOSSIER_#{dossier.id}/superpj_justif-1.png"]) expect(export_template.attachment_and_path(dossier, attachment, champ: champ_pj)).to eq([attachment, "DOSSIER_#{dossier.id}/superpj_justif-1.png"])
end end
end end
context 'pj repetable' do context 'pj repetable' do
@ -161,7 +161,7 @@ describe ExportTemplate do
dossier.champs_public << champ_pj dossier.champs_public << champ_pj
end end
it 'rename repetable pj' do it 'rename repetable pj' do
expect(export_template.attachment_and_path(dossier, attachment)).to eq([attachment, "DOSSIER_#{dossier.id}/pj_repet_#{dossier.id}-1.png"]) expect(export_template.attachment_and_path(dossier, attachment, champ: champ_pj)).to eq([attachment, "DOSSIER_#{dossier.id}/pj_repet_#{dossier.id}-1.png"])
end end
end end
end end
@ -272,7 +272,7 @@ describe ExportTemplate do
let(:pdf_mention) { { "type" => "mention", "attrs" => {} } } let(:pdf_mention) { { "type" => "mention", "attrs" => {} } }
it "add error for pdf name" do it "add error for pdf name" do
expect(subject.valid?).to be_falsey expect(subject.valid?).to be_falsey
expect(subject.errors.full_messages).to include "Le champ « Nom de l'export » doit être rempli" expect(subject.errors.full_messages).to include "Le champ « Nom du dossier au format pdf » doit être rempli"
end end
end end
end end

View file

@ -1,6 +1,6 @@
describe ProcedureExportService do describe ProcedureExportService do
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :piece_justificative, libelle: 'pj' }, { type: :repetition, children: [{ type: :piece_justificative }] }]) } let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :piece_justificative, libelle: 'pj' }, { type: :repetition, children: [{ type: :piece_justificative, libelle: 'repet_pj' }] }]) }
let(:dossiers) { create_list(:dossier, 10, procedure: procedure) } let(:dossiers) { create_list(:dossier, 10, procedure: procedure) }
let(:export_template) { create(:export_template, groupe_instructeur: procedure.defaut_groupe_instructeur).tap(&:set_default_values) } let(:export_template) { create(:export_template, groupe_instructeur: procedure.defaut_groupe_instructeur).tap(&:set_default_values) }
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template) } let(:service) { ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template) }
@ -40,22 +40,21 @@ describe ProcedureExportService do
subject subject
end end
expect(sql_count).to eq(58) expect(sql_count <= 58).to be_truthy
dossier = dossiers.first dossier = dossiers.first
File.write('tmp.zip', subject.download, mode: 'wb') File.write('tmp.zip', subject.download, mode: 'wb')
File.open('tmp.zip') do |fd| File.open('tmp.zip') do |fd|
files = ZipTricks::FileReader.read_zip_structure(io: fd) files = ZipTricks::FileReader.read_zip_structure(io: fd)
base_fn = "export"
structure = [ structure = [
"export/", "export/",
"export/dossier-#{dossier.id}/", "export/dossier-#{dossier.id}/",
"export/dossier-#{dossier.id}/export_#{dossier.id}.pdf", "export/dossier-#{dossier.id}/export_#{dossier.id}.pdf",
"export/dossier-#{dossier.id}/pj-#{dossier.id}-1.png", "export/dossier-#{dossier.id}/pj-#{dossier.id}-1.png",
"export/dossier-#{dossier.id}/libelle-du-champ-2-#{dossier.id}-1-1.png", "export/dossier-#{dossier.id}/repet_pj-#{dossier.id}-1-1.png",
"export/dossier-#{dossier.id}/libelle-du-champ-2-#{dossier.id}-2-1.png", "export/dossier-#{dossier.id}/repet_pj-#{dossier.id}-2-1.png",
"export/dossier-#{dossier.id}/libelle-du-champ-2-#{dossier.id}-1-2.png" "export/dossier-#{dossier.id}/repet_pj-#{dossier.id}-1-2.png"
] ]
expect(files.size).to eq(dossiers.count * 6 + 1) expect(files.size).to eq(dossiers.count * 6 + 1)