fetch and store bilans bdf
This commit is contained in:
parent
85b2e9ef44
commit
b12226c667
5 changed files with 33 additions and 3 deletions
|
@ -46,6 +46,13 @@ class ApiEntrepriseService
|
||||||
etablissement_params.merge!(attestation_fiscale_params)
|
etablissement_params.merge!(attestation_fiscale_params)
|
||||||
rescue ApiEntreprise::API::RequestFailed
|
rescue ApiEntreprise::API::RequestFailed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
bilans_bdf_params = ApiEntreprise::BilansBdfAdapter.new(entreprise_params[:entreprise_siren], procedure_id).to_params
|
||||||
|
etablissement_params.merge!(bilans_bdf_params)
|
||||||
|
rescue ApiEntreprise::API::RequestFailed
|
||||||
|
end
|
||||||
|
|
||||||
etablissement_params.merge(entreprise_params)
|
etablissement_params.merge(entreprise_params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddBilansBdfToEtablissements < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :etablissements, :entreprise_bilans_bdf, :jsonb
|
||||||
|
add_column :etablissements, :entreprise_bilans_bdf_monnaie, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_04_23_171759) do
|
ActiveRecord::Schema.define(version: 2020_04_29_191305) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -316,6 +316,8 @@ ActiveRecord::Schema.define(version: 2020_04_23_171759) do
|
||||||
t.decimal "entreprise_effectif_mensuel"
|
t.decimal "entreprise_effectif_mensuel"
|
||||||
t.decimal "entreprise_effectif_annuel"
|
t.decimal "entreprise_effectif_annuel"
|
||||||
t.string "entreprise_effectif_annuel_annee"
|
t.string "entreprise_effectif_annuel_annee"
|
||||||
|
t.jsonb "entreprise_bilans_bdf"
|
||||||
|
t.string "entreprise_bilans_bdf_monnaie"
|
||||||
t.index ["dossier_id"], name: "index_etablissements_on_dossier_id"
|
t.index ["dossier_id"], name: "index_etablissements_on_dossier_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,9 @@ describe Users::DossiersController, type: :controller do
|
||||||
let(:api_entreprise_attestation_fiscale_status) { 200 }
|
let(:api_entreprise_attestation_fiscale_status) { 200 }
|
||||||
let(:api_entreprise_attestation_fiscale_body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
|
let(:api_entreprise_attestation_fiscale_body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
|
||||||
|
|
||||||
|
let(:api_entreprise_bilans_bdf_status) { 200 }
|
||||||
|
let(:api_entreprise_bilans_bdf_body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') }
|
||||||
|
|
||||||
def stub_api_entreprise_requests
|
def stub_api_entreprise_requests
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
||||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||||
|
@ -248,12 +251,15 @@ describe Users::DossiersController, type: :controller do
|
||||||
.to_return(body: api_entreprise_attestation_fiscale_body, status: api_entreprise_attestation_fiscale_status)
|
.to_return(body: api_entreprise_attestation_fiscale_body, status: api_entreprise_attestation_fiscale_status)
|
||||||
stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf")
|
stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf")
|
||||||
.to_return(body: "body attestation", status: 200)
|
.to_return(body: "body attestation", status: 200)
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}?.*token=/)
|
||||||
|
.to_return(body: api_entreprise_bilans_bdf_body, status: api_entreprise_bilans_bdf_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
stub_api_entreprise_requests
|
stub_api_entreprise_requests
|
||||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(["attestations_fiscales", "attestations_sociales"])
|
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles)
|
||||||
|
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
|
||||||
end
|
end
|
||||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
||||||
|
@ -351,6 +357,7 @@ describe Users::DossiersController, type: :controller do
|
||||||
expect(dossier.etablissement.entreprise_effectif_annuel).to be_present
|
expect(dossier.etablissement.entreprise_effectif_annuel).to be_present
|
||||||
expect(dossier.etablissement.entreprise_attestation_sociale).to be_attached
|
expect(dossier.etablissement.entreprise_attestation_sociale).to be_attached
|
||||||
expect(dossier.etablissement.entreprise_attestation_fiscale).to be_attached
|
expect(dossier.etablissement.entreprise_attestation_fiscale).to be_attached
|
||||||
|
expect(dossier.etablissement.entreprise_bilans_bdf).to be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,8 @@ describe ApiEntrepriseService do
|
||||||
.to_return(body: attestation_sociale_body, status: attestation_sociale_status)
|
.to_return(body: attestation_sociale_body, status: attestation_sociale_status)
|
||||||
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: attestation_fiscale_body, status: attestation_fiscale_status)
|
.to_return(body: attestation_fiscale_body, status: attestation_fiscale_status)
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}?.*token=/)
|
||||||
|
.to_return(body: bilans_bdf_body, status: bilans_bdf_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||||
|
@ -52,6 +54,10 @@ describe ApiEntrepriseService do
|
||||||
let(:attestation_fiscale_body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
|
let(:attestation_fiscale_body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
|
||||||
let(:attestation_fiscale_url) { "https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf" }
|
let(:attestation_fiscale_url) { "https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf" }
|
||||||
|
|
||||||
|
let(:bilans_bdf_status) { 200 }
|
||||||
|
let(:bilans_bdf_body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') }
|
||||||
|
let(:bilans_bdf) { JSON.parse(bilans_bdf_body, symbolize_names: true)[:bilans] }
|
||||||
|
|
||||||
let(:exercices_status) { 200 }
|
let(:exercices_status) { 200 }
|
||||||
let(:exercices_body) { File.read('spec/fixtures/files/api_entreprise/exercices.json') }
|
let(:exercices_body) { File.read('spec/fixtures/files/api_entreprise/exercices.json') }
|
||||||
|
|
||||||
|
@ -62,7 +68,8 @@ describe ApiEntrepriseService do
|
||||||
let(:result) { ApiEntrepriseService.get_etablissement_params_for_siret(siret, procedure.id) }
|
let(:result) { ApiEntrepriseService.get_etablissement_params_for_siret(siret, procedure.id) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(["attestations_sociales", "attestations_fiscales"])
|
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles)
|
||||||
|
.and_return(["attestations_sociales", "attestations_fiscales", "bilans_entreprise_bdf"])
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when service is up' do
|
context 'when service is up' do
|
||||||
|
@ -75,6 +82,7 @@ describe ApiEntrepriseService do
|
||||||
expect(result[:entreprise_effectif_annuel]).to eq(effectif_annuel)
|
expect(result[:entreprise_effectif_annuel]).to eq(effectif_annuel)
|
||||||
expect(result[:entreprise_attestation_sociale_url]).to eq(attestation_sociale_url)
|
expect(result[:entreprise_attestation_sociale_url]).to eq(attestation_sociale_url)
|
||||||
expect(result[:entreprise_attestation_fiscale_url]).to eq(attestation_fiscale_url)
|
expect(result[:entreprise_attestation_fiscale_url]).to eq(attestation_fiscale_url)
|
||||||
|
expect(result[:entreprise_bilans_bdf]).to eq(bilans_bdf)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue