Add SIRET champs support to the API
This commit is contained in:
parent
df73e442e9
commit
17418edb54
2 changed files with 28 additions and 0 deletions
12
app/serializers/champs/siret_champ_serializer.rb
Normal file
12
app/serializers/champs/siret_champ_serializer.rb
Normal 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
|
16
spec/serializers/champs/siret_champ_serializer_spec.rb
Normal file
16
spec/serializers/champs/siret_champ_serializer_spec.rb
Normal 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
|
Loading…
Reference in a new issue