Fix api education wrong data type
This commit is contained in:
parent
2802269531
commit
44ebd0e8a5
3 changed files with 110 additions and 0 deletions
|
@ -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
|
||||
|
|
91
spec/fixtures/files/api_education/annuaire_education_bug.json
vendored
Normal file
91
spec/fixtures/files/api_education/annuaire_education_bug.json
vendored
Normal file
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue