feat(service): prefill type organisme from API Entreprise

This commit is contained in:
Colin Darie 2024-10-15 18:26:19 +02:00
parent 68cca71318
commit 065d380b70
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
10 changed files with 635 additions and 15 deletions

View file

@ -116,8 +116,14 @@ module Administrateurs
@service.validate @service.validate
if !@service.errors.include?(:siret) if !@service.errors.include?(:siret)
result = @service.prefill_from_siret prefilled = case @service.prefill_from_siret
prefilled = result.success? ? :success : :failure in [Dry::Monads::Result::Success, Dry::Monads::Result::Success]
:success
in [Dry::Monads::Result::Failure, Dry::Monads::Result::Success] | [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]
:partial
else
:failure
end
end end
siret_errors = @service.errors.where(:siret) siret_errors = @service.errors.where(:siret)

View file

@ -5,9 +5,9 @@ module PrefillableFromServicePublicConcern
included do included do
def prefill_from_siret def prefill_from_siret
result = AnnuaireServicePublicService.new.(siret:) result_sp = AnnuaireServicePublicService.new.(siret:)
# TODO: get organisme, … from API Entreprise
case result case result_sp
in Dry::Monads::Success(data) in Dry::Monads::Success(data)
self.nom = data[:nom] if nom.blank? self.nom = data[:nom] if nom.blank?
self.email = data[:adresse_courriel] if email.blank? self.email = data[:adresse_courriel] if email.blank?
@ -18,7 +18,19 @@ module PrefillableFromServicePublicConcern
# NOOP # NOOP
end end
result result_api_ent = APIRechercheEntreprisesService.new.call(siret:)
case result_api_ent
in Dry::Monads::Success(data)
self.type_organisme = detect_type_organisme(data) if type_organisme.blank?
# some services (etablissements, …) are not in service public, so we also try to prefill them with API Entreprise
self.nom = data[:nom_complet] if nom.blank?
self.adresse = data.dig(:siege, :geo_adresse) if adresse.blank?
else
# NOOP
end
[result_sp, result_api_ent]
end end
private private
@ -45,6 +57,23 @@ module PrefillableFromServicePublicConcern
end.join("\n") end.join("\n")
end end
def detect_type_organisme(data)
# Cf https://recherche-entreprises.api.gouv.fr/docs/#tag/Recherche-textuelle/paths/~1search/get
type = if data.dig(:complements, :collectivite_territoriale).present?
:collectivite_territoriale
elsif data.dig(:complements, :est_association)
:association
elsif data[:section_activite_principale] == "P"
:etablissement_enseignement
elsif data[:nom_complet].match?(/MINISTERE|MINISTERIEL/)
:administration_centrale
else # we can't differentiate between operateur d'état, administration centrale and service déconcentré de l'état, set the most frequent
:service_deconcentre_de_l_etat
end
Service.type_organismes[type]
end
def format_time(str_time) def format_time(str_time)
Time.zone Time.zone
.parse(str_time) .parse(str_time)

View file

@ -11,7 +11,10 @@
.fr-mb-2w .fr-mb-2w
- if local_assigns[:prefilled] == :success - if local_assigns[:prefilled] == :success
%p.fr-info-text Génial ! Les informations du service ont été préremplies ci-dessous. Vérifiez-les et complétez-les le cas échéant. %p.fr-info-text Génial ! La plupart des informations du service ont été préremplies ci-dessous. Vérifiez-les et complétez-les le cas échéant.
- elsif local_assigns[:prefilled] == :partial
%p.fr-info-text
Nous avons prérempli certaines informations correspondant à ce SIRET. Complétez les autres manuellement.
- elsif local_assigns[:prefilled] == :failure - elsif local_assigns[:prefilled] == :failure
%p.fr-error-text %p.fr-error-text
Une erreur a empêché le préremplissage des informations. Une erreur a empêché le préremplissage des informations.
@ -24,8 +27,9 @@
.fr-input-group .fr-input-group
= f.label :type_organisme, class: "fr-label" do = f.label :type_organisme, class: "fr-label" do
Type dorganisme Type dorganisme
= render EditableChamp::AsteriskMandatoryComponent.new
= f.select :type_organisme, Service.type_organismes.keys.map { |key| [ I18n.t("type_organisme.#{key}"), key] }, {}, class: 'fr-select' = f.select :type_organisme, Service.type_organismes.keys.map { |key| [ I18n.t("type_organisme.#{key}"), key] }, { include_blank: true }, { class: "fr-select" , required: true }
= render Dsfr::CalloutComponent.new(title: "Informations de contact") do |c| = render Dsfr::CalloutComponent.new(title: "Informations de contact") do |c|
- c.with_body do - c.with_body do

