ExercicesAdapter#to_array -> ExercicesAdapter#to_params
This commit is contained in:
parent
54ab0ec5f0
commit
5f1394cd7f
3 changed files with 14 additions and 12 deletions
|
@ -1,11 +1,13 @@
|
||||||
class ApiEntreprise::ExercicesAdapter < ApiEntreprise::Adapter
|
class ApiEntreprise::ExercicesAdapter < ApiEntreprise::Adapter
|
||||||
def to_array
|
def to_params
|
||||||
if data_source.present?
|
if data_source.present?
|
||||||
data_source[:exercices].map do |exercice|
|
exercices_array = data_source[:exercices].map do |exercice|
|
||||||
exercice.slice(*attr_to_fetch)
|
exercice.slice(*attr_to_fetch)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
{ exercices_attributes: exercices_array }
|
||||||
else
|
else
|
||||||
[]
|
{}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@ class SIRETService
|
||||||
|
|
||||||
if etablissement_params.present? && entreprise_params.present?
|
if etablissement_params.present? && entreprise_params.present?
|
||||||
association_params = ApiEntreprise::RNAAdapter.new(siret, procedure_id).to_params
|
association_params = ApiEntreprise::RNAAdapter.new(siret, procedure_id).to_params
|
||||||
exercices_array = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id).to_array
|
exercices_params = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id).to_params
|
||||||
|
|
||||||
params = etablissement_params
|
params = etablissement_params
|
||||||
.merge(entreprise_params.transform_keys { |k| "entreprise_#{k}" })
|
.merge(entreprise_params.transform_keys { |k| "entreprise_#{k}" })
|
||||||
.merge(association_params.transform_keys { |k| "association_#{k}" })
|
.merge(association_params.transform_keys { |k| "association_#{k}" })
|
||||||
.merge(exercices_attributes: exercices_array)
|
.merge(exercices_params)
|
||||||
|
|
||||||
# This is to fill legacy models and relationships
|
# This is to fill legacy models and relationships
|
||||||
if dossier.present?
|
if dossier.present?
|
||||||
|
|
|
@ -3,32 +3,32 @@ require 'spec_helper'
|
||||||
describe ApiEntreprise::ExercicesAdapter do
|
describe ApiEntreprise::ExercicesAdapter do
|
||||||
let(:siret) { '41816609600051' }
|
let(:siret) { '41816609600051' }
|
||||||
let(:procedure_id) { 11 }
|
let(:procedure_id) { 11 }
|
||||||
subject { described_class.new(siret, procedure_id).to_array }
|
subject { described_class.new(siret, procedure_id).to_params }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/staging.entreprise.api.gouv.fr\/v2\/exercices\/.*token=/)
|
stub_request(:get, /https:\/\/staging.entreprise.api.gouv.fr\/v2\/exercices\/.*token=/)
|
||||||
.to_return(body: File.read('spec/support/files/exercices.json', status: 200))
|
.to_return(body: File.read('spec/support/files/exercices.json', status: 200))
|
||||||
end
|
end
|
||||||
|
|
||||||
it '#to_array class est un Array ?' do
|
it '#to_params class est un Hash ?' do
|
||||||
expect(subject).to be_an_instance_of(Array)
|
expect(subject).to be_an_instance_of(Hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'have 3 exercices' do
|
it 'have 3 exercices' do
|
||||||
expect(subject.size).to eq(3)
|
expect(subject[:exercices_attributes].size).to eq(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Attributs Exercices' do
|
context 'Attributs Exercices' do
|
||||||
it 'L\'exercice contient bien un ca' do
|
it 'L\'exercice contient bien un ca' do
|
||||||
expect(subject[0][:ca]).to eq('21009417')
|
expect(subject[:exercices_attributes][0][:ca]).to eq('21009417')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'exercice contient bien une date de fin d\'exercice' do
|
it 'L\'exercice contient bien une date de fin d\'exercice' do
|
||||||
expect(subject[0][:date_fin_exercice]).to eq("2013-12-31T00:00:00+01:00")
|
expect(subject[:exercices_attributes][0][:date_fin_exercice]).to eq("2013-12-31T00:00:00+01:00")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'exercice contient bien une date_fin_exercice_timestamp' do
|
it 'L\'exercice contient bien une date_fin_exercice_timestamp' do
|
||||||
expect(subject[0][:date_fin_exercice_timestamp]).to eq(1388444400)
|
expect(subject[:exercices_attributes][0][:date_fin_exercice_timestamp]).to eq(1388444400)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue