Merge pull request #7909 from betagouv/fix_conditionnal_export
fix(export): met une valeur null aux champs cachés lors des exports
This commit is contained in:
commit
e4ceaa1194
2 changed files with 93 additions and 53 deletions
|
@ -1092,7 +1092,14 @@ class Dossier < ApplicationRecord
|
|||
types_de_champ.flat_map do |type_de_champ|
|
||||
champ_or_new = champs.find { |champ| champ.stable_id == type_de_champ.stable_id }
|
||||
champ_or_new ||= type_de_champ.champ.build
|
||||
Array.wrap(champ_or_new.for_export || [nil]).map.with_index do |champ_value, index|
|
||||
|
||||
champ_values = if champ_or_new.visible?
|
||||
champ_or_new.for_export || [nil]
|
||||
else
|
||||
[nil]
|
||||
end
|
||||
|
||||
Array.wrap(champ_values).map.with_index do |champ_value, index|
|
||||
[type_de_champ.libelle_for_export(index), champ_value]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1483,6 +1483,7 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe "champs_for_export" do
|
||||
context 'with a unconditionnal procedure' do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no, :with_explication, :with_commune, :with_repetition, zones: [create(:zone)]) }
|
||||
let(:text_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } }
|
||||
let(:yes_no_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } }
|
||||
|
@ -1548,6 +1549,38 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with a procedure with a condition' do
|
||||
include Logic
|
||||
let(:types_de_champ) { [{ type: :yes_no }, { type: :text }] }
|
||||
let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ) }
|
||||
let(:dossier) { create(:dossier, procedure:) }
|
||||
let(:yes_no_tdc) { procedure.types_de_champ.first }
|
||||
let(:text_tdc) { procedure.types_de_champ.second }
|
||||
|
||||
subject { Dossier.champs_for_export(dossier.champs, dossier.champs.map(&:type_de_champ)) }
|
||||
|
||||
before do
|
||||
text_tdc.update(condition: ds_eq(champ_value(yes_no_tdc.stable_id), constant(true)))
|
||||
|
||||
yes_no, text = dossier.champs
|
||||
yes_no.update(value: yes_no_value)
|
||||
text.update(value: 'text')
|
||||
end
|
||||
|
||||
context 'with a champ visible' do
|
||||
let(:yes_no_value) { 'true' }
|
||||
|
||||
it { is_expected.to eq([[yes_no_tdc.libelle, "Oui"], [text_tdc.libelle, "text"]]) }
|
||||
end
|
||||
|
||||
context 'with a champ invisible' do
|
||||
let(:yes_no_value) { 'false' }
|
||||
|
||||
it { is_expected.to eq([[yes_no_tdc.libelle, "Non"], [text_tdc.libelle, nil]]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "remove_titres_identite!" do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :followed, :with_individual) }
|
||||
let(:type_de_champ_titre_identite) { create(:type_de_champ_titre_identite, procedure: dossier.procedure) }
|
||||
|
|
Loading…
Reference in a new issue