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 {
attestationFiscaleAttachment: File
attestationSocialeAttachment: File
"""
capital social de lentreprise. -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 {

View file

@ -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 lentreprise. -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

View file

@ -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