test(dossier.pdf): add a test case with piece_justificative inside repetition

This commit is contained in:
Paul Chavard 2022-07-21 10:01:10 +02:00
parent 5d5f46b4d8
commit 430365768a
4 changed files with 25 additions and 16 deletions

View file

@ -263,9 +263,9 @@ describe API::V1::DossiersController do
it 'should have rows' do
expect(subject.size).to eq(2)
expect(subject[0][:id]).to eq(1)
expect(subject[0][:champs].size).to eq(2)
expect(subject[0][:champs].map { |c| c[:value] }).to eq(['text', '42'])
expect(subject[0][:champs].map { |c| c[:type_de_champ][:type_champ] }).to eq(['text', 'number'])
expect(subject[0][:champs].size).to eq(3)
expect(subject[0][:champs].map { |c| c[:value] }).to eq(['text', 'text', '42'])
expect(subject[0][:champs].map { |c| c[:type_de_champ][:type_champ] }).to eq(['text', 'text', 'number'])
end
end
end

View file

@ -226,6 +226,7 @@ FactoryBot.define do
position: 0,
parent: parent,
libelle: 'Nom')
types_de_champ.push(type_de_champ_text)
end
type_de_champ_number = types_de_champ.find { |tdc| tdc.libelle == 'Age' }
@ -235,13 +236,13 @@ FactoryBot.define do
position: 1,
parent: parent,
libelle: 'Age')
types_de_champ.push(type_de_champ_number)
end
evaluator.rows.times do |row|
champ_repetition.champs << [
build(:champ_text, dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ_text, parent: champ_repetition),
build(:champ_number, dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ_number, parent: champ_repetition)
]
champ_repetition.champs << types_de_champ.map do |type_de_champ|
build(:"champ_#{type_de_champ.type_champ}", dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ, parent: champ_repetition)
end
end
end

View file

@ -10,19 +10,22 @@ FactoryBot.define do
procedure { nil }
position { nil }
parent { nil }
no_coordinate { false }
end
after(:build) do |type_de_champ, evaluator|
revision = evaluator.procedure&.active_revision || build(:procedure_revision)
evaluator.procedure&.save
if !evaluator.no_coordinate
revision = evaluator.procedure&.active_revision || build(:procedure_revision)
evaluator.procedure&.save
revision.revision_types_de_champ << build(:procedure_revision_type_de_champ,
position: evaluator.position || 0,
revision: revision,
type_de_champ: type_de_champ,
parent: evaluator.parent)
revision.revision_types_de_champ << build(:procedure_revision_type_de_champ,
position: evaluator.position || 0,
revision: revision,
type_de_champ: type_de_champ,
parent: evaluator.parent)
revision.save
revision.save
end
end
trait :private do

View file

@ -190,7 +190,12 @@ describe PiecesJustificativesService do
end
describe '.generate_dossier_export' do
let(:dossier) { create(:dossier) }
let(:procedure) do
create(:procedure, :with_piece_justificative).tap do |procedure|
create(:type_de_champ_repetition, procedure: procedure, types_de_champ: [create(:type_de_champ_piece_justificative, procedure: procedure, no_coordinate: true)])
end
end
let(:dossier) { create(:dossier, :with_populated_champs, procedure: procedure) }
subject { PiecesJustificativesService.generate_dossier_export(Dossier.where(id: dossier.id)) }