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:
commit
d80f540246
6 changed files with 61 additions and 5 deletions
|
@ -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,
|
||||
|
|
|
@ -253,12 +253,14 @@ class API::V2::StoredQuery
|
|||
...GroupeInstructeurFragment
|
||||
}
|
||||
demandeur {
|
||||
__typename
|
||||
... on PersonnePhysique {
|
||||
civilite
|
||||
nom
|
||||
prenom
|
||||
dateDeNaissance
|
||||
}
|
||||
... on PersonneMoraleIncomplete { siret }
|
||||
...PersonneMoraleFragment
|
||||
}
|
||||
demarche {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -10,9 +10,13 @@ module Types
|
|||
when Individual
|
||||
Types::PersonnePhysiqueType
|
||||
when Etablissement
|
||||
if object.as_degraded_mode? && context.has_fragment?(:PersonneMoraleIncomplete)
|
||||
Types::PersonneMoraleIncompleteType
|
||||
else
|
||||
Types::PersonneMoraleType
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
7
app/graphql/types/personne_morale_incomplete_type.rb
Normal file
7
app/graphql/types/personne_morale_incomplete_type.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
module Types
|
||||
class PersonneMoraleIncompleteType < Types::BaseObject
|
||||
implements Types::DemandeurType
|
||||
|
||||
field :siret, String, null: false
|
||||
end
|
||||
end
|
|
@ -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,10 +352,18 @@ 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:) }
|
||||
|
||||
it {
|
||||
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 {
|
||||
|
@ -335,6 +371,7 @@ describe API::V2::GraphqlController do
|
|||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'dossierRefuser' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
||||
|
|
Loading…
Reference in a new issue