Add SIRET champs support to the API

This commit is contained in:
Paul Chavard 2018-10-22 19:27:33 +02:00
parent df73e442e9
commit 17418edb54
2 changed files with 28 additions and 0 deletions

View file

@ -0,0 +1,12 @@
class Champs::SiretChampSerializer < ChampSerializer
has_one :etablissement
has_one :entreprise
def etablissement
object.etablissement
end
def entreprise
object.etablissement&.entreprise
end
end

View file

@ -0,0 +1,16 @@
describe Champs::SiretChampSerializer do
describe '#attributes' do
subject { Champs::SiretChampSerializer.new(champ).serializable_hash }
context 'when type champ is siret' do
let(:etablissement) { create(:etablissement) }
let(:champ) { create(:type_de_champ_siret).champ.create(etablissement: etablissement, value: etablissement.siret) }
it {
is_expected.to include(value: etablissement.siret)
expect(subject[:etablissement]).to include(siret: etablissement.siret)
expect(subject[:entreprise]).to include(capital_social: etablissement.entreprise_capital_social)
}
end
end
end