Skip to content

Commit

Permalink
Merge pull request #9326 from demarches-simplifiees/9242-api-entrepri…
Browse files Browse the repository at this point in the history
…se-recipient

send service siret as recipient
  • Loading branch information
krichtof authored Jul 19, 2023
2 parents 4f4e687 + 619dfd5 commit 4862cc2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/lib/api_entreprise/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def current_status

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)
url = make_url(resource_name, siret_or_siren)

Expand Down Expand Up @@ -157,7 +161,7 @@ def build_params(user_id)
def base_params
{
context: APPLICATION_NAME,
recipient: ENV.fetch('API_ENTREPRISE_DEFAULT_SIRET'),
recipient: recipient,
non_diffusables: true
}
end
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/api_entreprise/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
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

Expand Down

0 comments on commit 4862cc2

Please sign in to comment.