From daa4c28af7a3fcaec5f51282b52191ce43982aba Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 21 Nov 2023 11:02:33 +0100 Subject: [PATCH] add data from rnf field to export --- app/models/champs/rnf_champ.rb | 8 ++++++++ app/models/types_de_champ/rnf_type_de_champ.rb | 3 +++ spec/models/champs/rnf_champ_spec.rb | 7 +++++++ spec/services/procedure_export_service_spec.rb | 12 ++++++++++++ 4 files changed, 30 insertions(+) diff --git a/app/models/champs/rnf_champ.rb b/app/models/champs/rnf_champ.rb index d96b6ebde..938729401 100644 --- a/app/models/champs/rnf_champ.rb +++ b/app/models/champs/rnf_champ.rb @@ -20,4 +20,12 @@ class Champs::RNFChamp < Champ def blank? rnf_id.blank? end + + def for_export + if data + [rnf_id, data['title'], data.dig('address', 'label'), data.dig('address', 'cityCode'), "#{data['department']} - #{APIGeoService.departement_name(data['department'])}"] + else + [rnf_id, nil, nil, nil, nil] + end + end end diff --git a/app/models/types_de_champ/rnf_type_de_champ.rb b/app/models/types_de_champ/rnf_type_de_champ.rb index ce3b24c9c..a5a796342 100644 --- a/app/models/types_de_champ/rnf_type_de_champ.rb +++ b/app/models/types_de_champ/rnf_type_de_champ.rb @@ -1,2 +1,5 @@ class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp + def libelle_for_export(index) + [libelle, "#{libelle} (Nom)", "#{libelle} (Adresse)", "#{libelle} (Code insee Ville)", "#{libelle} (Département)"][index] + end end diff --git a/spec/models/champs/rnf_champ_spec.rb b/spec/models/champs/rnf_champ_spec.rb index 22c414f93..865fec322 100644 --- a/spec/models/champs/rnf_champ_spec.rb +++ b/spec/models/champs/rnf_champ_spec.rb @@ -73,4 +73,11 @@ describe Champs::RNFChamp, type: :model do } end end + + describe 'for_export' do + let(:champ) { build(:champ_rnf, external_id:, data: JSON.parse(body)) } + it do + expect(champ.for_export).to eq(['075-FDD-00003-01', 'Fondation SFR', '16 Rue du Général de Boissieu 75015 Paris', '75115', '75 - Paris']) + end + end end diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index 0cdc536ff..cdf42b2c8 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -92,6 +92,10 @@ describe ProcedureExportService do "cojo", "expression_reguliere", "rnf", + "rnf (Nom)", + "rnf (Adresse)", + "rnf (Code insee Ville)", + "rnf (Département)", "engagement_juridique" ] end @@ -221,6 +225,10 @@ describe ProcedureExportService do "cojo", "expression_reguliere", "rnf", + "rnf (Nom)", + "rnf (Adresse)", + "rnf (Code insee Ville)", + "rnf (Département)", "engagement_juridique" ] end @@ -318,6 +326,10 @@ describe ProcedureExportService do "cojo", "expression_reguliere", "rnf", + "rnf (Nom)", + "rnf (Adresse)", + "rnf (Code insee Ville)", + "rnf (Département)", "engagement_juridique" ] end