call api_entreprise with specific token if exist
This commit is contained in:
parent
14ff18ca80
commit
e29af48420
2 changed files with 29 additions and 5 deletions
|
@ -74,11 +74,12 @@ class ApiEntreprise::API
|
||||||
recipient: siret_or_siren,
|
recipient: siret_or_siren,
|
||||||
object: "procedure_id: #{procedure_id}",
|
object: "procedure_id: #{procedure_id}",
|
||||||
non_diffusables: true,
|
non_diffusables: true,
|
||||||
token: token
|
token: token_for_procedure(procedure_id)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.token
|
def self.token_for_procedure(procedure_id)
|
||||||
Rails.application.secrets.api_entreprise[:key]
|
procedure = Procedure.find(procedure_id)
|
||||||
|
procedure.api_entreprise_token.presence || Rails.application.secrets.api_entreprise[:key]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
describe ApiEntreprise::API do
|
describe ApiEntreprise::API do
|
||||||
let(:procedure_id) { 12 }
|
let(:procedure) { create(:procedure) }
|
||||||
|
let(:procedure_id) { procedure.id }
|
||||||
|
let(:token) { Rails.application.secrets.api_entreprise[:key] }
|
||||||
|
|
||||||
describe '.entreprise' do
|
describe '.entreprise' do
|
||||||
subject { described_class.entreprise(siren, procedure_id) }
|
subject { described_class.entreprise(siren, procedure_id) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=#{token}/)
|
||||||
.to_return(status: status, body: body)
|
.to_return(status: status, body: body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,6 +49,27 @@ describe ApiEntreprise::API do
|
||||||
it 'returns response body' do
|
it 'returns response body' do
|
||||||
expect(subject).to eq(JSON.parse(body, symbolize_names: true))
|
expect(subject).to eq(JSON.parse(body, symbolize_names: true))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with specific token for procedure' do
|
||||||
|
let(:token) { 'token-for-demarche' }
|
||||||
|
let(:procedure) { create(:procedure, api_entreprise_token: token) }
|
||||||
|
let(:procedure_id) { procedure.id }
|
||||||
|
|
||||||
|
it 'call api-entreprise with specfic token' do
|
||||||
|
subject
|
||||||
|
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=token-for-demarche/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without specific token for procedure' do
|
||||||
|
let(:procedure) { create(:procedure, api_entreprise_token: nil) }
|
||||||
|
let(:procedure_id) { procedure.id }
|
||||||
|
|
||||||
|
it 'call api-entreprise with specfic token' do
|
||||||
|
subject
|
||||||
|
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=#{token}/)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue