Merge pull request #9957 from demarches-simplifiees/finalize-rna-rnf-ldu

ETQ instructeur et consommateur API, la vue du champ RNA est harmonisée avec le champ RNF
This commit is contained in:
Colin Darie 2024-02-14 15:30:54 +00:00 committed by GitHub
commit bd3c2c070a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 173 additions and 10 deletions

View file

@ -2,4 +2,4 @@
en:
rnf_info_error: No foundation found
rnf_info_pending: RNF verification pending
rnf_info_success: "This RNF matches %{title}"
rnf_info_success: "This RNF matches %{title}, %{address}"

View file

@ -2,4 +2,4 @@
fr:
rnf_info_error: Aucune fondation trouvée
rnf_info_pending: Vérification du RNF en cours
rnf_info_success: "Ce RNF correspond à %{title}"
rnf_info_success: "Ce RNF correspond à %{title}, %{address}"

View file

@ -6,4 +6,4 @@
- elsif @champ.fetch_external_data_pending?
%p.fr-info-text= t('.rnf_info_pending')
- elsif @champ.data?
%p.fr-info-text= t('.rnf_info_success', title: @champ.title)
%p.fr-info-text= t('.rnf_info_success', title: @champ.title, address: @champ.full_address)

View file

@ -63,6 +63,7 @@ class API::V2::Schema < GraphQL::Schema
Types::Champs::DepartementChampType,
Types::Champs::DossierLinkChampType,
Types::Champs::EpciChampType,
Types::Champs::RNAChampType,
Types::Champs::RNFChampType,
Types::Champs::IntegerNumberChampType,
Types::Champs::LinkedDropDownListChampType,

View file

