From 91abcd77928147780e17fa354e6b3e565a7d6082 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 4 Mar 2020 17:12:50 +0100 Subject: [PATCH] =?UTF-8?q?r=C3=A9cup=C3=A8re=20les=20infos=20d'=C3=A9tabl?= =?UTF-8?q?issement=20avec=20infos=20non=20diffusables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/api_entreprise/api.rb | 1 + .../api_entreprise/etablissement_adapter.rb | 3 +- ...sable_commercialement_to_etablissements.rb | 5 ++ db/schema.rb | 3 +- .../files/api_entreprise/etablissements.json | 2 +- .../etablissements_private.json | 49 +++++++++++++++++++ spec/lib/api_entreprise/api_spec.rb | 2 +- .../etablissement_adapter_spec.rb | 20 +++++++- 8 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20200304155418_add_diffusable_commercialement_to_etablissements.rb create mode 100644 spec/fixtures/files/api_entreprise/etablissements_private.json diff --git a/app/lib/api_entreprise/api.rb b/app/lib/api_entreprise/api.rb index 69304366a..af5b6acef 100644 --- a/app/lib/api_entreprise/api.rb +++ b/app/lib/api_entreprise/api.rb @@ -62,6 +62,7 @@ class ApiEntreprise::API context: "demarches-simplifiees.fr", recipient: siret_or_siren, object: "procedure_id: #{procedure_id}", + non_diffusables: true, token: token } end diff --git a/app/lib/api_entreprise/etablissement_adapter.rb b/app/lib/api_entreprise/etablissement_adapter.rb index 58f63c689..7e9139957 100644 --- a/app/lib/api_entreprise/etablissement_adapter.rb +++ b/app/lib/api_entreprise/etablissement_adapter.rb @@ -24,7 +24,8 @@ class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter :siret, :siege_social, :naf, - :libelle_naf + :libelle_naf, + :diffusable_commercialement ] end diff --git a/db/migrate/20200304155418_add_diffusable_commercialement_to_etablissements.rb b/db/migrate/20200304155418_add_diffusable_commercialement_to_etablissements.rb new file mode 100644 index 000000000..9be80c571 --- /dev/null +++ b/db/migrate/20200304155418_add_diffusable_commercialement_to_etablissements.rb @@ -0,0 +1,5 @@ +class AddDiffusableCommercialementToEtablissements < ActiveRecord::Migration[5.2] + def change + add_column :etablissements, :diffusable_commercialement, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 557bf1d0e..fe75b1601 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_02_27_100001) do +ActiveRecord::Schema.define(version: 2020_03_04_155418) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -304,6 +304,7 @@ ActiveRecord::Schema.define(version: 2020_02_27_100001) do t.date "association_date_publication" t.datetime "created_at" t.datetime "updated_at" + t.boolean "diffusable_commercialement" t.index ["dossier_id"], name: "index_etablissements_on_dossier_id" end diff --git a/spec/fixtures/files/api_entreprise/etablissements.json b/spec/fixtures/files/api_entreprise/etablissements.json index 835a18bf1..aa5aa7603 100644 --- a/spec/fixtures/files/api_entreprise/etablissements.json +++ b/spec/fixtures/files/api_entreprise/etablissements.json @@ -26,7 +26,7 @@ "code": null, "value": null }, - "diffusable_commercialement": null, + "diffusable_commercialement": true, "adresse": { "l1": "OCTO TECHNOLOGY", "l2": null, diff --git a/spec/fixtures/files/api_entreprise/etablissements_private.json b/spec/fixtures/files/api_entreprise/etablissements_private.json new file mode 100644 index 000000000..e2d58cf04 --- /dev/null +++ b/spec/fixtures/files/api_entreprise/etablissements_private.json @@ -0,0 +1,49 @@ +{ + "etablissement": { + "siege_social": true, + "siret": "41816609600051", + "naf": "6202A", + "libelle_naf": "Conseil en systèmes et logiciels informatiques", + "date_mise_a_jour": 1449183600, + "tranche_effectif_salarie_etablissement": { + "de": 200, + "a": 249, + "code": "31", + "date_reference": "2014", + "intitule": "200 à 249 salariés" + }, + "date_creation_etablissement": 1108594800, + "enseigne": null, + "region_implantation": { + "code": "11", + "value": "Île-de-France" + }, + "commune_implantation": { + "code": "75108", + "value": "PARIS 8" + }, + "pays_implantation": { + "code": null, + "value": null + }, + "diffusable_commercialement": false, + "adresse": { + "l1": "OCTO TECHNOLOGY", + "l2": null, + "l3": null, + "l4": "50 AVENUE DES CHAMPS ELYSEES", + "l5": null, + "l6": "75008 PARIS", + "l7": "FRANCE", + "numero_voie": "50", + "type_voie": "AV", + "nom_voie": "DES CHAMPS ELYSEES", + "complement_adresse": "complement_adresse", + "code_postal": "75008", + "localite": "PARIS 8", + "code_insee_localite": "75108", + "cedex": null + } + }, + "gateway_error": false +} diff --git a/spec/lib/api_entreprise/api_spec.rb b/spec/lib/api_entreprise/api_spec.rb index e4453ad99..d247e0f37 100644 --- a/spec/lib/api_entreprise/api_spec.rb +++ b/spec/lib/api_entreprise/api_spec.rb @@ -55,7 +55,7 @@ describe ApiEntreprise::API do describe '.etablissement' do subject { described_class.etablissement(siret, procedure_id) } before do - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) + stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*non_diffusables=true&.*token=/) .to_return(status: status, body: body) end diff --git a/spec/lib/api_entreprise/etablissement_adapter_spec.rb b/spec/lib/api_entreprise/etablissement_adapter_spec.rb index 86646148f..ba1876a5e 100644 --- a/spec/lib/api_entreprise/etablissement_adapter_spec.rb +++ b/spec/lib/api_entreprise/etablissement_adapter_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe ApiEntreprise::EtablissementAdapter do let(:procedure_id) { 33 } - context 'SIRET valide' do + context 'SIRET valide avec infos diffusables' do let(:siret) { '41816609600051' } subject { described_class.new(siret, procedure_id).to_params } @@ -33,6 +33,10 @@ describe ApiEntreprise::EtablissementAdapter do expect(subject[:libelle_naf]).to eq('Conseil en systèmes et logiciels informatiques') end + it 'L\'entreprise contient bien un diffusable_commercialement qui vaut true' do + expect(subject[:diffusable_commercialement]).to eq(true) + end + context 'Concaténation lignes adresse' do it 'L\'entreprise contient bien une adresse sur plusieurs lignes' do expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE") @@ -70,6 +74,20 @@ describe ApiEntreprise::EtablissementAdapter do end end + context 'SIRET valide avec infos non diffusables' do + let(:siret) { '41816609600051' } + subject { described_class.new(siret, procedure_id).to_params } + + before do + stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) + .to_return(body: File.read('spec/fixtures/files/api_entreprise/etablissements_private.json', status: 200)) + end + + it 'L\'entreprise contient bien un diffusable_commercialement qui vaut false' do + expect(subject[:diffusable_commercialement]).to eq(false) + end + end + context 'when siret is not found' do let(:bad_siret) { 11_111_111_111_111 } subject { described_class.new(bad_siret, 12).to_params }