Merge pull request #8707 from demarches-simplifiees/prefill/address
feat(dossier): prefill address champ
This commit is contained in:
commit
bab8fac81e
12 changed files with 77 additions and 16 deletions
|
@ -266,6 +266,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
TypeDeChamp.type_champs.fetch(:regions),
|
||||
TypeDeChamp.type_champs.fetch(:departements),
|
||||
TypeDeChamp.type_champs.fetch(:communes),
|
||||
TypeDeChamp.type_champs.fetch(:address),
|
||||
TypeDeChamp.type_champs.fetch(:date),
|
||||
TypeDeChamp.type_champs.fetch(:datetime),
|
||||
TypeDeChamp.type_champs.fetch(:yes_no),
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::PrefillAddressTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp
|
||||
def to_assignable_attributes(champ, value)
|
||||
return if value.blank?
|
||||
{ id: champ.id, value: value, external_id: value }
|
||||
end
|
||||
end
|
|
@ -25,6 +25,8 @@ class TypesDeChamp::PrefillTypeDeChamp < SimpleDelegator
|
|||
TypesDeChamp::PrefillDepartementTypeDeChamp.new(type_de_champ, revision)
|
||||
when TypeDeChamp.type_champs.fetch(:communes)
|
||||
TypesDeChamp::PrefillCommuneTypeDeChamp.new(type_de_champ, revision)
|
||||
when TypeDeChamp.type_champs.fetch(:address)
|
||||
TypesDeChamp::PrefillAddressTypeDeChamp.new(type_de_champ, revision)
|
||||
when TypeDeChamp.type_champs.fetch(:epci)
|
||||
TypesDeChamp::PrefillEpciTypeDeChamp.new(type_de_champ, revision)
|
||||
when TypeDeChamp.type_champs.fetch(:annuaire_education)
|
||||
|
|
|
@ -145,15 +145,16 @@ en:
|
|||
pays_html: An <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank" rel="noopener noreferrer">ISO 3166-2 country code</a>
|
||||
regions_html: An <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">INSEE region code</a>
|
||||
departements_html: A <a href="https://fr.wikipedia.org/wiki/Num%C3%A9rotation_des_d%C3%A9partements_fran%C3%A7ais" target="_blank">department number</a>
|
||||
communes_html: An array of the department code and the <a href="https://geo.api.gouv.fr/communes" target="_blank" rel="noopener noreferrer">INSEE commune code</a>.
|
||||
communes_html: An array of the department code and the <a href="https://geo.api.gouv.fr/communes" target="_blank" rel="noopener noreferrer">INSEE commune code</a>
|
||||
address_html: An address EXACTLY formated as the label returned by <a href="https://adresse.data.gouv.fr" target="_blank" rel="noopener noreferrer">the Base Adresse Nationale</a>
|
||||
drop_down_list_html: A choice among those selected when the procedure was created
|
||||
date_html: ISO8601 date
|
||||
datetime_html: ISO8601 datetime
|
||||
drop_down_list_other_html: Any value
|
||||
siret_html: A SIRET number
|
||||
rna_html: A RNA number
|
||||
repetition_html: A array of hashes with possible values for each field of the repetition.
|
||||
epci_html: An array of the department code and the <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">EPCI one</a>.
|
||||
repetition_html: A array of hashes with possible values for each field of the repetition
|
||||
epci_html: An array of the department code and the <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">EPCI one</a>
|
||||
annuaire_education_html: An educational institution code, as defined by the <a href="https://api.gouv.fr/les-api/api-annuaire-education" target="_blank" rel="noopener noreferrer">Éducation Nationale</a> directory
|
||||
dossier_link_html: The file ID, as integer
|
||||
examples:
|
||||
|
@ -169,6 +170,7 @@ en:
|
|||
pays: "FR"
|
||||
departements: "56"
|
||||
regions: "53"
|
||||
address: "20 Avenue de Ségur 75007 Paris"
|
||||
date: "2023-02-01"
|
||||
datetime: "2023-02-01T10:30"
|
||||
checkbox: "true"
|
||||
|
|
|
@ -136,7 +136,8 @@ fr:
|
|||
pays_html: Un <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank" rel="noopener noreferrer">code pays ISO 3166-2</a>
|
||||
regions_html: Un <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">code INSEE de région</a>
|
||||
departements_html: Un <a href="https://fr.wikipedia.org/wiki/Num%C3%A9rotation_des_d%C3%A9partements_fran%C3%A7ais" target="_blank">numéro de département</a>
|
||||
communes_html: Un tableau contenant le code de département et <a href="https://geo.api.gouv.fr/communes" target="_blank" rel="noopener noreferrer">le code INSEE de la commune</a>.
|
||||
communes_html: Un tableau contenant le code de département et <a href="https://geo.api.gouv.fr/communes" target="_blank" rel="noopener noreferrer">le code INSEE de la commune</a>
|
||||
address_html: Une adresse EXACTEMENT formatée telle que le label retourné par <a href="https://adresse.data.gouv.fr" target="_blank" rel="noopener noreferrer">la Base Adresse Nationale</a>
|
||||
drop_down_list_html: Un choix parmi ceux sélectionnés à la création de la procédure
|
||||
datetime_html: Datetime au format ISO8601
|
||||
date_html: Date au format ISO8601
|
||||
|
@ -144,9 +145,9 @@ fr:
|
|||
rna_html: Un numéro RNA
|
||||
siret_html: Un numéro de SIRET
|
||||
repetition_html: Un tableau de dictionnaires avec les valeurs possibles pour chaque champ de la répétition.
|
||||
epci_html: Un tableau contenant le code de département et <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">celui de l'EPCI</a>.
|
||||
annuaire_education_html: Un code d'établissement scolaire, tel que défini par <a href="https://api.gouv.fr/les-api/api-annuaire-education" target="_blank" rel="noopener noreferrer">l'Annuaire de l'Éducation Nationale</a>
|
||||
dossier_link_html: L'identifiant du dossier, sous forme de nombre entier
|
||||
epci_html: Un tableau contenant le code de département et <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">celui de l'EPCI</a>
|
||||
examples:
|
||||
title: Exemple
|
||||
text: Texte court
|
||||
|
@ -161,6 +162,7 @@ fr:
|
|||
pays: "FR"
|
||||
departements: "56"
|
||||
regions: "53"
|
||||
address: "20 Avenue de Ségur 75007 Paris"
|
||||
date: "2023-02-01"
|
||||
datetime: "2023-02-01T10:30"
|
||||
checkbox: "true"
|
||||
|
|
|
@ -140,6 +140,7 @@ RSpec.describe PrefillParams do
|
|||
it_behaves_like "a champ public value that is authorized", :drop_down_list, "value"
|
||||
it_behaves_like "a champ public value that is authorized", :departements, "03"
|
||||
it_behaves_like "a champ public value that is authorized", :communes, ['01', '01457']
|
||||
it_behaves_like "a champ public value that is authorized", :address, "20 avenue de Ségur 75007 Paris"
|
||||
it_behaves_like "a champ public value that is authorized", :annuaire_education, "0050009H"
|
||||
it_behaves_like "a champ public value that is authorized", :multiple_drop_down_list, ["val1", "val2"]
|
||||
it_behaves_like "a champ public value that is authorized", :dossier_link, "1"
|
||||
|
@ -183,6 +184,7 @@ RSpec.describe PrefillParams do
|
|||
it_behaves_like "a champ private value that is authorized", :siret, "13002526500013"
|
||||
it_behaves_like "a champ private value that is authorized", :departements, "03"
|
||||
it_behaves_like "a champ private value that is authorized", :communes, ['01', '01457']
|
||||
it_behaves_like "a champ private value that is authorized", :address, "20 avenue de Ségur 75007 Paris"
|
||||
it_behaves_like "a champ private value that is authorized", :annuaire_education, "0050009H"
|
||||
it_behaves_like "a champ private value that is authorized", :multiple_drop_down_list, ["val1", "val2"]
|
||||
it_behaves_like "a champ private value that is authorized", :dossier_link, "1"
|
||||
|
@ -220,7 +222,6 @@ RSpec.describe PrefillParams do
|
|||
it_behaves_like "a champ public value that is unauthorized", :pole_emploi, "value"
|
||||
it_behaves_like "a champ public value that is unauthorized", :mesri, "value"
|
||||
it_behaves_like "a champ public value that is unauthorized", :carte, "value"
|
||||
it_behaves_like "a champ public value that is unauthorized", :address, "value"
|
||||
it_behaves_like "a champ public value that is unauthorized", :pays, "value"
|
||||
it_behaves_like "a champ public value that is unauthorized", :regions, "value"
|
||||
it_behaves_like "a champ public value that is unauthorized", :departements, "value"
|
||||
|
|
|
@ -249,6 +249,7 @@ describe TypeDeChamp do
|
|||
it_behaves_like "a prefillable type de champ", :type_de_champ_regions
|
||||
it_behaves_like "a prefillable type de champ", :type_de_champ_departements
|
||||
it_behaves_like "a prefillable type de champ", :type_de_champ_communes
|
||||
it_behaves_like "a prefillable type de champ", :type_de_champ_address
|
||||
it_behaves_like "a prefillable type de champ", :type_de_champ_yes_no
|
||||
it_behaves_like "a prefillable type de champ", :type_de_champ_checkbox
|
||||
it_behaves_like "a prefillable type de champ", :type_de_champ_drop_down_list
|
||||
|
@ -271,7 +272,6 @@ describe TypeDeChamp do
|
|||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_pole_emploi
|
||||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_mesri
|
||||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_carte
|
||||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_address
|
||||
end
|
||||
|
||||
describe '#normalize_libelle' do
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe TypesDeChamp::PrefillAddressTypeDeChamp do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:type_de_champ) { build(:type_de_champ_address, procedure: procedure) }
|
||||
|
||||
describe 'ancestors' do
|
||||
subject { described_class.new(type_de_champ, procedure.active_revision) }
|
||||
|
||||
it { is_expected.to be_kind_of(TypesDeChamp::PrefillTypeDeChamp) }
|
||||
end
|
||||
|
||||
describe '#to_assignable_attributes' do
|
||||
let(:champ) { create(:champ_address, type_de_champ: type_de_champ) }
|
||||
subject { described_class.build(type_de_champ, procedure.active_revision).to_assignable_attributes(champ, value) }
|
||||
|
||||
context 'when the value is nil' do
|
||||
let(:value) { nil }
|
||||
it { is_expected.to match(nil) }
|
||||
end
|
||||
|
||||
context 'when the value is empty' do
|
||||
let(:value) { nil }
|
||||
it { is_expected.to match(nil) }
|
||||
end
|
||||
|
||||
context 'when the value is present' do
|
||||
let(:value) { 'hello' }
|
||||
it { is_expected.to match({ id: champ.id, external_id: 'hello', value: 'hello' }) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,49 +9,55 @@ RSpec.describe TypesDeChamp::PrefillTypeDeChamp, type: :model do
|
|||
describe '.build' do
|
||||
subject(:built) { described_class.build(type_de_champ, procedure.active_revision) }
|
||||
|
||||
context 'when the type de champ is a drop_down_list' do
|
||||
context 'when type de champ is drop_down_list' do
|
||||
let(:type_de_champ) { build(:type_de_champ_drop_down_list, procedure: procedure) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillDropDownListTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a multiple_drop_down_list' do
|
||||
context 'when type de champ is multiple_drop_down_list' do
|
||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, procedure: procedure) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillMultipleDropDownListTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a pays' do
|
||||
context 'when type de champ is pays' do
|
||||
let(:type_de_champ) { build(:type_de_champ_pays, procedure: procedure) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillPaysTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a regions' do
|
||||
context 'when type de champ is regions' do
|
||||
let(:type_de_champ) { build(:type_de_champ_regions, procedure: procedure) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillRegionTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a repetition' do
|
||||
context 'when type de champ is repetition' do
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition, procedure: procedure) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillRepetitionTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a departements' do
|
||||
context 'when type de champ is departements' do
|
||||
let(:type_de_champ) { build(:type_de_champ_departements, procedure: procedure) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillDepartementTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a communes' do
|
||||
context 'when type de champ is communes' do
|
||||
let(:type_de_champ) { build(:type_de_champ_communes) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillCommuneTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a epci' do
|
||||
context 'when type de champ is address' do
|
||||
let(:type_de_champ) { build(:type_de_champ_address) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillAddressTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when type de champ is epci' do
|
||||
let(:type_de_champ) { build(:type_de_champ_epci, procedure: procedure) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillEpciTypeDeChamp) }
|
||||
|
|
|
@ -27,5 +27,6 @@ shared_examples "the user has got a prefilled dossier, owned by themselves" do
|
|||
expect(page).to have_field(type_de_champ_dossier_link.libelle, with: dossier_link_value)
|
||||
expect(page).to have_selector("input[value='Vonnas (01540)']")
|
||||
expect(page).to have_content(annuaire_education_value.last)
|
||||
expect(page).to have_content(address_value.last)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ describe 'Prefilling a dossier (with a GET request):', js: true do
|
|||
let(:type_de_champ_annuaire_education) { create(:type_de_champ_annuaire_education, procedure: procedure) }
|
||||
let(:type_de_champ_dossier_link) { create(:type_de_champ_dossier_link, procedure: procedure) }
|
||||
let(:type_de_champ_commune) { create(:type_de_champ_communes, procedure: procedure) }
|
||||
let(:type_de_champ_address) { create(:type_de_champ_address, procedure: procedure) }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
|
||||
|
||||
let(:text_value) { "My Neighbor Totoro is the best movie ever" }
|
||||
|
@ -32,6 +33,7 @@ describe 'Prefilling a dossier (with a GET request):', js: true do
|
|||
let(:epci_value) { ['01', '200029999'] }
|
||||
let(:dossier_link_value) { '42' }
|
||||
let(:commune_value) { ['01', '01457'] } # Vonnas (01540)
|
||||
let(:address_value) { "20 Avenue de Ségur 75007 Paris" }
|
||||
let(:sub_type_de_champs_repetition) { procedure.active_revision.children_of(type_de_champ_repetition) }
|
||||
let(:text_repetition_libelle) { sub_type_de_champs_repetition.first.libelle }
|
||||
let(:integer_repetition_libelle) { sub_type_de_champs_repetition.second.libelle }
|
||||
|
@ -49,6 +51,7 @@ describe 'Prefilling a dossier (with a GET request):', js: true do
|
|||
"champ_#{type_de_champ_epci.to_typed_id_for_query}" => epci_value,
|
||||
"champ_#{type_de_champ_dossier_link.to_typed_id_for_query}" => dossier_link_value,
|
||||
"champ_#{type_de_champ_commune.to_typed_id_for_query}" => commune_value,
|
||||
"champ_#{type_de_champ_address.to_typed_id_for_query}" => address_value,
|
||||
"champ_#{type_de_champ_siret.to_typed_id_for_query}" => siret_value,
|
||||
"champ_#{type_de_champ_rna.to_typed_id_for_query}" => rna_value,
|
||||
"champ_#{type_de_champ_repetition.to_typed_id_for_query}" => [
|
||||
|
|
|
@ -15,8 +15,9 @@ describe 'Prefilling a dossier (with a POST request):', js: true do
|
|||
let(:type_de_champ_epci) { create(:type_de_champ_epci, procedure: procedure) }
|
||||
let(:type_de_champ_annuaire_education) { create(:type_de_champ_annuaire_education, procedure: procedure) }
|
||||
let(:type_de_champ_dossier_link) { create(:type_de_champ_dossier_link, procedure: procedure) }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
|
||||
let(:type_de_champ_commune) { create(:type_de_champ_communes, procedure: procedure) }
|
||||
let(:type_de_champ_address) { create(:type_de_champ_address, procedure: procedure) }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
|
||||
|
||||
let(:text_value) { "My Neighbor Totoro is the best movie ever" }
|
||||
let(:phone_value) { "invalid phone value" }
|
||||
|
@ -31,6 +32,7 @@ describe 'Prefilling a dossier (with a POST request):', js: true do
|
|||
}
|
||||
let(:epci_value) { ['01', '200029999'] }
|
||||
let(:commune_value) { ['01', '01457'] } # Vonnas (01540)
|
||||
let(:address_value) { "20 Avenue de Ségur 75007 Paris" }
|
||||
let(:sub_type_de_champs_repetition) { procedure.active_revision.children_of(type_de_champ_repetition) }
|
||||
let(:text_repetition_libelle) { sub_type_de_champs_repetition.first.libelle }
|
||||
let(:integer_repetition_libelle) { sub_type_de_champs_repetition.second.libelle }
|
||||
|
@ -163,6 +165,7 @@ describe 'Prefilling a dossier (with a POST request):', js: true do
|
|||
"champ_#{type_de_champ_epci.to_typed_id_for_query}" => epci_value,
|
||||
"champ_#{type_de_champ_dossier_link.to_typed_id_for_query}" => dossier_link_value,
|
||||
"champ_#{type_de_champ_commune.to_typed_id_for_query}" => commune_value,
|
||||
"champ_#{type_de_champ_address.to_typed_id_for_query}" => address_value,
|
||||
"champ_#{type_de_champ_annuaire_education.to_typed_id_for_query}" => annuaire_education_value
|
||||
}.to_json
|
||||
JSON.parse(session.response.body)["dossier_url"].gsub("http://www.example.com", "")
|
||||
|
|
Loading…
Reference in a new issue