Merge pull request #8861 from tchak/fix-graphql-demandeur-as_degraded_mode

fix(graphql): demandeur personne morale can be in degraded mode
This commit is contained in:
Paul Chavard 2023-04-05 09:30:29 +00:00 committed by GitHub
commit d80f540246
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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::ParcelleCadastraleType,
Types::GeoAreas::SelectionUtilisateurType, Types::GeoAreas::SelectionUtilisateurType,
Types::PersonneMoraleType, Types::PersonneMoraleType,
Types::PersonneMoraleIncompleteType,
Types::PersonnePhysiqueType, Types::PersonnePhysiqueType,
Types::Champs::Descriptor::AddressChampDescriptorType, Types::Champs::Descriptor::AddressChampDescriptorType,
Types::Champs::Descriptor::AnnuaireEducationChampDescriptorType, Types::Champs::Descriptor::AnnuaireEducationChampDescriptorType,

View file

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

View file

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

View file

@ -10,7 +10,11 @@ module Types
when Individual when Individual
Types::PersonnePhysiqueType Types::PersonnePhysiqueType
when Etablissement when Etablissement
Types::PersonneMoraleType if object.as_degraded_mode? && context.has_fragment?(:PersonneMoraleIncomplete)
Types::PersonneMoraleIncompleteType
else
Types::PersonneMoraleType
end
end end
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 { it {
expect(gql_errors).to be_nil expect(gql_errors).to be_nil
expect(gql_data[:dossier][:id]).to eq(dossier.to_typed_id) 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 end
context 'getDemarche' do context 'getDemarche' do
@ -324,15 +352,24 @@ describe API::V2::GraphqlController do
} }
end end
context 'when in degraded mode' do context 'with entreprise' do
let(:procedure) { create(:procedure, :published, :with_service, administrateurs: [admin]) } let(:procedure) { create(:procedure, :published, :with_service, administrateurs: [admin]) }
let(:dossier) { create(:dossier, :en_instruction, :with_entreprise, procedure:) } let(:dossier) { create(:dossier, :en_instruction, :with_entreprise, procedure:) }
before { dossier.etablissement.update(adresse: nil) }
it { 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
end end