Fix format prefill repetition

This commit is contained in:
Damien Le Thiec 2023-02-22 19:32:25 +01:00
parent cc2ec995d6
commit fbe4fe251a
16 changed files with 91 additions and 98 deletions

View file

@ -22,4 +22,8 @@ class ApplicationRecord < ActiveRecord::Base
def to_typed_id
GraphQL::Schema::UniqueWithinType.encode(self.class.name, id)
end
def to_typed_id_for_query
to_typed_id.delete("==")
end
end

View file

@ -72,7 +72,7 @@ class Champ < ApplicationRecord
:refresh_after_update?,
to: :type_de_champ
delegate :to_typed_id, to: :type_de_champ, prefix: true
delegate :to_typed_id, :to_typed_id_for_query, to: :type_de_champ, prefix: true
delegate :revision, to: :dossier, prefix: true

View file

@ -13,3 +13,14 @@ module DossierPrefillableConcern
save(validate: false)
end
end
# Pour être sûr de bien être alignés, on veut bien les format suivants ?
# En POST, je prends un hash classique et je lui fais to_json
# Pour ton exemple ça donne: "{\"champ_id1\":\"text\",\"champ_id2\":[\"option1\",\"option2\"],\"champ_id3\":[{\"champ_id4\":\"text\",\"champ_id5\":true,\"champ_id6\":42,\"champ_id7\":[\"option1\",\"option2\"]},{\"champ_id4\":\"text2\",\"champ_id6\":32}]}"
# En GET, je prends un hash et je lui applique to_query
# Pour ton exemple, et en escapant les caractères spéciaux: "champ_id1=text&champ_id2[]=option1&champ_id2[]=option2&champ_id3[][champ_id4]=text&champ_id3[][champ_id5]=true&champ_id3[][champ_id6]=42&champ_id3[][champ_id7][]=option1&champ_id3[][champ_id7][]=option2&champ_id3[][champ_id4]=text2&champ_id3[][champ_id6]=32"
#Tu confirmes ? Je préfère checker car c'est un tout petit peu différent de ton exemple

View file

@ -27,7 +27,7 @@ class PrefillDescription < SimpleDelegator
end
def prefill_link
@prefill_link ||= commencer_url({ path: path }.merge(prefilled_champs_for_link))
@prefill_link ||= CGI.unescape(commencer_url({ path: path }.merge(prefilled_champs_as_params)))
end
def prefill_query
@ -35,7 +35,7 @@ class PrefillDescription < SimpleDelegator
<<~TEXT
curl --request POST '#{api_public_v1_dossiers_url(self)}' \\
--header 'Content-Type: application/json' \\
--data '{#{prefilled_champs_for_query}}'
--data '#{prefilled_champs_as_params.to_json}'
TEXT
end
@ -49,29 +49,7 @@ class PrefillDescription < SimpleDelegator
active_revision.types_de_champ_public.fillable
end
def prefilled_champs_for_link
prefilled_champs_as_params.map(&:to_a).to_h
end
def prefilled_champs_for_query
prefilled_champs_as_params.map(&:to_s).join(', ')
end
def prefilled_champs_as_params
prefilled_champs.map { |type_de_champ| Param.new(type_de_champ.to_typed_id, type_de_champ.example_value) }
end
Param = Struct.new(:key, :value) do
def to_a
["champ_#{key}", value]
end
def to_s
if value.is_a?(Array)
"\"champ_#{key}\": #{value}"
else
"\"champ_#{key}\": \"#{value}\""
end
end
prefilled_champs.map { |type_de_champ| ["champ_#{type_de_champ.to_typed_id_for_query}", type_de_champ.example_value] }.to_h
end
end

View file

