This commit is contained in:
Damien Le Thiec 2023-02-15 17:14:29 +01:00
parent 5a89a2dbe4
commit 4b3d403d7e
4 changed files with 11 additions and 9 deletions

View file

@ -1,7 +1,8 @@
# frozen_string_literal: true
RSpec.describe TypesDeChamp::PrefillDepartementTypeDeChamp, type: :model do
let(:type_de_champ) { build(:type_de_champ_departements) }
let(:procedure) { create(:procedure) }
let(:type_de_champ) { build(:type_de_champ_departements, procedure: procedure) }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
@ -17,10 +18,12 @@ RSpec.describe TypesDeChamp::PrefillDepartementTypeDeChamp, type: :model do
describe '#possible_values', vcr: { cassette_name: 'api_geo_departements' } do
let(:expected_values) {
APIGeoService.departements.sort_by { |departement| departement[:code] }.map { |departement| "#{departement[:code]} (#{departement[:name]})" }
"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><br><a title=\"Toutes les valeurs possibles — Nouvel onglet\" target=\"_blank\" rel=\"noopener noreferrer\" href=\"/procedures/#{procedure.path}/prefill_type_de_champs/#{type_de_champ.id}\">Voir toutes les valeurs possibles</a>"
}
subject(:possible_values) { described_class.new(type_de_champ).possible_values }
before { type_de_champ.reload }
it { expect(possible_values).to match(expected_values) }
end
end

View file

@ -69,7 +69,6 @@ RSpec.describe TypesDeChamp::PrefillRepetitionTypeDeChamp, type: :model, vcr: {
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\"}"] }

View file

@ -31,8 +31,8 @@ describe 'Prefilling a dossier (with a GET request):' do
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => [
"{
\"#{sub_type_de_champs_repetition.first.libelle}\": \"#{text_repetition_value}\",
\"#{sub_type_de_champs_repetition.second.libelle}\": \"#{integer_repetition_value}\"
\"#{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_datetime.to_typed_id}" => datetime_value
@ -51,8 +51,8 @@ describe 'Prefilling a dossier (with a GET request):' do
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => [
"{
\"#{sub_type_de_champs_repetition.first.libelle}\": \"#{text_repetition_value}\",
\"#{sub_type_de_champs_repetition.second.libelle}\": \"#{integer_repetition_value}\"
\"#{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_datetime.to_typed_id}" => datetime_value

View file

@ -106,8 +106,8 @@ describe 'Prefilling a dossier (with a POST request):' do
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => [
"{
\"#{sub_type_de_champs_repetition.first.libelle}\": \"#{text_repetition_value}\",
\"#{sub_type_de_champs_repetition.second.libelle}\": \"#{integer_repetition_value}\"
\"#{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_datetime.to_typed_id}" => datetime_value