fix(graphql): demandeur personne morale can be in degraded mode

This commit is contained in:
Paul Chavard 2023-04-04 16:58:47 +02:00
parent 020f501a02
commit dee0952b2a
6 changed files with 61 additions and 5 deletions

View file

@ -78,6 +78,7 @@ class API::V2::Schema < GraphQL::Schema
Types::GeoAreas::ParcelleCadastraleType,
Types::GeoAreas::SelectionUtilisateurType,
Types::PersonneMoraleType,
Types::PersonneMoraleIncompleteType,
Types::PersonnePhysiqueType,
Types::Champs::Descriptor::AddressChampDescriptorType,
Types::Champs::Descriptor::AnnuaireEducationChampDescriptorType,

View file

@ -253,12 +253,14 @@ class API::V2::StoredQuery
...GroupeInstructeurFragment
}
demandeur {
__typename
... on PersonnePhysique {
civilite
nom
prenom
dateDeNaissance
}
... on PersonneMoraleIncomplete { siret }
...PersonneMoraleFragment
}
demarche {

View file

@ -3085,6 +3085,11 @@ type PersonneMorale implements Demandeur {
typeVoie: String @deprecated(reason: "Utilisez le champ `address.street_address` à la place.")
}
type PersonneMoraleIncomplete implements Demandeur {
id: ID!
siret: String!
}
type PersonnePhysique implements Demandeur {
civilite: Civilite
dateDeNaissance: ISO8601Date

View file

@ -10,7 +10,11 @@ module Types
when Individual
Types::PersonnePhysiqueType
when Etablissement
Types::PersonneMoraleType
if object.as_degraded_mode? && context.has_fragment?(:PersonneMoraleIncomplete)
Types::PersonneMoraleIncompleteType
else
Types::PersonneMoraleType
end
end
end
end

View file

@ -0,0 +1,7 @@
module Types
class PersonneMoraleIncompleteType < Types::BaseObject
implements Types::DemandeurType
field :siret, String, null: false
end
end

View file

@ -71,7 +71,35 @@ describe API::V2::GraphqlController do
it {
expect(gql_errors).to be_nil
expect(gql_data[:dossier][:id]).to eq(dossier.to_typed_id)
expect(gql_data[:dossier][:demandeur][:__typename]).to eq('PersonnePhysique')
expect(gql_data[:dossier][:demandeur][:nom]).to eq(dossier.individual.nom)
expect(gql_data[:dossier][:demandeur][:prenom]).to eq(dossier.individual.prenom)
}
context 'with entreprise' do
let(:procedure) { create(:procedure, :published, :with_service, administrateurs: [admin], types_de_champ_public:) }
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure) }
it {
expect(gql_errors).to be_nil
expect(gql_data[:dossier][:id]).to eq(dossier.to_typed_id)
expect(gql_data[:dossier][:demandeur][:__typename]).to eq('PersonneMorale')
expect(gql_data[:dossier][:demandeur][:siret]).to eq(dossier.etablissement.siret)
expect(gql_data[:dossier][:demandeur][:libelleNaf]).to eq(dossier.etablissement.libelle_naf)
}
context 'when in degraded mode' do
before { dossier.etablissement.update(adresse: nil) }
it {
expect(gql_errors).to be_nil
expect(gql_data[:dossier][:id]).to eq(dossier.to_typed_id)
expect(gql_data[:dossier][:demandeur][:__typename]).to eq('PersonneMoraleIncomplete')
expect(gql_data[:dossier][:demandeur][:siret]).to eq(dossier.etablissement.siret)
expect(gql_data[:dossier][:demandeur][:libelleNaf]).to be_nil
}
end
end
end
context 'getDemarche' do
@ -324,15 +352,24 @@ describe API::V2::GraphqlController do
}
end
context 'when in degraded mode' do
context 'with entreprise' do
let(:procedure) { create(:procedure, :published, :with_service, administrateurs: [admin]) }
let(:dossier) { create(:dossier, :en_instruction, :with_entreprise, procedure:) }
before { dossier.etablissement.update(adresse: nil) }
it {
expect(gql_data[:dossierAccepter][:errors].first[:message]).to eq('Les informations du SIRET du dossier ne sont pas complètes. Veuillez réessayer plus tard.')
expect(gql_errors).to be_nil
expect(gql_data[:dossierAccepter][:errors]).to be_nil
expect(gql_data[:dossierAccepter][:dossier][:id]).to eq(dossier.to_typed_id)
expect(gql_data[:dossierAccepter][:dossier][:state]).to eq('accepte')
}
context 'when in degraded mode' do
before { dossier.etablissement.update(adresse: nil) }
it {
expect(gql_data[:dossierAccepter][:errors].first[:message]).to eq('Les informations du SIRET du dossier ne sont pas complètes. Veuillez réessayer plus tard.')
}
end
end
end