diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index a81e39392..bf39ff900 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -713,8 +713,12 @@ type Effectif { type Entreprise { attestationFiscaleAttachment: File attestationSocialeAttachment: File + + """ + capital social de l’entreprise. -1 si inconnu. + """ capitalSocial: BigInt! - codeEffectifEntreprise: String! + codeEffectifEntreprise: String dateCreation: ISO8601Date! """ @@ -1011,10 +1015,10 @@ type PersonneMorale implements Demandeur { localite: String! naf: String! nomVoie: String! - numeroVoie: String! + numeroVoie: String siegeSocial: Boolean! siret: String! - typeVoie: String! + typeVoie: String } type PersonnePhysique implements Demandeur { diff --git a/app/graphql/types/personne_morale_type.rb b/app/graphql/types/personne_morale_type.rb index 769554ce6..bef7c6d02 100644 --- a/app/graphql/types/personne_morale_type.rb +++ b/app/graphql/types/personne_morale_type.rb @@ -7,14 +7,14 @@ module Types end field :siren, String, null: false - field :capital_social, GraphQL::Types::BigInt, null: false + field :capital_social, GraphQL::Types::BigInt, null: false, description: "capital social de l’entreprise. -1 si inconnu." field :numero_tva_intracommunautaire, String, null: false field :forme_juridique, String, null: false field :forme_juridique_code, String, null: false 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,17 @@ 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 + # we need this in order to bypass Hashie::Dash deserialization issue on nil values + object.code_effectif_entreprise + end + def effectif_annuel if object.effectif_annuel.present? { @@ -76,8 +87,8 @@ module Types field :naf, String, null: false field :libelle_naf, String, null: false field :adresse, String, null: false - field :numero_voie, String, null: false - field :type_voie, String, null: false + field :numero_voie, String, null: true + field :type_voie, String, null: true field :nom_voie, String, null: false field :complement_adresse, String, null: false field :code_postal, String, null: false diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index b1c200c2f..feaf61eb2 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -396,37 +396,76 @@ describe API::V2::GraphqlController do ... on PersonneMorale { siret siegeSocial + numeroVoie + typeVoie entreprise { siren dateCreation capitalSocial + codeEffectifEntreprise } } } } }" end - - it "should be returned" do - expect(gql_errors).to eq(nil) - expect(gql_data).to eq(dossier: { - id: dossier.to_typed_id, - number: dossier.id, - usager: { - id: dossier.user.to_typed_id, - email: dossier.user.email - }, - demandeur: { - id: dossier.etablissement.to_typed_id, - siret: dossier.etablissement.siret, - siegeSocial: dossier.etablissement.siege_social, - entreprise: { - siren: dossier.etablissement.entreprise_siren, - dateCreation: dossier.etablissement.entreprise_date_creation.iso8601, - capitalSocial: dossier.etablissement.entreprise_capital_social.to_s + context "in the nominal case" do + it "should be returned" do + expect(gql_errors).to eq(nil) + expect(gql_data).to eq(dossier: { + id: dossier.to_typed_id, + number: dossier.id, + usager: { + id: dossier.user.to_typed_id, + email: dossier.user.email + }, + demandeur: { + id: dossier.etablissement.to_typed_id, + siret: dossier.etablissement.siret, + siegeSocial: dossier.etablissement.siege_social, + numeroVoie: dossier.etablissement.numero_voie.to_s, + typeVoie: dossier.etablissement.type_voie.to_s, + entreprise: { + siren: dossier.etablissement.entreprise_siren, + dateCreation: dossier.etablissement.entreprise_date_creation.iso8601, + capitalSocial: dossier.etablissement.entreprise_capital_social.to_s, + codeEffectifEntreprise: dossier.etablissement.entreprise_code_effectif_entreprise.to_s + } } - } - }) + }) + end + end + + context "when there are missing data" do + before do + dossier.etablissement.update!(entreprise_code_effectif_entreprise: nil, entreprise_capital_social: nil, + numero_voie: nil, type_voie: nil) + end + + it "should be returned" do + expect(gql_errors).to eq(nil) + expect(gql_data).to eq(dossier: { + id: dossier.to_typed_id, + number: dossier.id, + usager: { + id: dossier.user.to_typed_id, + email: dossier.user.email + }, + demandeur: { + id: dossier.etablissement.to_typed_id, + siret: dossier.etablissement.siret, + siegeSocial: dossier.etablissement.siege_social, + numeroVoie: nil, + typeVoie: nil, + entreprise: { + siren: dossier.etablissement.entreprise_siren, + dateCreation: dossier.etablissement.entreprise_date_creation.iso8601, + capitalSocial: '-1', + codeEffectifEntreprise: nil + } + } + }) + end end end end