@ -3620,6 +3620,35 @@ type Query {
): GroupeInstructeurWithDossiers!
}
type RNA {
address: Address
id: String!
title: String
}
type RNAChamp implements Champ {
commune: Commune
departement: Departement
id: ID!
"""
Libellé du champ.
"""
label: String!
prefilled: Boolean!
rna: RNA
"""
La valeur du champ sous forme texte.
"""
stringValue: String
"""
Date de dernière modification du champ.
"""
updatedAt: ISO8601DateTime!
}
type RNAChampDescriptor implements ChampDescriptor {
"""
Description des champs dun bloc répétable.

View file

@ -75,6 +75,8 @@ module Types
Types::Champs::TitreIdentiteChampType
when ::Champs::EpciChamp
Types::Champs::EpciChampType
when ::Champs::RNAChamp
Types::Champs::RNAChampType
when ::Champs::RNFChamp
Types::Champs::RNFChampType
when ::Champs::EngagementJuridiqueChamp

View file

@ -0,0 +1,23 @@
module Types::Champs
class RNAChampType < Types::BaseObject
implements Types::ChampType
class RNAType < Types::BaseObject
field :id, String, null: false, method: :value
field :title, String, null: true, method: :title
field :address, Types::AddressType, null: true, method: :rna_address
end
field :rna, RNAType, null: true
field :commune, Types::Champs::CommuneChampType::CommuneType, null: true
field :departement, Types::Champs::DepartementChampType::DepartementType, null: true
def rna_id
object.value
end
def rna
object if object.value.present?
end
end
end

View file

@ -23,7 +23,8 @@ class APIEntreprise::RNAAdapter < APIEntreprise::Adapter
"association_date_creation" => data[:date_creation],
# see: https://mattermost.incubateur.net/betagouv/pl/r6txumw9cpyx58rt7iq5dte9qe
"association_date_declaration" => meta[:date_derniere_mise_a_jour_rna],
"association_date_publication" => data[:date_publication_journal_officiel]
"association_date_publication" => data[:date_publication_journal_officiel],
"adresse" => data[:adresse_siege]
}
end
end

View file

@ -22,4 +22,25 @@ class Champs::RNAChamp < Champ
def search_terms
etablissement.present? ? etablissement.search_terms : [value]
end
def full_address
address = data&.dig("adresse")
return if address.blank?
"#{address["numero_voie"]} #{address["type_voie"]} #{address["libelle_voie"]} #{address["code_postal"]} #{address["commune"]}"
end
def rna_address
address = data&.dig("adresse")
return if address.blank?
{
label: full_address,
type: "housenumber",
street_address: address["libelle_voie"] ? [address["numero_voie"], address["type_voie"], address["libelle_voie"]].compact.join(' ') : nil,
street_number: address["numero_voie"],
street_name: [address["type_voie"], address["libelle_voie"]].compact.join(' '),
postal_code: address["code_postal"],
city_name: address["commune"],
city_code: address["code_insee"]
}
end
end

View file

@ -109,4 +109,10 @@ class Champs::RNFChamp < Champ
}
end
end
def full_address
if address.present?
address['label']
end
end
end

View file

@ -8,4 +8,4 @@
%p.fr-error-text= t('.network_error')
- else
- if champ.value.present?
%p.fr-info-text= t('.data_fetched', title: champ.title)
%p.fr-info-text= t('.data_fetched', title: champ.title, address: champ.full_address)

View file

@ -21,3 +21,14 @@
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rna_champ.data.#{scope}")) do |c|
- c.with_value do
%p= l(champ.data[scope].to_date)
- if champ.data['address'].present?
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rna_champ.data.address")) do |c|
- c.with_value do
%p= champ.full_address
- ['code_insee', 'code_postal'].each do |scope|
- if champ.data['address'][scope].present?
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rna_champ.data.#{scope}")) do |c|
- c.with_value do
%p= champ.data['address'][scope]

View file

@ -9,6 +9,9 @@ en:
association_date_creation: Creation date
association_date_declaration: Declaration date
association_date_publication: Publication date
address: Address
code_insee: INSEE code
code_postal: Postal code
paste: Copy the RNA to the clipboard
paste_success: The RNA has been copied to the clipboard
activerecord:

View file

@ -9,6 +9,9 @@ fr:
association_date_creation: Date de création
association_date_declaration: Date de déclaration
association_date_publication: Date de publication
address: Adresse
code_insee: Code INSEE
code_postal: Code postal
paste: Copier le RNA dans le presse-papier
paste_success: Le RNA a été copié dans le presse-papier
activerecord:

View file

@ -15,6 +15,7 @@ en:
cityCode: City code
postalCode: Postal code
department: Department
label: Address
paste: Copy the RNF to the clipboard
paste_success: The RNF has been copied to the clipboard
activerecord:

View file

@ -15,6 +15,7 @@ fr:
cityCode: Code INSEE
postalCode: Code postal
department: Département
label: Adresse
paste: Copier le RNF dans le presse-papier
paste_success: Le RNF a été copié dans le presse-papier
activerecord:

View file

@ -28,7 +28,7 @@ en:
not_filled: not filled
not_found: "RNA number %{rna} (no association found)"
association:
data_fetched: "This RNA number is linked to %{title}"
data_fetched: "This RNA number is linked to %{title}, %{address}"
not_found: "No association found"
network_error: "A network error has prevented the association associated with this RNA to be fetched"
rnf:

View file

@ -30,7 +30,7 @@ fr:
not_filled: non renseigné
not_found: "RNA %{rna} (aucun établissement trouvé)"
association:
data_fetched: "Ce RNA correspond à %{title}"
data_fetched: "Ce RNA correspond à %{title}, %{address}"
not_found: "Aucun établissement trouvé"
network_error: "Une erreur réseau a empêché lassociation liée à ce RNA dêtre trouvée"
rnf:

View file

@ -27,7 +27,7 @@ RSpec.describe Types::DossierType, type: :graphql do
end
describe 'dossier with champs' do
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :communes }, { type: :address }, { type: :siret }]) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :communes }, { type: :address }, { type: :siret }, { type: :rna }]) }
let(:dossier) { create(:dossier, :accepte, :with_populated_champs, procedure: procedure) }
let(:query) { DOSSIER_WITH_CHAMPS_QUERY }
let(:variables) { { number: dossier.id } }
@ -48,7 +48,30 @@ RSpec.describe Types::DossierType, type: :graphql do
}
end
before { dossier.champs_public.second.update(data: address) }
let(:rna) do
{
"adresse" => {
"commune" => "Paris 14e",
"type_voie" => "RUE",
"code_insee" => "75114",
"complement" => nil,
"code_postal" => "75512",
"numero_voie" => "12",
"distribution" => nil,
"libelle_voie" => "xyz"
},
"association_rna" => "W173847273",
"association_objet" => "prévenir",
"association_titre" => "CROIX ROUGE",
"association_date_creation" => "1964-12-30",
"association_date_declaration" => "2022-08-10"
}
end
before do
dossier.champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:address) }.update(data: address)
dossier.champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:rna) }.update(data: rna)
end
it do
expect(data[:dossier][:champs][0][:__typename]).to eq "CommuneChamp"
@ -59,6 +82,11 @@ RSpec.describe Types::DossierType, type: :graphql do
expect(data[:dossier][:champs][1][:departement][:code]).to eq('75')
expect(data[:dossier][:champs][2][:etablissement][:siret]).to eq dossier.champs_public[2].etablissement.siret
expect(data[:dossier][:champs][0][:id]).to eq(data[:dossier][:revision][:champDescriptors][0][:id])
expect(data[:dossier][:champs][3][:rna][:id]).to eq('W173847273')
expect(data[:dossier][:champs][3][:rna][:title]).to eq('CROIX ROUGE')
expect(data[:dossier][:champs][3][:rna][:address][:label]).to eq('12 RUE xyz 75512 Paris 14e')
expect(data[:dossier][:champs][3][:rna][:address][:streetNumber]).to eq('12')
end
context 'when etablissement is in degraded mode' do
@ -398,6 +426,8 @@ RSpec.describe Types::DossierType, type: :graphql do
entreprise { capitalSocial }
}
}
...RNAChampFragment
}
}
}
@ -423,6 +453,17 @@ RSpec.describe Types::DossierType, type: :graphql do
streetName
streetNumber
}
fragment RNAChampFragment on RNAChamp {
stringValue
rna {
id
title
address {
...AddressFragment
}
}
}
GRAPHQL
DOSSIER_WITH_LINKED_DOSIER_QUERY = <<-GRAPHQL

View file

@ -31,6 +31,16 @@ describe APIEntreprise::RNAAdapter do
expect(subject["association_objet"]).to eq("L'association a pour objet de promouvoir la pratique du sport de haut niveau et de contribuer à la formation des jeunes sportifs.")
expect(subject["association_date_declaration"]).to eq("2019-01-01")
expect(subject["association_date_publication"]).to eq("2018-01-01")
expect(subject["adresse"]).to eq({
complement: "",
numero_voie: "33",
type_voie: "rue",
libelle_voie: "de Modagor",
distribution: "dummy",
code_insee: "75108",
code_postal: "75009",
commune: "Paris"
})
end
end
end

View file

@ -68,7 +68,17 @@ RSpec.describe RNAChampAssociationFetchableConcern do
"association_date_creation" => "2015-01-01",
"association_date_declaration" => "2019-01-01",
"association_date_publication" => "2018-01-01",
"association_rna" => "W751080001"
"association_rna" => "W751080001",
"adresse" => {
"complement" => "",
"numero_voie" => "33",
"type_voie" => "rue",
"libelle_voie" => "de Modagor",
"distribution" => "dummy",
"code_insee" => "75108",
"code_postal" => "75009",
"commune" => "Paris"
}
}
end
end