Merge pull request #8679 from demarches-simplifiees/prefill/dossier-link
feat(dossier): prefill dossier link champ
This commit is contained in:
commit
568c2f8f4e
11 changed files with 71 additions and 2 deletions
|
@ -21,4 +21,13 @@
|
||||||
# type_de_champ_id :integer
|
# type_de_champ_id :integer
|
||||||
#
|
#
|
||||||
class Champs::DossierLinkChamp < Champ
|
class Champs::DossierLinkChamp < Champ
|
||||||
|
validate :value_integerable, if: -> { value.present? }, on: :prefill
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def value_integerable
|
||||||
|
Integer(value)
|
||||||
|
rescue ArgumentError
|
||||||
|
errors.add(:value, :not_integerable)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,8 @@ class PrefillParams
|
||||||
TypeDeChamp.type_champs.fetch(:regions),
|
TypeDeChamp.type_champs.fetch(:regions),
|
||||||
TypeDeChamp.type_champs.fetch(:departements),
|
TypeDeChamp.type_champs.fetch(:departements),
|
||||||
TypeDeChamp.type_champs.fetch(:multiple_drop_down_list),
|
TypeDeChamp.type_champs.fetch(:multiple_drop_down_list),
|
||||||
TypeDeChamp.type_champs.fetch(:epci)
|
TypeDeChamp.type_champs.fetch(:epci),
|
||||||
|
TypeDeChamp.type_champs.fetch(:dossier_link)
|
||||||
]
|
]
|
||||||
|
|
||||||
attr_reader :champ, :value, :dossier
|
attr_reader :champ, :value, :dossier
|
||||||
|
|
|
@ -273,6 +273,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
TypeDeChamp.type_champs.fetch(:repetition),
|
TypeDeChamp.type_champs.fetch(:repetition),
|
||||||
TypeDeChamp.type_champs.fetch(:multiple_drop_down_list),
|
TypeDeChamp.type_champs.fetch(:multiple_drop_down_list),
|
||||||
TypeDeChamp.type_champs.fetch(:epci),
|
TypeDeChamp.type_champs.fetch(:epci),
|
||||||
|
TypeDeChamp.type_champs.fetch(:dossier_link),
|
||||||
TypeDeChamp.type_champs.fetch(:siret),
|
TypeDeChamp.type_champs.fetch(:siret),
|
||||||
TypeDeChamp.type_champs.fetch(:rna)
|
TypeDeChamp.type_champs.fetch(:rna)
|
||||||
])
|
])
|
||||||
|
|
|
@ -140,6 +140,7 @@ en:
|
||||||
rna_html: A RNA number
|
rna_html: A RNA number
|
||||||
repetition_html: A array of hashes with possible values for each field of the repetition.
|
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>.
|
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>.
|
||||||
|
dossier_link_html: The file ID, as integer.
|
||||||
examples:
|
examples:
|
||||||
title: Example
|
title: Example
|
||||||
text: Short text
|
text: Short text
|
||||||
|
@ -156,6 +157,7 @@ en:
|
||||||
date: "2023-02-01"
|
date: "2023-02-01"
|
||||||
datetime: "2023-02-01T10:30"
|
datetime: "2023-02-01T10:30"
|
||||||
checkbox: "true"
|
checkbox: "true"
|
||||||
|
dossier_link: 42
|
||||||
rna: "W503726238"
|
rna: "W503726238"
|
||||||
siret: "13002526500013"
|
siret: "13002526500013"
|
||||||
prefill_link_title: Prefill link (GET)
|
prefill_link_title: Prefill link (GET)
|
||||||
|
@ -507,6 +509,10 @@ en:
|
||||||
not_in_departement_epci_codes: "must be a valid EPCI code of the matching department"
|
not_in_departement_epci_codes: "must be a valid EPCI code of the matching department"
|
||||||
value:
|
value:
|
||||||
not_in_departement_epci_names: "must be a valid EPCI name of the matching department"
|
not_in_departement_epci_names: "must be a valid EPCI name of the matching department"
|
||||||
|
"champs/dossier_link_champ":
|
||||||
|
attributes:
|
||||||
|
value:
|
||||||
|
not_integerable: "must be an integer"
|
||||||
errors:
|
errors:
|
||||||
format: "Field « %{attribute} » %{message}"
|
format: "Field « %{attribute} » %{message}"
|
||||||
messages:
|
messages:
|
||||||
|
|
|
@ -131,6 +131,7 @@ fr:
|
||||||
siret_html: Un numéro de SIRET
|
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.
|
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>.
|
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>.
|
||||||
|
dossier_link_html: L'identifiant du dossier, sous forme de nombre entier.
|
||||||
examples:
|
examples:
|
||||||
title: Exemple
|
title: Exemple
|
||||||
text: Texte court
|
text: Texte court
|
||||||
|
@ -148,6 +149,7 @@ fr:
|
||||||
date: "2023-02-01"
|
date: "2023-02-01"
|
||||||
datetime: "2023-02-01T10:30"
|
datetime: "2023-02-01T10:30"
|
||||||
checkbox: "true"
|
checkbox: "true"
|
||||||
|
dossier_link: 42
|
||||||
rna: "W503726238"
|
rna: "W503726238"
|
||||||
siret: "13002526500013"
|
siret: "13002526500013"
|
||||||
prefill_link_title: Lien de préremplissage (GET)
|
prefill_link_title: Lien de préremplissage (GET)
|
||||||
|
@ -502,6 +504,10 @@ fr:
|
||||||
not_in_departement_epci_codes: "doit être un code d'EPCI du département correspondant"
|
not_in_departement_epci_codes: "doit être un code d'EPCI du département correspondant"
|
||||||
value:
|
value:
|
||||||
not_in_departement_epci_names: "doit être un nom d'EPCI du département correspondant"
|
not_in_departement_epci_names: "doit être un nom d'EPCI du département correspondant"
|
||||||
|
"champs/dossier_link_champ":
|
||||||
|
attributes:
|
||||||
|
value:
|
||||||
|
not_integerable: "doit être un entier"
|
||||||
errors:
|
errors:
|
||||||
format: "Le champ « %{attribute} » %{message}"
|
format: "Le champ « %{attribute} » %{message}"
|
||||||
messages:
|
messages:
|
||||||
|
|
37
spec/models/champs/dossier_link_champ_spec.rb
Normal file
37
spec/models/champs/dossier_link_champ_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
describe Champs::DossierLinkChamp, type: :model do
|
||||||
|
describe 'prefilling validations' do
|
||||||
|
describe 'value' do
|
||||||
|
subject { build(:champ_dossier_link, value: value).valid?(:prefill) }
|
||||||
|
|
||||||
|
context 'when nil' do
|
||||||
|
let(:value) { nil }
|
||||||
|
|
||||||
|
it { expect(subject).to eq(true) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when empty' do
|
||||||
|
let(:value) { '' }
|
||||||
|
|
||||||
|
it { expect(subject).to eq(true) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when an integer' do
|
||||||
|
let(:value) { 42 }
|
||||||
|
|
||||||
|
it { expect(subject).to eq(true) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when a string representing an integer' do
|
||||||
|
let(:value) { "42" }
|
||||||
|
|
||||||
|
it { expect(subject).to eq(true) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when it can be casted as integer' do
|
||||||
|
let(:value) { 'totoro' }
|
||||||
|
|
||||||
|
it { expect(subject).to eq(false) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -141,6 +141,7 @@ RSpec.describe PrefillParams do
|
||||||
it_behaves_like "a champ public value that is authorized", :departements, "03"
|
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", :communes, ['01', '01457']
|
||||||
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", :multiple_drop_down_list, ["val1", "val2"]
|
||||||
|
it_behaves_like "a champ public value that is authorized", :dossier_link, "1"
|
||||||
it_behaves_like "a champ public value that is authorized", :epci, ['01', '200042935']
|
it_behaves_like "a champ public value that is authorized", :epci, ['01', '200042935']
|
||||||
it_behaves_like "a champ public value that is authorized", :siret, "13002526500013"
|
it_behaves_like "a champ public value that is authorized", :siret, "13002526500013"
|
||||||
it_behaves_like "a champ public value that is authorized", :rna, "value"
|
it_behaves_like "a champ public value that is authorized", :rna, "value"
|
||||||
|
@ -182,6 +183,7 @@ RSpec.describe PrefillParams do
|
||||||
it_behaves_like "a champ private value that is authorized", :departements, "03"
|
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", :communes, ['01', '01457']
|
||||||
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", :multiple_drop_down_list, ["val1", "val2"]
|
||||||
|
it_behaves_like "a champ private value that is authorized", :dossier_link, "1"
|
||||||
it_behaves_like "a champ private value that is authorized", :epci, ['01', '200042935']
|
it_behaves_like "a champ private value that is authorized", :epci, ['01', '200042935']
|
||||||
|
|
||||||
context "when the private type de champ is authorized (repetition)" do
|
context "when the private type de champ is authorized (repetition)" do
|
||||||
|
|
|
@ -255,11 +255,11 @@ describe TypeDeChamp do
|
||||||
it_behaves_like "a prefillable type de champ", :type_de_champ_repetition
|
it_behaves_like "a prefillable type de champ", :type_de_champ_repetition
|
||||||
it_behaves_like "a prefillable type de champ", :type_de_champ_multiple_drop_down_list
|
it_behaves_like "a prefillable type de champ", :type_de_champ_multiple_drop_down_list
|
||||||
it_behaves_like "a prefillable type de champ", :type_de_champ_epci
|
it_behaves_like "a prefillable type de champ", :type_de_champ_epci
|
||||||
|
it_behaves_like "a prefillable type de champ", :type_de_champ_dossier_link
|
||||||
it_behaves_like "a prefillable type de champ", :type_de_champ_siret
|
it_behaves_like "a prefillable type de champ", :type_de_champ_siret
|
||||||
it_behaves_like "a prefillable type de champ", :type_de_champ_rna
|
it_behaves_like "a prefillable type de champ", :type_de_champ_rna
|
||||||
|
|
||||||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_number
|
it_behaves_like "a non-prefillable type de champ", :type_de_champ_number
|
||||||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_dossier_link
|
|
||||||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_titre_identite
|
it_behaves_like "a non-prefillable type de champ", :type_de_champ_titre_identite
|
||||||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_linked_drop_down_list
|
it_behaves_like "a non-prefillable type de champ", :type_de_champ_linked_drop_down_list
|
||||||
it_behaves_like "a non-prefillable type de champ", :type_de_champ_header_section
|
it_behaves_like "a non-prefillable type de champ", :type_de_champ_header_section
|
||||||
|
|
|
@ -24,6 +24,7 @@ shared_examples "the user has got a prefilled dossier, owned by themselves" do
|
||||||
expect(page).to have_content(multiple_drop_down_list_values.first)
|
expect(page).to have_content(multiple_drop_down_list_values.first)
|
||||||
expect(page).to have_content(multiple_drop_down_list_values.last)
|
expect(page).to have_content(multiple_drop_down_list_values.last)
|
||||||
expect(page).to have_field(type_de_champ_epci.libelle, with: epci_value.last)
|
expect(page).to have_field(type_de_champ_epci.libelle, with: epci_value.last)
|
||||||
|
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_selector("input[value='Vonnas (01540)']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,7 @@ describe 'Prefilling a dossier (with a GET request):', js: true do
|
||||||
let(:type_de_champ_datetime) { create(:type_de_champ_datetime, procedure: procedure) }
|
let(:type_de_champ_datetime) { create(:type_de_champ_datetime, procedure: procedure) }
|
||||||
let(:type_de_champ_multiple_drop_down_list) { create(:type_de_champ_multiple_drop_down_list, procedure: procedure) }
|
let(:type_de_champ_multiple_drop_down_list) { create(:type_de_champ_multiple_drop_down_list, procedure: procedure) }
|
||||||
let(:type_de_champ_epci) { create(:type_de_champ_epci, procedure: procedure) }
|
let(:type_de_champ_epci) { create(:type_de_champ_epci, 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_commune) { create(:type_de_champ_communes, procedure: procedure) }
|
||||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
|
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ describe 'Prefilling a dossier (with a GET request):', js: true do
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
let(:epci_value) { ['01', '200029999'] }
|
let(:epci_value) { ['01', '200029999'] }
|
||||||
|
let(:dossier_link_value) { '42' }
|
||||||
let(:commune_value) { ['01', '01457'] } # Vonnas (01540)
|
let(:commune_value) { ['01', '01457'] } # Vonnas (01540)
|
||||||
let(:sub_type_de_champs_repetition) { procedure.active_revision.children_of(type_de_champ_repetition) }
|
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(:text_repetition_libelle) { sub_type_de_champs_repetition.first.libelle }
|
||||||
|
@ -43,6 +45,7 @@ describe 'Prefilling a dossier (with a GET request):', js: true do
|
||||||
"champ_#{type_de_champ_datetime.to_typed_id_for_query}" => datetime_value,
|
"champ_#{type_de_champ_datetime.to_typed_id_for_query}" => datetime_value,
|
||||||
"champ_#{type_de_champ_multiple_drop_down_list.to_typed_id_for_query}" => multiple_drop_down_list_values,
|
"champ_#{type_de_champ_multiple_drop_down_list.to_typed_id_for_query}" => multiple_drop_down_list_values,
|
||||||
"champ_#{type_de_champ_epci.to_typed_id_for_query}" => epci_value,
|
"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_commune.to_typed_id_for_query}" => commune_value,
|
||||||
"champ_#{type_de_champ_siret.to_typed_id_for_query}" => siret_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_rna.to_typed_id_for_query}" => rna_value,
|
||||||
|
|
|
@ -13,6 +13,7 @@ describe 'Prefilling a dossier (with a POST request):', js: true do
|
||||||
let(:type_de_champ_datetime) { create(:type_de_champ_datetime, procedure: procedure) }
|
let(:type_de_champ_datetime) { create(:type_de_champ_datetime, procedure: procedure) }
|
||||||
let(:type_de_champ_multiple_drop_down_list) { create(:type_de_champ_multiple_drop_down_list, procedure: procedure) }
|
let(:type_de_champ_multiple_drop_down_list) { create(:type_de_champ_multiple_drop_down_list, procedure: procedure) }
|
||||||
let(:type_de_champ_epci) { create(:type_de_champ_epci, procedure: procedure) }
|
let(:type_de_champ_epci) { create(:type_de_champ_epci, 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_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_commune) { create(:type_de_champ_communes, procedure: procedure) }
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ describe 'Prefilling a dossier (with a POST request):', js: true do
|
||||||
let(:integer_repetition_libelle) { sub_type_de_champs_repetition.second.libelle }
|
let(:integer_repetition_libelle) { sub_type_de_champs_repetition.second.libelle }
|
||||||
let(:text_repetition_value) { "First repetition text" }
|
let(:text_repetition_value) { "First repetition text" }
|
||||||
let(:integer_repetition_value) { "42" }
|
let(:integer_repetition_value) { "42" }
|
||||||
|
let(:dossier_link_value) { '42' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(Rails).to receive(:cache).and_return(memory_store)
|
allow(Rails).to receive(:cache).and_return(memory_store)
|
||||||
|
@ -157,6 +159,7 @@ describe 'Prefilling a dossier (with a POST request):', js: true do
|
||||||
"champ_#{type_de_champ_datetime.to_typed_id_for_query}" => datetime_value,
|
"champ_#{type_de_champ_datetime.to_typed_id_for_query}" => datetime_value,
|
||||||
"champ_#{type_de_champ_multiple_drop_down_list.to_typed_id_for_query}" => multiple_drop_down_list_values,
|
"champ_#{type_de_champ_multiple_drop_down_list.to_typed_id_for_query}" => multiple_drop_down_list_values,
|
||||||
"champ_#{type_de_champ_epci.to_typed_id_for_query}" => epci_value,
|
"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_commune.to_typed_id_for_query}" => commune_value
|
||||||
}.to_json
|
}.to_json
|
||||||
JSON.parse(session.response.body)["dossier_url"].gsub("http://www.example.com", "")
|
JSON.parse(session.response.body)["dossier_url"].gsub("http://www.example.com", "")
|
||||||
|
|
Loading…
Reference in a new issue