From 1173f1e459d8c1f7b1230dbedfd12a3ece52d335 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 21 Sep 2020 21:16:58 +0200 Subject: [PATCH] add default values when nil --- app/graphql/types/personne_morale_type.rb | 12 +++++++++++- spec/controllers/api/v2/graphql_controller_spec.rb | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/graphql/types/personne_morale_type.rb b/app/graphql/types/personne_morale_type.rb index 769554ce6..40b243d0a 100644 --- a/app/graphql/types/personne_morale_type.rb +++ b/app/graphql/types/personne_morale_type.rb @@ -14,7 +14,7 @@ module Types field :nom_commercial, String, null: false field :raison_sociale, String, null: false field :siret_siege_social, String, null: false - field :code_effectif_entreprise, String, null: false + 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 @@ -41,6 +41,16 @@ module Types end end + def capital_social + # capital_social is defined as a BigInt, so we can't return an empty string when value is unknown + # 0 could appear to be a legitimate value, so a negative value helps to ensure the value is not known + object.capital_social || '-1' + end + + def code_effectif_entreprise + object.code_effectif_entreprise || '' + end + def effectif_annuel if object.effectif_annuel.present? { diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index b987c5f53..8c6fae99e 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -453,7 +453,7 @@ describe API::V2::GraphqlController do entreprise: { siren: dossier.etablissement.entreprise_siren, dateCreation: dossier.etablissement.entreprise_date_creation.iso8601, - capitalSocial: '', + capitalSocial: '-1', codeEffectifEntreprise: '' } }