send service siret as recipient
This commit is contained in:
parent
9bd6cea38d
commit
619dfd5553
2 changed files with 25 additions and 1 deletions
|
@ -91,6 +91,10 @@ class APIEntreprise::API
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def recipient
|
||||||
|
@procedure&.service && @procedure.service.siret.presence || ENV.fetch('API_ENTREPRISE_DEFAULT_SIRET')
|
||||||
|
end
|
||||||
|
|
||||||
def call_with_siret(resource_name, siret_or_siren, user_id: nil)
|
def call_with_siret(resource_name, siret_or_siren, user_id: nil)
|
||||||
url = make_url(resource_name, siret_or_siren)
|
url = make_url(resource_name, siret_or_siren)
|
||||||
|
|
||||||
|
@ -157,7 +161,7 @@ class APIEntreprise::API
|
||||||
def base_params
|
def base_params
|
||||||
{
|
{
|
||||||
context: APPLICATION_NAME,
|
context: APPLICATION_NAME,
|
||||||
recipient: ENV.fetch('API_ENTREPRISE_DEFAULT_SIRET'),
|
recipient: recipient,
|
||||||
non_diffusables: true
|
non_diffusables: true
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,6 +81,26 @@ describe APIEntreprise::API do
|
||||||
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a service without siret' do
|
||||||
|
let(:procedure) { create(:procedure, :with_service) }
|
||||||
|
let(:dinum_siret) { "13002526500013" }
|
||||||
|
it 'send default recipient' do
|
||||||
|
ENV["API_ENTREPRISE_DEFAULT_SIRET"] = dinum_siret
|
||||||
|
procedure.service.siret = nil
|
||||||
|
procedure.service.save(validate: false)
|
||||||
|
subject
|
||||||
|
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/).with(query: hash_including({ recipient: dinum_siret }))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a service with siret' do
|
||||||
|
let(:procedure) { create(:procedure, :with_service) }
|
||||||
|
it 'send default recipient' do
|
||||||
|
subject
|
||||||
|
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/).with(query: hash_including({ recipient: procedure.service.siret }))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue