récupère les infos d'établissement avec infos non diffusables

This commit is contained in:
Christophe Robillard 2020-03-04 17:12:50 +01:00 committed by GitHub Action
parent c311a0c95e
commit 91abcd7792
8 changed files with 80 additions and 5 deletions

View file

@ -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

View file

@ -24,7 +24,8 @@ class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter
:siret,
:siege_social,
:naf,
:libelle_naf
:libelle_naf,
:diffusable_commercialement
]
end

View file

@ -0,0 +1,5 @@
class AddDiffusableCommercialementToEtablissements < ActiveRecord::Migration[5.2]
def change
add_column :etablissements, :diffusable_commercialement, :boolean
end
end

View file

@ -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

View file

@ -26,7 +26,7 @@
"code": null,
"value": null
},
"diffusable_commercialement": null,
"diffusable_commercialement": true,
"adresse": {
"l1": "OCTO TECHNOLOGY",
"l2": null,

View file

@ -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
}

View file

@ -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

View file

@ -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 }