call api_entreprise adapters with siret

This commit is contained in:
Christophe Robillard 2020-05-14 14:41:54 +02:00
parent f7201dd17b
commit e3ee423197
12 changed files with 34 additions and 26 deletions

View file

@ -25,4 +25,8 @@ class ApiEntreprise::Adapter
def valid_params?(params)
!params.has_value?(UNAVAILABLE)
end
def siren
@siret[0..8]
end
end

View file

@ -1,6 +1,6 @@
class ApiEntreprise::AttestationFiscaleAdapter < ApiEntreprise::Adapter
def initialize(siren, procedure_id, user_id)
@siren = siren
def initialize(siret, procedure_id, user_id)
@siret = siret
@procedure_id = procedure_id
@user_id = user_id
end
@ -8,7 +8,7 @@ class ApiEntreprise::AttestationFiscaleAdapter < ApiEntreprise::Adapter
private
def get_resource
ApiEntreprise::API.attestation_fiscale(@siren, @procedure_id, @user_id)
ApiEntreprise::API.attestation_fiscale(siren, @procedure_id, @user_id)
end
def process_params

View file

@ -1,13 +1,13 @@
class ApiEntreprise::AttestationSocialeAdapter < ApiEntreprise::Adapter
def initialize(siren, procedure_id)
@siren = siren
def initialize(siret, procedure_id)
@siret = siret
@procedure_id = procedure_id
end
private
def get_resource
ApiEntreprise::API.attestation_sociale(@siren, @procedure_id)
ApiEntreprise::API.attestation_sociale(siren, @procedure_id)
end
def process_params

View file

@ -1,13 +1,13 @@
class ApiEntreprise::BilansBdfAdapter < ApiEntreprise::Adapter
def initialize(siren, procedure_id)
@siren = siren
def initialize(siret, procedure_id)
@siret = siret
@procedure_id = procedure_id
end
private
def get_resource
ApiEntreprise::API.bilans_bdf(@siren, @procedure_id)
ApiEntreprise::API.bilans_bdf(siren, @procedure_id)
end
def process_params

View file

@ -1,6 +1,6 @@
class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter
def initialize(siren, procedure_id, annee, mois)
@siren = siren
def initialize(siret, procedure_id, annee, mois)
@siret = siret
@procedure_id = procedure_id
@annee = annee
@mois = mois
@ -9,7 +9,7 @@ class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter
private
def get_resource
ApiEntreprise::API.effectifs(@siren, @procedure_id, @annee, @mois)
ApiEntreprise::API.effectifs(siren, @procedure_id, @annee, @mois)
end
def process_params

View file

@ -1,13 +1,13 @@
class ApiEntreprise::EffectifsAnnuelsAdapter < ApiEntreprise::Adapter
def initialize(siren, procedure_id)
@siren = siren
def initialize(siret, procedure_id)
@siret = siret
@procedure_id = procedure_id
end
private
def get_resource
ApiEntreprise::API.effectifs_annuels(@siren, @procedure_id)
ApiEntreprise::API.effectifs_annuels(siren, @procedure_id)
end
def process_params

View file

@ -2,7 +2,6 @@ class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter
private
def get_resource
siren = @siret[0..8]
ApiEntreprise::API.entreprise(siren, @procedure_id)
end

View file

@ -1,12 +1,13 @@
describe ApiEntreprise::AttestationFiscaleAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
let(:user_id) { 1 }
let(:adapter) { described_class.new(siren, procedure.id, user_id) }
let(:adapter) { described_class.new(siret, procedure.id, user_id) }
subject { adapter.to_params }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}?.*token=/)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}\?.*token=/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["attestations_fiscales"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)

View file

@ -1,11 +1,12 @@
describe ApiEntreprise::AttestationSocialeAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
let(:adapter) { described_class.new(siren, procedure.id) }
let(:adapter) { described_class.new(siret, procedure.id) }
subject { adapter.to_params }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}?.*token=/)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}\?.*token=/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["attestations_sociales"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)

View file

@ -1,12 +1,13 @@
describe ApiEntreprise::BilansBdfAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
let(:adapter) { described_class.new(siren, procedure_id) }
let(:adapter) { described_class.new(siret, procedure_id) }
subject { adapter.to_params }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}?.*token=/)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}\?.*token=/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)

View file

@ -1,14 +1,15 @@
describe ApiEntreprise::EffectifsAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
let(:annee) { "2020" }
let(:mois) { "02" }
let(:adapter) { described_class.new(siren, procedure_id, annee, mois) }
let(:adapter) { described_class.new(siret, procedure_id, annee, mois) }
subject { adapter.to_params }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}?.*token=/)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}\?.*token=/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
end

View file

@ -1,12 +1,13 @@
describe ApiEntreprise::EffectifsAnnuelsAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
let(:adapter) { described_class.new(siren, procedure_id) }
let(:adapter) { described_class.new(siret, procedure_id) }
subject { adapter.to_params }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}\?.*token=/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
end