From 4c17acf349366d2d63c796f5ac0dea60749ec0b7 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 21 Sep 2020 20:38:05 +0200 Subject: [PATCH 1/6] ajout du code effectif entreprise dans une spec graphql nominale --- spec/controllers/api/v2/graphql_controller_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index b1c200c2f..acddbc61b 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -400,6 +400,7 @@ describe API::V2::GraphqlController do siren dateCreation capitalSocial + codeEffectifEntreprise } } } @@ -423,7 +424,8 @@ describe API::V2::GraphqlController do entreprise: { siren: dossier.etablissement.entreprise_siren, dateCreation: dossier.etablissement.entreprise_date_creation.iso8601, - capitalSocial: dossier.etablissement.entreprise_capital_social.to_s + capitalSocial: dossier.etablissement.entreprise_capital_social.to_s, + codeEffectifEntreprise: dossier.etablissement.entreprise_code_effectif_entreprise.to_s } } }) From adb2a916405971fe4e8a1c224e62f4ba98676c3f Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 21 Sep 2020 20:39:54 +0200 Subject: [PATCH 2/6] add a broken test case --- .../api/v2/graphql_controller_spec.rb | 72 +++++++++++++------ 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index acddbc61b..b987c5f53 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -407,28 +407,58 @@ describe API::V2::GraphqlController do } }" 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, - codeEffectifEntreprise: dossier.etablissement.entreprise_code_effectif_entreprise.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, + 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) + 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: '', + codeEffectifEntreprise: '' + } + } + }) + end end end end From 1173f1e459d8c1f7b1230dbedfd12a3ece52d335 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 21 Sep 2020 21:16:58 +0200 Subject: [PATCH 3/6] 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: '' } } From 412a87e532a5a81813abf59c1fe13def7f782621 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Tue, 22 Sep 2020 09:26:46 +0200 Subject: [PATCH 4/6] add fix for nil values on numeroVoie and typeVoie --- app/graphql/types/personne_morale_type.rb | 9 +++++---- spec/controllers/api/v2/graphql_controller_spec.rb | 11 +++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/graphql/types/personne_morale_type.rb b/app/graphql/types/personne_morale_type.rb index 40b243d0a..bef7c6d02 100644 --- a/app/graphql/types/personne_morale_type.rb +++ b/app/graphql/types/personne_morale_type.rb @@ -7,7 +7,7 @@ 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 @@ -48,7 +48,8 @@ module Types end def code_effectif_entreprise - object.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 @@ -86,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 8c6fae99e..d1dffa0e0 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -396,6 +396,8 @@ describe API::V2::GraphqlController do ... on PersonneMorale { siret siegeSocial + numeroVoie + typeVoie entreprise { siren dateCreation @@ -421,11 +423,13 @@ describe API::V2::GraphqlController do 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 + codeEffectifEntreprise: dossier.etablissement.entreprise_code_effectif_entreprise.to_s, } } }) @@ -434,7 +438,8 @@ describe API::V2::GraphqlController do context "when there are missing data" do before do - dossier.etablissement.update!(entreprise_code_effectif_entreprise: nil, entreprise_capital_social: nil) + dossier.etablissement.update!(entreprise_code_effectif_entreprise: nil, entreprise_capital_social: nil, + numero_voie: nil, type_voie: nil) end it "should be returned" do @@ -450,6 +455,8 @@ describe API::V2::GraphqlController do 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, From 7ba8ab9e6a32dcf74c49207c839994bf88b9b43e Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Tue, 22 Sep 2020 09:30:28 +0200 Subject: [PATCH 5/6] maj du schema json --- app/graphql/schema.graphql | 10 +++++++--- spec/controllers/api/v2/graphql_controller_spec.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) 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/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index d1dffa0e0..33711e8b1 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -461,7 +461,7 @@ describe API::V2::GraphqlController do siren: dossier.etablissement.entreprise_siren, dateCreation: dossier.etablissement.entreprise_date_creation.iso8601, capitalSocial: '-1', - codeEffectifEntreprise: '' + codeEffectifEntreprise: nil } } }) From 005c244438fc0a224483f932e2027053ef6f3c3b Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Tue, 22 Sep 2020 10:17:54 +0200 Subject: [PATCH 6/6] fixup! add fix for nil values on numeroVoie and typeVoie --- spec/controllers/api/v2/graphql_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 33711e8b1..feaf61eb2 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -429,7 +429,7 @@ describe API::V2::GraphqlController do 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, + codeEffectifEntreprise: dossier.etablissement.entreprise_code_effectif_entreprise.to_s } } })