Merge pull request #5603 from Keirua/fix-graphql-entreprise-nil-values

#5600 - Fix GraphQL entreprise nil values
This commit is contained in:
Keirua 2020-09-22 10:32:22 +02:00 committed by GitHub
commit 58bc2ee4e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 27 deletions

View file

@ -713,8 +713,12 @@ type Effectif {
type Entreprise { type Entreprise {
attestationFiscaleAttachment: File attestationFiscaleAttachment: File
attestationSocialeAttachment: File attestationSocialeAttachment: File
"""
capital social de lentreprise. -1 si inconnu.
"""
capitalSocial: BigInt! capitalSocial: BigInt!
codeEffectifEntreprise: String! codeEffectifEntreprise: String
dateCreation: ISO8601Date! dateCreation: ISO8601Date!
""" """
@ -1011,10 +1015,10 @@ type PersonneMorale implements Demandeur {
localite: String! localite: String!
naf: String! naf: String!
nomVoie: String! nomVoie: String!
numeroVoie: String! numeroVoie: String
siegeSocial: Boolean! siegeSocial: Boolean!
siret: String! siret: String!
typeVoie: String! typeVoie: String
} }
type PersonnePhysique implements Demandeur { type PersonnePhysique implements Demandeur {

View file

@ -7,14 +7,14 @@ module Types
end end
field :siren, String, null: false 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 lentreprise. -1 si inconnu."
field :numero_tva_intracommunautaire, String, null: false field :numero_tva_intracommunautaire, String, null: false
field :forme_juridique, String, null: false field :forme_juridique, String, null: false
field :forme_juridique_code, String, null: false field :forme_juridique_code, String, null: false
field :nom_commercial, String, null: false field :nom_commercial, String, null: false
field :raison_sociale, String, null: false field :raison_sociale, String, null: false
field :siret_siege_social, 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_mensuel, EffectifType, null: true, description: "effectif pour un mois donné"
field :effectif_annuel, EffectifType, null: true, description: "effectif moyen d'une année" 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: false
@ -41,6 +41,17 @@ module Types
end end
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 def effectif_annuel
if object.effectif_annuel.present? if object.effectif_annuel.present?
{ {
@ -76,8 +87,8 @@ module Types
field :naf, String, null: false field :naf, String, null: false
field :libelle_naf, String, null: false field :libelle_naf, String, null: false
field :adresse, String, null: false field :adresse, String, null: false
field :numero_voie, String, null: false field :numero_voie, String, null: true
field :type_voie, String, null: false field :type_voie, String, null: true
field :nom_voie, String, null: false field :nom_voie, String, null: false
field :complement_adresse, String, null: false field :complement_adresse, String, null: false
field :code_postal, String, null: false field :code_postal, String, null: false

View file

@ -396,37 +396,76 @@ describe API::V2::GraphqlController do
... on PersonneMorale { ... on PersonneMorale {
siret siret
siegeSocial siegeSocial
numeroVoie
typeVoie
entreprise { entreprise {
siren siren
dateCreation dateCreation
capitalSocial capitalSocial
codeEffectifEntreprise
} }
} }
} }
} }
}" }"
end end
context "in the nominal case" do
it "should be returned" do it "should be returned" do
expect(gql_errors).to eq(nil) expect(gql_errors).to eq(nil)
expect(gql_data).to eq(dossier: { expect(gql_data).to eq(dossier: {
id: dossier.to_typed_id, id: dossier.to_typed_id,
number: dossier.id, number: dossier.id,
usager: { usager: {
id: dossier.user.to_typed_id, id: dossier.user.to_typed_id,
email: dossier.user.email email: dossier.user.email
}, },
demandeur: { demandeur: {
id: dossier.etablissement.to_typed_id, id: dossier.etablissement.to_typed_id,
siret: dossier.etablissement.siret, siret: dossier.etablissement.siret,
siegeSocial: dossier.etablissement.siege_social, siegeSocial: dossier.etablissement.siege_social,
entreprise: { numeroVoie: dossier.etablissement.numero_voie.to_s,
siren: dossier.etablissement.entreprise_siren, typeVoie: dossier.etablissement.type_voie.to_s,
dateCreation: dossier.etablissement.entreprise_date_creation.iso8601, entreprise: {
capitalSocial: dossier.etablissement.entreprise_capital_social.to_s 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 end
end end