@ -10,7 +10,7 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh
end
def example_value
[row_values_format, row_values_format].map { |row| row.to_s.gsub("=>", ":") }
[row_values_format, row_values_format]
end
def to_assignable_attributes(champ, value)
@ -25,14 +25,14 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh
def subchamps_all_possible_values
"<ul>" + prefillable_subchamps.map do |prefill_type_de_champ|
"<li>#{prefill_type_de_champ.to_typed_id}: #{prefill_type_de_champ.possible_values}</li>"
"<li>champ_#{prefill_type_de_champ.to_typed_id_for_query}: #{prefill_type_de_champ.possible_values}</li>"
end.join + "</ul>"
end
def row_values_format
@row_example_value ||=
prefillable_subchamps.map do |prefill_type_de_champ|
[prefill_type_de_champ.to_typed_id, prefill_type_de_champ.example_value.to_s]
["champ_#{prefill_type_de_champ.to_typed_id_for_query}", prefill_type_de_champ.example_value.to_s]
end.to_h
end
@ -52,14 +52,17 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh
end
def to_assignable_attributes
return unless repetition.is_a?(Hash)
row = champ.rows[index] || champ.add_row(champ.dossier_revision)
JSON.parse(repetition).map do |key, value|
subchamp = row.find { |champ| champ.type_de_champ_to_typed_id == key }
repetition.map do |key, value|
next unless key.is_a?(String) && key.starts_with?("champ_")
subchamp = row.find { |champ| champ.type_de_champ_to_typed_id_for_query == key.split("_").last }
next unless subchamp
TypesDeChamp::PrefillTypeDeChamp.build(subchamp.type_de_champ, revision).to_assignable_attributes(subchamp, value)
rescue JSON::ParserError # On ignore les valeurs qu'on n'arrive pas à parser
end.compact
end
end

View file

@ -27,7 +27,7 @@
%th
= t("views.prefill_descriptions.edit.champ_id")
%td
= type_de_champ.to_typed_id
= type_de_champ.to_typed_id_for_query
%tr
%th
= t("views.prefill_descriptions.edit.champ_type")

View file

@ -15,7 +15,7 @@
%th
= t("views.prefill_descriptions.edit.champ_id")
%td
= @type_de_champ.to_typed_id
= @type_de_champ.to_typed_id_for_query
%tr
%th
= t("views.prefill_descriptions.edit.champ_type")

View file

@ -50,8 +50,8 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do
let(:params) {
{
id: procedure.id,
"champ_#{type_de_champ_1.to_typed_id}" => value_1,
"champ_#{type_de_champ_2.to_typed_id}" => value_2
"champ_#{type_de_champ_1.to_typed_id_for_query}" => value_1,
"champ_#{type_de_champ_2.to_typed_id_for_query}" => value_2
}
}

View file

@ -67,24 +67,19 @@ describe PrefillDescriptionsController, type: :controller do
it { expect(response).to render_template(:update) }
it "includes the prefill URL" do
type_de_champ_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
type_de_champ_to_add_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_add.type_champ}")
expect(response.body).to include(commencer_path(path: procedure.path))
expect(response.body).to include(
{
"champ_#{type_de_champ.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
}.to_query
)
expect(response.body).to include({
"champ_#{type_de_champ_to_add.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_add.type_champ}")
}.to_query)
expect(response.body).to include("champ_#{type_de_champ.to_typed_id_for_query}=#{type_de_champ_value}")
expect(response.body).to include("champ_#{type_de_champ_to_add.to_typed_id_for_query}=#{type_de_champ_to_add_value}")
end
it "includes the prefill query" do
type_de_champ_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
type_de_champ_to_add_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_add.type_champ}")
expect(response.body).to include(api_public_v1_dossiers_path(procedure))
expect(response.body).to include(
"&quot;champ_#{type_de_champ.to_typed_id}&quot;: &quot;#{type_de_champ_value}&quot;, &quot;champ_#{type_de_champ_to_add.to_typed_id}&quot;: &quot;#{type_de_champ_to_add_value}&quot"
"&quot;champ_#{type_de_champ.to_typed_id_for_query}&quot;:&quot;#{type_de_champ_value}&quot;,&quot;champ_#{type_de_champ_to_add.to_typed_id_for_query}&quot;:&quot;#{type_de_champ_to_add_value}&quot"
)
end
end
@ -96,13 +91,11 @@ describe PrefillDescriptionsController, type: :controller do
it { expect(response).to render_template(:update) }
it "includes the prefill URL" do
type_de_champ_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
type_de_champ_to_remove_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_remove.type_champ}")
expect(response.body).to include(commencer_path(path: procedure.path))
expect(response.body).to include({
"champ_#{type_de_champ.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
}.to_query)
expect(response.body).not_to include({
"champ_#{type_de_champ_to_remove.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_remove.type_champ}")
}.to_query)
expect(response.body).to include("champ_#{type_de_champ.to_typed_id_for_query}=#{type_de_champ_value}")
expect(response.body).not_to include("champ_#{type_de_champ_to_remove.to_typed_id_for_query}=#{type_de_champ_to_remove_value}")
end
it "includes the prefill query" do
@ -111,10 +104,10 @@ describe PrefillDescriptionsController, type: :controller do
expect(response.body).to include(api_public_v1_dossiers_path(procedure))
expect(response.body).to include(
"&quot;champ_#{type_de_champ.to_typed_id}&quot;: &quot;#{type_de_champ_value}&quot;"
"&quot;champ_#{type_de_champ.to_typed_id_for_query}&quot;:&quot;#{type_de_champ_value}&quot;"
)
expect(response.body).not_to include(
"&quot;champ_#{type_de_champ_to_remove.to_typed_id}&quot;: &quot;#{type_de_champ_to_remove_value}&quot;"
"&quot;champ_#{type_de_champ_to_remove.to_typed_id_for_query}&quot;:&quot;#{type_de_champ_to_remove_value}&quot;"
)
end
end

View file

@ -1077,8 +1077,8 @@ describe Users::DossiersController, type: :controller do
let(:params) {
{
procedure_id: procedure_id,
"champ_#{type_de_champ_1.to_typed_id}" => value_1,
"champ_#{type_de_champ_2.to_typed_id}" => value_2
"champ_#{type_de_champ_1.to_typed_id_for_query}" => value_1,
"champ_#{type_de_champ_2.to_typed_id_for_query}" => value_2
}
}

View file

@ -114,11 +114,13 @@ RSpec.describe PrefillDescription, type: :model do
it "builds the URL to create a new prefilled dossier" do
expect(prefill_description.prefill_link).to eq(
commencer_url(
path: procedure.path,
"champ_#{type_de_champ_text.to_typed_id}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_text, procedure.active_revision).example_value,
"champ_#{type_de_champ_epci.to_typed_id}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_epci, procedure.active_revision).example_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_repetition, procedure.active_revision).example_value
CGI.unescape(
commencer_url(
path: procedure.path,
"champ_#{type_de_champ_text.to_typed_id_for_query}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_text, procedure.active_revision).example_value,
"champ_#{type_de_champ_epci.to_typed_id_for_query}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_epci, procedure.active_revision).example_value,
"champ_#{type_de_champ_repetition.to_typed_id_for_query}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_repetition, procedure.active_revision).example_value
)
)
)
end
@ -130,13 +132,15 @@ RSpec.describe PrefillDescription, type: :model do
let(:type_de_champ_epci) { TypesDeChamp::PrefillTypeDeChamp.build(create(:type_de_champ_epci, procedure: procedure), procedure.active_revision) }
let(:type_de_champ_repetition) { build(:type_de_champ_repetition, :with_types_de_champ, :with_region_types_de_champ, procedure: procedure) }
let(:prefillable_subchamps) { TypesDeChamp::PrefillRepetitionTypeDeChamp.new(type_de_champ_repetition, procedure.active_revision).send(:prefillable_subchamps) }
let(:text_repetition) { prefillable_subchamps.first }
let(:integer_repetition) { prefillable_subchamps.second }
let(:region_repetition) { prefillable_subchamps.third }
let(:prefill_description) { described_class.new(procedure) }
let(:expected_query) do
<<~TEXT
curl --request POST '#{api_public_v1_dossiers_url(procedure)}' \\
--header 'Content-Type: application/json' \\
--data '{"champ_#{type_de_champ_text.to_typed_id}": "#{TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_text, procedure.active_revision).example_value}", "champ_#{type_de_champ_epci.to_typed_id}": #{TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_epci, procedure.active_revision).example_value}, "champ_#{type_de_champ_repetition.to_typed_id}": #{TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_repetition, procedure.active_revision).example_value}}'
--data '{"champ_#{type_de_champ_text.to_typed_id_for_query}":"Texte court","champ_#{type_de_champ_epci.to_typed_id_for_query}":["01","200042935"],"champ_#{type_de_champ_repetition.to_typed_id_for_query}":[{"champ_#{text_repetition.to_typed_id_for_query}":"Texte court","champ_#{integer_repetition.to_typed_id_for_query}":"42","champ_#{region_repetition.to_typed_id_for_query}":"53"},{"champ_#{text_repetition.to_typed_id_for_query}":"Texte court","champ_#{integer_repetition.to_typed_id_for_query}":"42","champ_#{region_repetition.to_typed_id_for_query}":"53"}]}'
TEXT
end

View file

@ -36,8 +36,8 @@ RSpec.describe PrefillParams do
let(:params) {
{
"champ_#{type_de_champ_1.to_typed_id}" => value_1,
"champ_#{type_de_champ_2.to_typed_id}" => value_2
"champ_#{type_de_champ_1.to_typed_id_for_query}" => value_1,
"champ_#{type_de_champ_2.to_typed_id_for_query}" => value_2
}
}
@ -53,7 +53,7 @@ RSpec.describe PrefillParams do
let(:type_de_champ) { procedure.published_revision.types_de_champ_public.first }
let(:types_de_champ_public) { [{ type: :text }] }
let(:params) { { type_de_champ.to_typed_id => "value" } }
let(:params) { { type_de_champ.to_typed_id_for_query => "value" } }
it "filters out the champ" do
expect(prefill_params_array).to match([])
@ -71,7 +71,7 @@ RSpec.describe PrefillParams do
context 'when there is no Champ that matches the TypeDeChamp with the given stable id' do
let!(:type_de_champ) { create(:type_de_champ_text) } # goes to another procedure
let(:params) { { "champ_#{type_de_champ.to_typed_id}" => "value" } }
let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => "value" } }
it "filters out the param" do
expect(prefill_params_array).to match([])
@ -84,7 +84,7 @@ RSpec.describe PrefillParams do
let(:type_de_champ) { procedure.published_revision.types_de_champ_public.first }
let(:champ) { find_champ_by_stable_id(dossier, type_de_champ.stable_id) }
let(:params) { { "champ_#{type_de_champ.to_typed_id}" => value } }
let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => value } }
it "builds an array of hash matching the given params" do
expect(prefill_params_array).to match([{ id: champ.id }.merge(attributes(champ, value))])
@ -98,7 +98,7 @@ RSpec.describe PrefillParams do
let(:type_de_champ) { procedure.published_revision.types_de_champ_private.first }
let(:champ) { find_champ_by_stable_id(dossier, type_de_champ.stable_id) }
let(:params) { { "champ_#{type_de_champ.to_typed_id}" => value } }
let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => value } }
it "builds an array of hash matching the given params" do
expect(prefill_params_array).to match([{ id: champ.id }.merge(attributes(champ, value))])
@ -110,7 +110,7 @@ RSpec.describe PrefillParams do
let(:types_de_champ_public) { [{ type: type_de_champ_type }] }
let(:type_de_champ) { procedure.published_revision.types_de_champ_public.first }
let(:params) { { "champ_#{type_de_champ.to_typed_id}" => value } }
let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => value } }
context "when the type de champ is unauthorized (#{type_de_champ_type})" do
it "filters out the param" do
@ -147,7 +147,7 @@ RSpec.describe PrefillParams do
let(:type_de_champ_child_value) { "value" }
let(:type_de_champ_child_value2) { "value2" }
let(:params) { { "champ_#{type_de_champ.to_typed_id}" => ["{\"#{type_de_champ_child.to_typed_id}\":\"#{type_de_champ_child_value}\"}", "{\"#{type_de_champ_child.to_typed_id}\":\"#{type_de_champ_child_value2}\"}"] } }
let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => [{"champ_#{type_de_champ_child.to_typed_id_for_query}"=> type_de_champ_child_value}, {"champ_#{type_de_champ_child.to_typed_id_for_query}"=> type_de_champ_child_value2 }] } }
it "builds an array of hash(id, value) matching the given params" do
expect(prefill_params_array).to match([{ id: type_de_champ_child.champ.first.id, value: type_de_champ_child_value }, { id: type_de_champ_child.champ.second.id, value: type_de_champ_child_value2 }])
@ -183,7 +183,7 @@ RSpec.describe PrefillParams do
let(:type_de_champ_child_value) { "value" }
let(:type_de_champ_child_value2) { "value2" }
let(:params) { { "champ_#{type_de_champ.to_typed_id}" => ["{\"#{type_de_champ_child.to_typed_id}\":\"#{type_de_champ_child_value}\"}", "{\"#{type_de_champ_child.to_typed_id}\":\"#{type_de_champ_child_value2}\"}"] } }
let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => [{"champ_#{type_de_champ_child.to_typed_id_for_query}" => type_de_champ_child_value}, {"champ_#{type_de_champ_child.to_typed_id_for_query}" => type_de_champ_child_value2}] } }
it "builds an array of hash(id, value) matching the given params" do
expect(prefill_params_array).to match([{ id: type_de_champ_child.champ.first.id, value: type_de_champ_child_value }, { id: type_de_champ_child.champ.second.id, value: type_de_champ_child_value2 }])
@ -223,7 +223,7 @@ RSpec.describe PrefillParams do
let(:type_de_champ) { procedure.published_revision.types_de_champ_public.first }
let(:type_de_champ_child) { procedure.published_revision.children_of(type_de_champ).first }
let(:params) { { "champ_#{type_de_champ.to_typed_id}" => "value" } }
let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => "value" } }
it "builds an array of hash(id, value) matching the given params" do
expect(prefill_params_array).to match([])
@ -235,7 +235,7 @@ RSpec.describe PrefillParams do
let(:type_de_champ) { procedure.published_revision.types_de_champ_public.first }
let(:type_de_champ_child) { procedure.published_revision.children_of(type_de_champ).first }
let(:params) { { "champ_#{type_de_champ.to_typed_id}" => ["{\"wrong\":\"value\"}", "{\"wrong\":\"value2\"}"] } }
let(:params) { { "champ_#{type_de_champ.to_typed_id_for_query}" => ["{\"wrong\":\"value\"}", "{\"wrong\":\"value2\"}"] } }
it "builds an array of hash(id, value) matching the given params" do
expect(prefill_params_array).to match([])

View file

@ -24,7 +24,7 @@ RSpec.describe TypesDeChamp::PrefillRepetitionTypeDeChamp, type: :model, vcr: {
describe '#possible_values' do
subject(:possible_values) { described_class.new(type_de_champ, procedure.active_revision).possible_values }
let(:expected_value) {
"Un tableau de dictionnaires avec les valeurs possibles pour chaque champ de la répétition.</br><ul><li>#{text_repetition.to_typed_id}: Un texte court<br></li><li>#{integer_repetition.to_typed_id}: Un nombre entier<br></li><li>#{region_repetition.to_typed_id}: 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><br><a title=\"Toutes les valeurs possibles — Nouvel onglet\" target=\"_blank\" rel=\"noopener noreferrer\" href=\"/procedures/#{procedure.path}/prefill_type_de_champs/#{region_repetition.id}\">Voir toutes les valeurs possibles</a></li></ul>"
"Un tableau de dictionnaires avec les valeurs possibles pour chaque champ de la répétition.</br><ul><li>champ_#{text_repetition.to_typed_id_for_query}: Un texte court<br></li><li>champ_#{integer_repetition.to_typed_id_for_query}: Un nombre entier<br></li><li>champ_#{region_repetition.to_typed_id_for_query}: 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><br><a title=\"Toutes les valeurs possibles — Nouvel onglet\" target=\"_blank\" rel=\"noopener noreferrer\" href=\"/procedures/#{procedure.path}/prefill_type_de_champs/#{region_repetition.id}\">Voir toutes les valeurs possibles</a></li></ul>"
}
it {
@ -34,7 +34,7 @@ RSpec.describe TypesDeChamp::PrefillRepetitionTypeDeChamp, type: :model, vcr: {
describe '#example_value' do
subject(:example_value) { described_class.new(type_de_champ, procedure.active_revision).example_value }
let(:expected_value) { ["{\"#{text_repetition.to_typed_id}\":\"Texte court\", \"#{integer_repetition.to_typed_id}\":\"42\", \"#{region_repetition.to_typed_id}\":\"53\"}", "{\"#{text_repetition.to_typed_id}\":\"Texte court\", \"#{integer_repetition.to_typed_id}\":\"42\", \"#{region_repetition.to_typed_id}\":\"53\"}"] }
let(:expected_value) { [{"champ_#{text_repetition.to_typed_id_for_query}" => "Texte court", "champ_#{integer_repetition.to_typed_id_for_query}" => "42", "champ_#{region_repetition.to_typed_id_for_query}" => "53"}, {"champ_#{text_repetition.to_typed_id_for_query}" => "Texte court", "champ_#{integer_repetition.to_typed_id_for_query}" => "42", "champ_#{region_repetition.to_typed_id_for_query}" => "53"}] }
it { expect(example_value).to eq(expected_value) }
end
@ -64,13 +64,13 @@ RSpec.describe TypesDeChamp::PrefillRepetitionTypeDeChamp, type: :model, vcr: {
end
context 'when the value is an array with some wrong keys' do
let(:value) { ["{\"#{text_repetition.to_typed_id}\":\"value\", \"blabla\":\"value2\"}", "{\"#{integer_repetition.to_typed_id}\":\"value3\"}", "{\"blabla\":\"false\"}"] }
let(:value) { [{"champ_#{text_repetition.to_typed_id_for_query}" => "value", "blabla" => "value2"}, {"champ_#{integer_repetition.to_typed_id_for_query}" => "value3"}, {"blabla" =>"false"}] }
it { is_expected.to match([[{ id: text_repetition.champ.first.id, value: "value" }], [{ id: integer_repetition.champ.second.id, value: "value3" }]]) }
end
context 'when the value is an array with right keys' do
let(:value) { ["{\"#{text_repetition.to_typed_id}\":\"value\"}", "{\"#{text_repetition.to_typed_id}\":\"value2\"}"] }
let(:value) { [{"champ_#{text_repetition.to_typed_id_for_query}" =>"value"}, {"champ_#{text_repetition.to_typed_id_for_query}" => "value2"}] }
it { is_expected.to match([[{ id: text_repetition.champ.first.id, value: "value" }], [{ id: text_repetition.champ.second.id, value: "value2" }]]) }
end

View file

@ -5,7 +5,7 @@ describe 'As an integrator:', js: true do
before { visit "/preremplir/#{procedure.path}" }
scenario 'I can read the procedure prefilling (aka public champs)' do
expect(page).to have_content(type_de_champ.to_typed_id)
expect(page).to have_content(type_de_champ.to_typed_id_for_query)
expect(page).to have_content(I18n.t("activerecord.attributes.type_de_champ.type_champs.#{type_de_champ.type_champ}"))
expect(page).to have_content(type_de_champ.libelle)
expect(page).to have_content(type_de_champ.description)

View file

@ -31,16 +31,16 @@ describe 'Prefilling a dossier (with a GET request):' do
let(:entry_path) {
commencer_path(
path: procedure.path,
"champ_#{type_de_champ_text.to_typed_id}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_datetime.to_typed_id}" => datetime_value,
"champ_#{type_de_champ_multiple_drop_down_list.to_typed_id}" => multiple_drop_down_list_values,
"champ_#{type_de_champ_epci.to_typed_id}" => epci_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => [
"{
\"#{sub_type_de_champs_repetition.first.to_typed_id}\": \"#{text_repetition_value}\",
\"#{sub_type_de_champs_repetition.second.to_typed_id}\": \"#{integer_repetition_value}\"
}"
"champ_#{type_de_champ_text.to_typed_id_for_query}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id_for_query}" => phone_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_epci.to_typed_id_for_query}" => epci_value,
"champ_#{type_de_champ_repetition.to_typed_id_for_query}" => [
{
"champ_#{sub_type_de_champs_repetition.first.to_typed_id_for_query}": text_repetition_value,
"champ_#{sub_type_de_champs_repetition.second.to_typed_id_for_query}": integer_repetition_value
}
]
)
}

View file

@ -126,17 +126,17 @@ describe 'Prefilling a dossier (with a POST request):' do
session.post api_public_v1_dossiers_path(procedure),
headers: { "Content-Type" => "application/json" },
params: {
"champ_#{type_de_champ_text.to_typed_id}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => [
"{
\"#{sub_type_de_champs_repetition.first.to_typed_id}\": \"#{text_repetition_value}\",
\"#{sub_type_de_champs_repetition.second.to_typed_id}\": \"#{integer_repetition_value}\"
}"
"champ_#{type_de_champ_text.to_typed_id_for_query}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id_for_query}" => phone_value,
"champ_#{type_de_champ_repetition.to_typed_id_for_query}" => [
{
"champ_#{sub_type_de_champs_repetition.first.to_typed_id_for_query}": text_repetition_value,
"champ_#{sub_type_de_champs_repetition.second.to_typed_id_for_query}": integer_repetition_value
}
],
"champ_#{type_de_champ_datetime.to_typed_id}" => datetime_value,
"champ_#{type_de_champ_multiple_drop_down_list.to_typed_id}" => multiple_drop_down_list_values,
"champ_#{type_de_champ_epci.to_typed_id}" => epci_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_epci.to_typed_id_for_query}" => epci_value
}.to_json
JSON.parse(session.response.body)["dossier_url"].gsub("http://www.example.com", "")
end