diff --git a/app/lib/api_education/annuaire_education_adapter.rb b/app/lib/api_education/annuaire_education_adapter.rb index 161317d69..492f274d9 100644 --- a/app/lib/api_education/annuaire_education_adapter.rb +++ b/app/lib/api_education/annuaire_education_adapter.rb @@ -15,6 +15,13 @@ class APIEducation::AnnuaireEducationAdapter record = data_source[:records].first if record.present? properties = record[:fields].merge({ geometry: record[:geometry] }).deep_stringify_keys + # API sends numbers as strings sometime. Try to parse. + if properties['code_type_contrat_prive'].is_a? String + code = properties['code_type_contrat_prive'].to_i + if code.to_s == properties['code_type_contrat_prive'] + properties['code_type_contrat_prive'] = code + end + end if schemer.valid?(properties) properties else diff --git a/app/models/concerns/procedure_stats_concern.rb b/app/models/concerns/procedure_stats_concern.rb index a98fe4e23..6c8414e8c 100644 --- a/app/models/concerns/procedure_stats_concern.rb +++ b/app/models/concerns/procedure_stats_concern.rb @@ -31,7 +31,7 @@ module ProcedureStatsConcern def stats_termines_by_week Rails.cache.fetch("#{cache_key_with_version}/stats_termines_by_week", expires_in: 12.hours) do now = Time.zone.now - chart_data = dossiers.joins(:traitements) + chart_data = dossiers.includes(:traitements) .state_termine .where(traitements: { processed_at: (now.beginning_of_week - 6.months)..now.end_of_week }) diff --git a/spec/fixtures/files/api_education/annuaire_education_bug.json b/spec/fixtures/files/api_education/annuaire_education_bug.json new file mode 100644 index 000000000..3bf23e897 --- /dev/null +++ b/spec/fixtures/files/api_education/annuaire_education_bug.json @@ -0,0 +1,91 @@ +{ + "nhits": 1, + "parameters": { + "dataset": "fr-en-annuaire-education", + "q": "0050009H", + "timezone": "UTC", + "rows": 1, + "start": 0, + "format": "json" + }, + "records": [ + { + "datasetid": "fr-en-annuaire-education", + "recordid": "0fd6a58dc6c7e5346e3bd62ada6216f476ebeeac", + "fields": { + "section_arts": "0", + "lycee_agricole": "0", + "apprentissage": "1", + "voie_generale": "0", + "ministere_tutelle": "MINISTERE DE L'EDUCATION NATIONALE", + "statut_public_prive": "Public", + "libelle_region": "Provence-Alpes-Côte d'Azur", + "telephone": "04 92 56 56 10", + "date_maj_ligne": "2021-01-12", + "hebergement": 1, + "libelle_nature": "LYCEE PROFESSIONNEL", + "lycee_militaire": "0", + "section_sport": "0", + "voie_technologique": "0", + "fiche_onisep": "http://geolocalisation.onisep.fr/05-hautes-alpes/gap/lycee/lycee-professionnel-sevigne.html", + "etat": "OUVERT", + "web": "www.lyc-sevigne.ac-aix-marseille.fr", + "rpi_concentre": 0, + "identifiant_de_l_etablissement": "0050009H", + "code_region": "93", + "ulis": 1, + "restauration": 1, + "code_departement": "05", + "date_ouverture": "1965-05-01", + "voie_professionnelle": "1", + "greta": "1", + "coordy_origine": 6389542.2, + "siren_siret": "19050009000013", + "mail": "ce.0050009H@ac-aix-marseille.fr", + "type_contrat_prive": "SANS OBJET", + "nom_commune": "Gap", + "segpa": "0", + "adresse_3": "05000 GAP", + "fax": "04 92 56 56 30", + "type_etablissement": "Lycée", + "nombre_d_eleves": 451, + "libelle_zone_animation_pedagogique": "GAP", + "code_commune": "05061", + "latitude": 44.562179100043984, + "section_theatre": "0", + "section_internationale": "0", + "post_bac": "1", + "precision_localisation": "Numéro de rue", + "multi_uai": 0, + "code_postal": "05000", + "libelle_departement": "Hautes-Alpes", + "section_cinema": "0", + "section_europeenne": "1", + "libelle_academie": "Aix-Marseille", + "longitude": 6.0746303437466915, + "code_zone_animation_pedagogique": "02104", + "code_academie": "02", + "lycee_des_metiers": "1", + "epsg_origine": "EPSG:2154", + "adresse_1": "6 rue Jean Macé", + "nom_etablissement": "Lycée professionnel Sévigné", + "pial": "0050009H", + "code_nature": 320, + "position": [ + 44.562179100043984, + 6.0746303437466915 + ], + "code_type_contrat_prive": "99", + "coordx_origine": 944110.8 + }, + "geometry": { + "type": "Point", + "coordinates": [ + 6.0746303437466915, + 44.562179100043984 + ] + }, + "record_timestamp": "2021-01-12T18:03:00+00:00" + } + ] +} diff --git a/spec/lib/api_education/annuaire_education_adapter_spec.rb b/spec/lib/api_education/annuaire_education_adapter_spec.rb index fe5fa5024..d47e9c29c 100644 --- a/spec/lib/api_education/annuaire_education_adapter_spec.rb +++ b/spec/lib/api_education/annuaire_education_adapter_spec.rb @@ -15,6 +15,18 @@ describe APIEducation::AnnuaireEducationAdapter do it '#to_params return vaid hash' do expect(subject).to be_an_instance_of(Hash) expect(subject['identifiant_de_l_etablissement']).to eq(search_term) + expect(subject['code_type_contrat_prive']).to eq(99) + end + end + + context "when responds with code_type_contrat_prive as string" do + let(:body) { File.read('spec/fixtures/files/api_education/annuaire_education_bug.json') } + let(:status) { 200 } + + it '#to_params return vaid hash' do + expect(subject).to be_an_instance_of(Hash) + expect(subject['identifiant_de_l_etablissement']).to eq(search_term) + expect(subject['code_type_contrat_prive']).to eq(99) end end