diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 4ccc4d345..a4449a991 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -1450,7 +1450,7 @@ type Entreprise { """ capitalSocial: BigInt codeEffectifEntreprise: String - dateCreation: ISO8601Date! + dateCreation: ISO8601Date """ effectif moyen d’une année diff --git a/app/graphql/types/personne_morale_type.rb b/app/graphql/types/personne_morale_type.rb index e69f8812e..6fd46e2dc 100644 --- a/app/graphql/types/personne_morale_type.rb +++ b/app/graphql/types/personne_morale_type.rb @@ -22,7 +22,7 @@ module Types field :code_effectif_entreprise, String, null: true field :effectif_mensuel, EffectifType, null: true, description: "effectif pour un mois donné" field :effectif_annuel, EffectifType, null: true, description: "effectif moyen d’une année" - field :date_creation, GraphQL::Types::ISO8601Date, null: false + field :date_creation, GraphQL::Types::ISO8601Date, null: true field :etat_administratif, EntrepriseEtatAdministratifType, null: true field :nom, String, null: true field :prenom, String, null: true diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb index 09a71053e..169d8a46b 100644 --- a/app/models/entreprise.rb +++ b/app/models/entreprise.rb @@ -19,7 +19,7 @@ class Entreprise < Hashie::Dash property :effectif_mensuel property :effectif_annuel property :effectif_annuel_annee - property :date_creation + property :date_creation, default: nil property :nom, default: nil property :prenom, default: nil diff --git a/spec/services/serializer_service_spec.rb b/spec/services/serializer_service_spec.rb new file mode 100644 index 000000000..2a32c4184 --- /dev/null +++ b/spec/services/serializer_service_spec.rb @@ -0,0 +1,27 @@ +describe SerializerService do + let(:dossier) { create(:dossier, :en_construction) } + + describe 'champ' do + subject { SerializerService.champ(champ) } + + describe 'type champ is siret' do + let(:etablissement) { create(:etablissement) } + let(:champ) { create(:champ_siret, etablissement:, dossier:) } + + it { + is_expected.to include("stringValue" => etablissement.siret) + expect(subject["etablissement"]).to include("siret" => etablissement.siret) + expect(subject["etablissement"]["entreprise"]).to include("codeEffectifEntreprise" => etablissement.entreprise_code_effectif_entreprise) + } + + context 'with entreprise_date_creation is nil' do + let(:etablissement) { create(:etablissement, entreprise_date_creation: nil) } + + it { + expect(subject["etablissement"]["entreprise"]).to include("nomCommercial" => etablissement.entreprise_nom_commercial) + expect(subject["etablissement"]["entreprise"]["dateCreation"]).to be_nil + } + end + end + end +end