View file

@ -31,7 +31,7 @@ describe Administrateurs::ServicesController, type: :controller do
end end
end end
context 'when attempting to prefilling from unknown SIRET' do context 'when attempting to prefilling from invalid SIRET' do
let(:xhr) { true } let(:xhr) { true }
let(:params) do let(:params) do
{ {
@ -41,11 +41,29 @@ describe Administrateurs::ServicesController, type: :controller do
end end
it "render an error" do it "render an error" do
VCR.use_cassette('annuaire_service_public_failure_20004021000000') do subject
expect(response.body).to include('turbo-stream')
expect(assigns[:service].nom).to be_nil
expect(assigns[:service].errors.key?(:siret)).to be_present
end
end
context 'when attempting to prefilling from not service public SIRET' do
let(:xhr) { true }
let(:params) do
{
procedure_id: procedure.id,
service: { siret: "41816609600051" }
}
end
it "render partial information" do
VCR.use_cassette('annuaire_service_public_success_41816609600051') do
subject subject
expect(response.body).to include('turbo-stream') expect(response.body).to include('turbo-stream')
expect(assigns[:service].nom).to be_nil expect(assigns[:service].nom).to eq("OCTO-TECHNOLOGY")
expect(assigns[:service].errors.key?(:siret)).to be_present expect(assigns[:service].horaires).to be_nil
expect(assigns[:service].errors.key?(:siret)).not_to be_present
end end
end end
end end

View file

@ -0,0 +1,116 @@
---
http_interactions:
- request:
method: get
uri: https://api-lannuaire.service-public.fr/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records?where=siret:11004601800013
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- openresty
Date:
- Tue, 15 Oct 2024 16:24:17 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '33'
X-Ratelimit-Remaining:
- '999918'
X-Ratelimit-Limit:
- '1000000'
X-Ratelimit-Reset:
- '2024-10-16 00:00:00+00:00'
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Vary:
- Accept-Language, Cookie, Host
Content-Language:
- fr-fr
Access-Control-Allow-Origin:
- "*"
Access-Control-Allow-Methods:
- POST, GET, OPTIONS
Access-Control-Max-Age:
- '1000'
Access-Control-Allow-Headers:
- Authorization, X-Requested-With, Origin, ODS-API-Analytics-App, ODS-API-Analytics-Embed-Type,
ODS-API-Analytics-Embed-Referrer, ODS-Widgets-Version, Accept
Access-Control-Expose-Headers:
- ODS-Explore-API-Deprecation, Link, X-RateLimit-Remaining, X-RateLimit-Limit,
X-RateLimit-Reset, X-RateLimit-dataset-Remaining, X-RateLimit-dataset-Limit,
X-RateLimit-dataset-Reset
Strict-Transport-Security:
- max-age=31536000
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
Referrer-Policy:
- strict-origin-when-cross-origin
Permissions-Policy:
- midi=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()
Content-Security-Policy:
- upgrade-insecure-requests;
X-Ua-Compatible:
- IE=edge
body:
encoding: ASCII-8BIT
string: '{"total_count": 0, "results": []}'
recorded_at: Tue, 15 Oct 2024 16:24:17 GMT
- request:
method: get
uri: https://recherche-entreprises.api.gouv.fr/search?q=11004601800013
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- nginx/1.27.1
Date:
- Tue, 15 Oct 2024 16:24:17 GMT
Content-Type:
- application/json
Content-Length:
- '3289'
Vary:
- Accept-Encoding
- Accept-Encoding
Annuaire-Entreprises-Instance-Number:
- '02'
X-Frame-Options:
- DENY
X-Content-Type-Options:
- nosniff
Strict-Transport-Security:
- max-age=31536000
X-Xss-Protection:
- 1; mode=block
Access-Control-Allow-Headers:
- Content-Type
Access-Control-Allow-Origin:
- "*"
body:
encoding: ASCII-8BIT
string: !binary |-
eyJyZXN1bHRzIjpbeyJzaXJlbiI6IjExMDA0NjAxOCIsIm5vbV9jb21wbGV0IjoiTUlOSVNURVJFIERFIExBIENVTFRVUkUiLCJub21fcmFpc29uX3NvY2lhbGUiOiJNSU5JU1RFUkUgREUgTEEgQ1VMVFVSRSIsInNpZ2xlIjpudWxsLCJub21icmVfZXRhYmxpc3NlbWVudHMiOjMsIm5vbWJyZV9ldGFibGlzc2VtZW50c19vdXZlcnRzIjoxLCJzaWVnZSI6eyJhY3Rpdml0ZV9wcmluY2lwYWxlIjoiODQuMTFaIiwiYWN0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2VtZW50IjoiTyIsInRyYW5jaGVfZWZmZWN0aWZfc2FsYXJpZSI6IjIyIn1dLCJmaW5hbmNlcyI6bnVsbCwiY29tcGxlbWVudHMiOnsiY29sbGVjdGl2aXRlX3RlcnJpdG9yaWFsZSI6bnVsbCwiY29udmVudGlvbl9jb2xsZWN0aXZlX3JlbnNlaWduZWUiOmZhbHNlLCJsaXN0ZV9pZGNjIjpudWxsLCJlZ2Fwcm9fcmVuc2VpZ25lZSI6ZmFsc2UsImVzdF9hc3NvY2lhdGlvbiI6ZmFsc2UsImVzdF9iaW8iOmZhbHNlLCJlc3RfZW50cmVwcmVuZXVyX2luZGl2aWR1ZWwiOmZhbHNlLCJlc3RfZW50cmVwcmVuZXVyX3NwZWN0YWNsZSI6ZmFsc2UsImVzdF9lc3MiOmZhbHNlLCJlc3RfZmluZXNzIjpmYWxzZSwiZXN0X29yZ2FuaXNtZV9mb3JtYXRpb24iOnRydWUsImVzdF9xdWFsaW9waSI6ZmFsc2UsImxpc3RlX2lkX29yZ2FuaXNtZV9mb3JtYXRpb24iOlsiMTE3NTU2MDg5NzUiXSwiZXN0X3JnZSI6ZmFsc2UsImVzdF9zZXJ2aWNlX3B1YmxpYyI6dHJ1ZSwiZXN0X3NpYWUiOmZhbHNlLCJlc3Rfc29jaWV0ZV9taXNzaW9uIjpmYWxzZSwiZXN0X3VhaSI6ZmFsc2UsImlkZW50aWZpYW50X2Fzc29jaWF0aW9uIjpudWxsLCJzdGF0dXRfZW50cmVwcmVuZXVyX3NwZWN0YWNsZSI6bnVsbCwidHlwZV9zaWFlIjpudWxsfX1dLCJ0b3RhbF9yZXN1bHRzIjoxLCJwYWdlIjoxLCJwZXJfcGFnZSI6MTAsInRvdGFsX3BhZ2VzIjoxfQ==
recorded_at: Tue, 15 Oct 2024 16:24:17 GMT
recorded_with: VCR 6.2.0

View file

@ -0,0 +1,120 @@
---
http_interactions:
- request:
method: get
uri: https://api-lannuaire.service-public.fr/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records?where=siret:19750664500013
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- openresty
Date:
- Tue, 15 Oct 2024 14:57:11 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '33'
X-Ratelimit-Remaining:
- '999997'
X-Ratelimit-Limit:
- '1000000'
X-Ratelimit-Reset:
- '2024-10-16 00:00:00+00:00'
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Vary:
- Accept-Language, Cookie, Host
Content-Language:
- fr-fr
Access-Control-Allow-Origin:
- "*"
Access-Control-Allow-Methods:
- POST, GET, OPTIONS
Access-Control-Max-Age:
- '1000'
Access-Control-Allow-Headers:
- Authorization, X-Requested-With, Origin, ODS-API-Analytics-App, ODS-API-Analytics-Embed-Type,
ODS-API-Analytics-Embed-Referrer, ODS-Widgets-Version, Accept
Access-Control-Expose-Headers:
- ODS-Explore-API-Deprecation, Link, X-RateLimit-Remaining, X-RateLimit-Limit,
X-RateLimit-Reset, X-RateLimit-dataset-Remaining, X-RateLimit-dataset-Limit,
X-RateLimit-dataset-Reset
Strict-Transport-Security:
- max-age=31536000
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
Referrer-Policy:
- strict-origin-when-cross-origin
Permissions-Policy:
- midi=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()
Content-Security-Policy:
- upgrade-insecure-requests;
X-Ua-Compatible:
- IE=edge
body:
encoding: ASCII-8BIT
string: '{"total_count": 0, "results": []}'
recorded_at: Tue, 15 Oct 2024 14:57:11 GMT
- request:
method: get
uri: https://recherche-entreprises.api.gouv.fr/search?q=19750664500013
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- nginx/1.27.1
Date:
- Tue, 15 Oct 2024 14:57:12 GMT
Content-Type:
- application/json
Content-Length:
- '3310'
Vary:
- Accept-Encoding
- Accept-Encoding
Annuaire-Entreprises-Instance-Number:
- '02'
X-Frame-Options:
- DENY
X-Content-Type-Options:
- nosniff
Strict-Transport-Security:
- max-age=31536000
X-Xss-Protection:
- 1; mode=block
Access-Control-Allow-Headers:
- Content-Type
Access-Control-Allow-Origin:
- "*"
body:
encoding: ASCII-8BIT
string: '{"results":[{"siren":"197506645","nom_complet":"LYCEE GENERAL ET TECHNOLOGIQUE
RACINE","nom_raison_sociale":"LYCEE GENERAL ET TECHNOLOGIQUE RACINE","sigle":null,"nombre_etablissements":1,"nombre_etablissements_ouverts":1,"siege":{"activite_principale":"85.31Z","activite_principale_registre_metier":null,"annee_tranche_effectif_salarie":"2022","adresse":"20
RUE DU ROCHER 75008 PARIS","caractere_employeur":"N","cedex":null,"code_pays_etranger":null,"code_postal":"75008","commune":"75108","complement_adresse":null,"coordonnees":"48.876451,2.3223","date_creation":"1983-03-01","date_debut_activite":"2008-01-01","date_fermeture":null,"date_mise_a_jour":null,"date_mise_a_jour_insee":"2024-03-30T03:25:45","departement":"75","distribution_speciale":null,"epci":"200054781","est_siege":true,"etat_administratif":"A","geo_adresse":"20
Rue du Rocher 75008 Paris","geo_id":"75108_8291_00020","indice_repetition":null,"latitude":"48.876451","libelle_cedex":null,"libelle_commune":"PARIS","libelle_commune_etranger":null,"libelle_pays_etranger":null,"libelle_voie":"DU
ROCHER","liste_enseignes":null,"liste_finess":null,"liste_id_bio":null,"liste_idcc":["9999"],"liste_id_organisme_formation":null,"liste_rge":null,"liste_uai":["0750664P"],"longitude":"2.3223","nom_commercial":null,"numero_voie":"20","region":"11","siret":"19750664500013","statut_diffusion_etablissement":"O","tranche_effectif_salarie":"22","type_voie":"RUE"},"activite_principale":"85.31Z","categorie_entreprise":"PME","caractere_employeur":null,"annee_categorie_entreprise":"2022","date_creation":"1965-05-01","date_fermeture":null,"date_mise_a_jour":"2024-10-14T15:00:03","date_mise_a_jour_insee":"2024-03-22T14:26:06","date_mise_a_jour_rne":null,"dirigeants":[],"etat_administratif":"A","nature_juridique":"7331","section_activite_principale":"P","tranche_effectif_salarie":"22","annee_tranche_effectif_salarie":"2022","statut_diffusion":"O","matching_etablissements":[{"activite_principale":"85.31Z","ancien_siege":false,"annee_tranche_effectif_salarie":"2022","adresse":"20
RUE DU ROCHER 75008 PARIS","caractere_employeur":"N","code_postal":"75008","commune":"75108","date_creation":"1983-03-01","date_debut_activite":"2008-01-01","date_fermeture":null,"epci":"200054781","est_siege":true,"etat_administratif":"A","geo_id":"75108_8291_00020","latitude":"48.876451","libelle_commune":"PARIS","liste_enseignes":null,"liste_finess":null,"liste_id_bio":null,"liste_idcc":["9999"],"liste_id_organisme_formation":null,"liste_rge":null,"liste_uai":["0750664P"],"longitude":"2.3223","nom_commercial":null,"region":"11","siret":"19750664500013","statut_diffusion_etablissement":"O","tranche_effectif_salarie":"22"}],"finances":null,"complements":{"collectivite_territoriale":null,"convention_collective_renseignee":true,"liste_idcc":["9999"],"egapro_renseignee":false,"est_association":false,"est_bio":false,"est_entrepreneur_individuel":false,"est_entrepreneur_spectacle":false,"est_ess":false,"est_finess":false,"est_organisme_formation":false,"est_qualiopi":false,"liste_id_organisme_formation":null,"est_rge":false,"est_service_public":true,"est_siae":false,"est_societe_mission":false,"est_uai":true,"identifiant_association":null,"statut_entrepreneur_spectacle":null,"type_siae":null}}],"total_results":1,"page":1,"per_page":10,"total_pages":1}'
recorded_at: Tue, 15 Oct 2024 14:57:11 GMT
recorded_with: VCR 6.2.0

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,122 @@
---
http_interactions:
- request:
method: get
uri: https://api-lannuaire.service-public.fr/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records?where=siret:35600082800018
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- openresty
Date:
- Tue, 15 Oct 2024 16:24:16 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '33'
X-Ratelimit-Remaining:
- '999919'
X-Ratelimit-Limit:
- '1000000'
X-Ratelimit-Reset:
- '2024-10-16 00:00:00+00:00'
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Vary:
- Accept-Language, Cookie, Host
Content-Language:
- fr-fr
Access-Control-Allow-Origin:
- "*"
Access-Control-Allow-Methods:
- POST, GET, OPTIONS
Access-Control-Max-Age:
- '1000'
Access-Control-Allow-Headers:
- Authorization, X-Requested-With, Origin, ODS-API-Analytics-App, ODS-API-Analytics-Embed-Type,
ODS-API-Analytics-Embed-Referrer, ODS-Widgets-Version, Accept
Access-Control-Expose-Headers:
- ODS-Explore-API-Deprecation, Link, X-RateLimit-Remaining, X-RateLimit-Limit,
X-RateLimit-Reset, X-RateLimit-dataset-Remaining, X-RateLimit-dataset-Limit,
X-RateLimit-dataset-Reset
Strict-Transport-Security:
- max-age=31536000
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
Referrer-Policy:
- strict-origin-when-cross-origin
Permissions-Policy:
- midi=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()
Content-Security-Policy:
- upgrade-insecure-requests;
X-Ua-Compatible:
- IE=edge
body:
encoding: ASCII-8BIT
string: '{"total_count": 0, "results": []}'
recorded_at: Tue, 15 Oct 2024 16:24:16 GMT
- request:
method: get
uri: https://recherche-entreprises.api.gouv.fr/search?q=35600082800018
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- nginx/1.27.1
Date:
- Tue, 15 Oct 2024 16:24:16 GMT
Content-Type:
- application/json
Content-Length:
- '3374'
Vary:
- Accept-Encoding
- Accept-Encoding
- Accept-Encoding
Annuaire-Entreprises-Instance-Number:
- '01'
- '02'
X-Frame-Options:
- DENY
X-Content-Type-Options:
- nosniff
Strict-Transport-Security:
- max-age=31536000
X-Xss-Protection:
- 1; mode=block
Access-Control-Allow-Headers:
- Content-Type
Access-Control-Allow-Origin:
- "*"
body:
encoding: ASCII-8BIT
string: '{"results":[{"siren":"356000828","nom_complet":"LA POSTE (REGION RHONE
ALPES)","nom_raison_sociale":"LA POSTE","sigle":null,"nombre_etablissements":2948,"nombre_etablissements_ouverts":0,"siege":{"activite_principale":"53.10Z","activite_principale_registre_metier":null,"annee_tranche_effectif_salarie":null,"adresse":"4
QUAI DU POINT DU JOUR 92100 BOULOGNE-BILLANCOURT","caractere_employeur":"N","cedex":null,"code_pays_etranger":null,"code_postal":"92100","commune":"92012","complement_adresse":null,"coordonnees":"48.832893,2.259972","date_creation":"1991-01-01","date_debut_activite":"2011-12-31","date_fermeture":"2011-12-31","date_mise_a_jour":null,"date_mise_a_jour_insee":"2024-03-22T15:40:57","departement":"92","distribution_speciale":null,"epci":"200054781","est_siege":true,"etat_administratif":"F","geo_adresse":"4
Quai du Point du Jour 92100 Boulogne-Billancourt","geo_id":"92012_7231_00004","indice_repetition":null,"latitude":"48.832893","libelle_cedex":null,"libelle_commune":"BOULOGNE-BILLANCOURT","libelle_commune_etranger":null,"libelle_pays_etranger":null,"libelle_voie":"DU
POINT DU JOUR","liste_enseignes":null,"liste_finess":null,"liste_id_bio":null,"liste_idcc":null,"liste_id_organisme_formation":null,"liste_rge":null,"liste_uai":null,"longitude":"2.259972","nom_commercial":null,"numero_voie":"4","region":"11","siret":"35600082800018","statut_diffusion_etablissement":"O","tranche_effectif_salarie":null,"type_voie":"QUAI"},"activite_principale":"53.10Z","categorie_entreprise":null,"caractere_employeur":null,"annee_categorie_entreprise":null,"date_creation":"1991-01-01","date_fermeture":"2011-12-31","date_mise_a_jour":"2024-10-14T15:38:40","date_mise_a_jour_insee":"2024-03-22T14:26:06","date_mise_a_jour_rne":null,"dirigeants":[],"etat_administratif":"C","nature_juridique":"4130","section_activite_principale":"H","tranche_effectif_salarie":null,"annee_tranche_effectif_salarie":null,"statut_diffusion":"O","matching_etablissements":[{"activite_principale":"53.10Z","ancien_siege":false,"annee_tranche_effectif_salarie":null,"adresse":"4
QUAI DU POINT DU JOUR 92100 BOULOGNE-BILLANCOURT","caractere_employeur":"N","code_postal":"92100","commune":"92012","date_creation":"1991-01-01","date_debut_activite":"2011-12-31","date_fermeture":"2011-12-31","epci":"200054781","est_siege":true,"etat_administratif":"F","geo_id":"92012_7231_00004","latitude":"48.832893","libelle_commune":"BOULOGNE-BILLANCOURT","liste_enseignes":null,"liste_finess":null,"liste_id_bio":null,"liste_idcc":null,"liste_id_organisme_formation":null,"liste_rge":null,"liste_uai":null,"longitude":"2.259972","nom_commercial":null,"region":"11","siret":"35600082800018","statut_diffusion_etablissement":"O","tranche_effectif_salarie":null}],"finances":null,"complements":{"collectivite_territoriale":null,"convention_collective_renseignee":false,"liste_idcc":null,"egapro_renseignee":false,"est_association":false,"est_bio":false,"est_entrepreneur_individuel":false,"est_entrepreneur_spectacle":false,"est_ess":false,"est_finess":false,"est_organisme_formation":false,"est_qualiopi":false,"liste_id_organisme_formation":null,"est_rge":false,"est_service_public":true,"est_siae":false,"est_societe_mission":false,"est_uai":false,"identifiant_association":null,"statut_entrepreneur_spectacle":null,"type_siae":null}}],"total_results":1,"page":1,"per_page":10,"total_pages":1}'
recorded_at: Tue, 15 Oct 2024 16:24:16 GMT
recorded_with: VCR 6.2.0

View file

@ -0,0 +1,119 @@
---
http_interactions:
- request:
method: get
uri: https://recherche-entreprises.api.gouv.fr/search?q=41816609600051
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- nginx/1.27.1
Date:
- Thu, 17 Oct 2024 07:51:06 GMT
Content-Type:
- application/json
Content-Length:
- '3471'
Vary:
- Accept-Encoding
- Accept-Encoding
- Accept-Encoding
Annuaire-Entreprises-Instance-Number:
- '02'
X-Frame-Options:
- DENY
X-Content-Type-Options:
- nosniff
Strict-Transport-Security:
- max-age=31536000
- max-age=31536000
X-Xss-Protection:
- 1; mode=block
- 1; mode=block
Access-Control-Allow-Headers:
- Content-Type
Access-Control-Allow-Origin:
- "*"
body:
encoding: ASCII-8BIT
string: !binary |-
eyJyZXN1bHRzIjpbeyJzaXJlbiI6IjQxODE2NjA5NiIsIm5vbV9jb21wbGV0IjoiT0NUTy1URUNITk9MT0dZIiwibm9tX3JhaXNvbl9zb2NpYWxlIjoiT0NUTy1URUNITk9MT0dZIiwic2lnbGUiOm51bGwsIm5vbWJyZV9ldGFibGlzc2VtZW50cyI6Nywibm9tYnJlX2V0YWJsaXNzZW1lbnRzX291dmVydHMiOjEsInNpZWdlIjp7ImFjdGl2aXRlX3ByaW5jaXBhbGUiOiI2Mi4wMkEiLCJhY3Rpdml0ZV9wcmluY2lwYWxlX3JlZ2lzdHJlX21ldGllciI6bnVsbCwiYW5uZWVfdHJhbmNoZV9lZmZlY3RpZl9zYWxhcmllIjoiMjAyMiIsImFkcmVzc2UiOiIzNCBBVkVOVUUgREUgTCdPUEVSQSA3NTAwMiBQQVJJUyIsImNhcmFjdGVyZV9lbXBsb3lldXIiOiJPIiwiY2VkZXgiOm51bGwsImNvZGVfcGF5c19ldHJhbmdlciI6bnVsbCwiY29kZV9wb3N0YWwiOiI3NTAwMiIsImNvbW11bmUiOiI3NTEwMiIsImNvbXBsZW1lbnRfYWRyZXNzZSI6bnVsbCwiY29vcmRvbm5lZXMiOiI0OC44Njg2NjIsMi4zMzMzODIiLCJkYXRlX2NyZWF0aW9uIjoiMjAxNi0xMS0yOCIsImRhdGVfZGVidXRfYWN0aXZpdGUiOiIyMDE2LTExLTI4IiwiZGF0ZV9mZXJtZXR1cmUiOm51bGwsImRhdGVfbWlzZV9hX2pvdXIiOm51bGwsImRhdGVfbWlzZV9hX2pvdXJfaW5zZWUiOiIyMDI0LTA1LTMxVDA1OjI5OjU4IiwiZGVwYXJ0ZW1lbnQiOiI3NSIsImRpc3RyaWJ1dGlvbl9zcGVjaWFsZSI6bnVsbCwiZXBjaSI6IjIwMDA1NDc4MSI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UsImVzdF9maW5lc3MiOmZhbHNlLCJlc3Rfb3JnYW5pc21lX2Zvcm1hdGlvbiI6dHJ1ZSwiZXN0X3F1YWxpb3BpIjp0cnVlLCJsaXN0ZV9pZF9vcmdhbmlzbWVfZm9ybWF0aW9uIjpbIjExNzU0ODkzNjc1Il0sImVzdF9yZ2UiOmZhbHNlLCJlc3Rfc2VydmljZV9wdWJsaWMiOmZhbHNlLCJlc3Rfc2lhZSI6ZmFsc2UsImVzdF9zb2NpZXRlX21pc3Npb24iOmZhbHNlLCJlc3RfdWFpIjpmYWxzZSwiaWRlbnRpZmlhbnRfYXNzb2NpYXRpb24iOm51bGwsInN0YXR1dF9lbnRyZXByZW5ldXJfc3BlY3RhY2xlIjpudWxsLCJ0eXBlX3NpYWUiOm51bGx9fV0sInRvdGFsX3Jlc3VsdHMiOjEsInBhZ2UiOjEsInBlcl9wYWdlIjoxMCwidG90YWxfcGFnZXMiOjF9
recorded_at: Thu, 17 Oct 2024 07:51:06 GMT
- request:
method: get
uri: https://api-lannuaire.service-public.fr/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records?where=siret:41816609600051
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
response:
status:
code: 200
message: ''
headers:
Server:
- openresty
Date:
- Thu, 17 Oct 2024 07:51:06 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '33'
X-Ratelimit-Remaining:
- '999989'
X-Ratelimit-Limit:
- '1000000'
X-Ratelimit-Reset:
- '2024-10-18 00:00:00+00:00'
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Vary:
- Accept-Language, Cookie, Host
Content-Language:
- fr-fr
Access-Control-Allow-Origin:
- "*"
Access-Control-Allow-Methods:
- POST, GET, OPTIONS
Access-Control-Max-Age:
- '1000'
Access-Control-Allow-Headers:
- Authorization, X-Requested-With, Origin, ODS-API-Analytics-App, ODS-API-Analytics-Embed-Type,
ODS-API-Analytics-Embed-Referrer, ODS-Widgets-Version, Accept
Access-Control-Expose-Headers:
- ODS-Explore-API-Deprecation, Link, X-RateLimit-Remaining, X-RateLimit-Limit,
X-RateLimit-Reset, X-RateLimit-dataset-Remaining, X-RateLimit-dataset-Limit,
X-RateLimit-dataset-Reset
Strict-Transport-Security:
- max-age=31536000
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
Referrer-Policy:
- strict-origin-when-cross-origin
Permissions-Policy:
- midi=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()
Content-Security-Policy:
- upgrade-insecure-requests;
X-Ua-Compatible:
- IE=edge
body:
encoding: ASCII-8BIT
string: '{"total_count": 0, "results": []}'
recorded_at: Thu, 17 Oct 2024 07:51:06 GMT
recorded_with: VCR 6.2.0

View file

@ -9,12 +9,13 @@ RSpec.describe PrefillableFromServicePublicConcern, type: :model do
describe '#prefill_from_siret' do describe '#prefill_from_siret' do
let(:service) { Service.new(siret:) } let(:service) { Service.new(siret:) }
subject { service.prefill_from_siret } subject { service.prefill_from_siret }
context 'when API call is successful' do context 'when API call is successful with collectivite' do
it 'prefills service attributes' do it 'prefills service attributes' do
VCR.use_cassette('annuaire_service_public_success_20004021000060') do VCR.use_cassette('annuaire_service_public_success_20004021000060') do
expect(subject).to be_success expect(subject.all?(&:success?)).to be_truthy
expect(service.nom).to eq("Communauté de communes - Lacs et Gorges du Verdon") expect(service.nom).to eq("Communauté de communes - Lacs et Gorges du Verdon")
expect(service).to be_collectivite_territoriale
expect(service.email).to eq("redacted@email.fr") expect(service.email).to eq("redacted@email.fr")
expect(service.telephone).to eq("04 94 70 00 00") expect(service.telephone).to eq("04 94 70 00 00")
expect(service.horaires).to eq("Lundi au Jeudi : de 8:00 à 12:00 et de 13:30 à 17:30\nVendredi : de 8:00 à 12:00") expect(service.horaires).to eq("Lundi au Jeudi : de 8:00 à 12:00 et de 13:30 à 17:30\nVendredi : de 8:00 à 12:00")
@ -39,7 +40,46 @@ RSpec.describe PrefillableFromServicePublicConcern, type: :model do
let(:siret) { '20004021000000' } let(:siret) { '20004021000000' }
it 'returns a failure result' do it 'returns a failure result' do
VCR.use_cassette('annuaire_service_public_failure_20004021000000') do VCR.use_cassette('annuaire_service_public_failure_20004021000000') do
expect(subject).to be_failure expect(subject.all?(&:failure?)).to be_truthy
end
end
end
context 'when SIRET is enseignement' do
let(:siret) { '19750664500013' }
it 'prefills for enseignement' do
VCR.use_cassette('annuaire_service_public_success_19750664500013') do
expect(subject.one?(&:success?)).to be_truthy
expect(service.nom).to eq("LYCEE GENERAL ET TECHNOLOGIQUE RACINE")
expect(service).to be_etablissement_enseignement
expect(service.adresse).to eq("20 Rue du Rocher 75008 Paris")
expect(service.horaires).to be_nil
end
end
end
context 'when SIRET is a ministere' do
let(:siret) { '11004601800013' }
it 'prefills for administration centrale' do
VCR.use_cassette('annuaire_service_public_success_11004601800013') do
expect(subject.one?(&:success?)).to be_truthy
expect(service.nom).to eq("MINISTERE DE LA CULTURE")
expect(service).to be_administration_centrale
expect(service.adresse).to eq("182 Rue Saint-Honoré 75001 Paris")
expect(service.horaires).to be_nil
end
end
end
context 'when SIRET is La Poste' do
let(:siret) { '35600082800018' }
it 'prefills for administration centrale' do
VCR.use_cassette('annuaire_service_public_success_35600082800018') do
expect(subject.one?(&:success?)).to be_truthy
expect(service.nom).to eq("LA POSTE (REGION RHONE ALPES)")
expect(service).to be_service_deconcentre_de_l_etat
expect(service.adresse).to eq("4 Quai du Point du Jour 92100 Boulogne-Billancourt")
expect(service.horaires).to be_nil
end end
end end
end end