Fix merge conflict spec

This commit is contained in:
Damien Le Thiec 2023-02-16 17:28:18 +01:00
parent dce4c84f9a
commit d2452980fe
5 changed files with 61 additions and 87 deletions

View file

@ -1,8 +1,8 @@
class TypesDeChamp::PrefillMultipleDropDownListTypeDeChamp < TypesDeChamp::PrefillDropDownListTypeDeChamp
def example_value
return nil if possible_values.empty?
return possible_values.first if possible_values.one?
return nil if all_possible_values.empty?
return all_possible_values.first if all_possible_values.one?
[possible_values.first, possible_values.second]
[all_possible_values.first, all_possible_values.second]
end
end

View file

@ -88,70 +88,13 @@ RSpec.describe PrefillDescription, type: :model do
describe '#prefill_link', vcr: { cassette_name: 'api_geo_regions' } do
let(:procedure) { create(:procedure) }
let(:type_de_champ) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_repetition) { build(:type_de_champ_repetition, :with_types_de_champ, :with_region_types_de_champ, procedure: procedure) }
let(:type_de_champ_text) { build(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_epci) { build(:type_de_champ_epci, procedure: procedure) }
let(:type_de_champ_repetition) { create(: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).send(:prefillable_subchamps) }
let(:region_repetition) { prefillable_subchamps.third }
let(:prefill_description) { described_class.new(procedure) }
before { prefill_description.update(selected_type_de_champ_ids: [type_de_champ.id, type_de_champ_repetition.id]) }
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.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}"),
"champ_#{type_de_champ_repetition.to_typed_id}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_repetition).example_value
)
)
end
context 'when the type de champ can have multiple values' do
let(:type_de_champ) { TypesDeChamp::PrefillTypeDeChamp.build(create(:type_de_champ_epci, procedure: procedure)) }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_epcis')
end
after do
VCR.eject_cassette('api_geo_departements')
VCR.eject_cassette('api_geo_epcis')
end
it 'builds the URL with array parameter' do
expect(prefill_description.prefill_link).to eq(
commencer_url(
path: procedure.path,
"champ_#{type_de_champ.to_typed_id}": type_de_champ.example_value
)
)
end
end
end
describe '#prefill_query', vcr: { cassette_name: 'api_geo_regions' } do
let(:procedure) { create(:procedure) }
let(:type_de_champ) { create(:type_de_champ_text, procedure: procedure) }
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).send(:prefillable_subchamps) }
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.to_typed_id}": "#{I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")}", "champ_#{type_de_champ_repetition.to_typed_id}": #{TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_repetition).example_value}}'
TEXT
end
before { prefill_description.update(selected_type_de_champ_ids: [type_de_champ.id, type_de_champ_repetition.id]) }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
@ -161,7 +104,52 @@ RSpec.describe PrefillDescription, type: :model do
VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_epcis')
prefill_description.update(selected_type_de_champ_ids: [type_de_champ.id])
prefill_description.update(selected_type_de_champ_ids: [type_de_champ_text.id, type_de_champ_epci.id, type_de_champ_repetition.id])
end
after do
VCR.eject_cassette('api_geo_departements')
VCR.eject_cassette('api_geo_epcis')
end
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).example_value,
"champ_#{type_de_champ_epci.to_typed_id}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_epci).example_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_repetition).example_value
)
)
end
end
describe '#prefill_query', vcr: { cassette_name: 'api_geo_regions' } do
let(:procedure) { create(:procedure) }
let(:type_de_champ_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_epci) { TypesDeChamp::PrefillTypeDeChamp.build(create(:type_de_champ_epci, procedure: procedure)) }
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).send(:prefillable_subchamps) }
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).example_value}", "champ_#{type_de_champ_epci.to_typed_id}": #{TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_epci).example_value}, "champ_#{type_de_champ_repetition.to_typed_id}": #{TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_repetition).example_value}}'
TEXT
end
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_epcis')
prefill_description.update(selected_type_de_champ_ids: [type_de_champ_text.id, type_de_champ_epci.id, type_de_champ_repetition.id])
end
after do
@ -172,20 +160,5 @@ RSpec.describe PrefillDescription, type: :model do
it "builds the query to create a new prefilled dossier" do
expect(prefill_description.prefill_query).to eq(expected_query)
end
context 'when the type de champ can have multiple values' do
let(:type_de_champ) { TypesDeChamp::PrefillTypeDeChamp.build(create(:type_de_champ_epci, procedure: 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.to_typed_id}": #{type_de_champ.example_value}}'
TEXT
end
it 'builds the query with array parameter' do
expect(prefill_description.prefill_query).to eq(expected_query)
end
end
end
end

View file

@ -2,6 +2,7 @@
RSpec.describe TypesDeChamp::PrefillEpciTypeDeChamp do
let(:type_de_champ) { build(:type_de_champ_epci) }
let(:champ) { create(:champ_epci, type_de_champ: type_de_champ) }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
@ -57,32 +58,32 @@ RSpec.describe TypesDeChamp::PrefillEpciTypeDeChamp do
context 'when the value is nil' do
let(:value) { nil }
it { is_expected.to match({ code_departement: nil, value: nil }) }
it { is_expected.to match({ code_departement: nil, value: nil, id: champ.id }) }
end
context 'when the value is empty' do
let(:value) { '' }
it { is_expected.to match({ code_departement: nil, value: nil }) }
it { is_expected.to match({ code_departement: nil, value: nil, id: champ.id }) }
end
context 'when the value is a string' do
let(:value) { 'hello' }
it { is_expected.to match({ code_departement: nil, value: nil }) }
it { is_expected.to match({ code_departement: nil, value: nil, id: champ.id }) }
end
context 'when the value is an array of one element' do
let(:value) { ['01'] }
it { is_expected.to match({ code_departement: '01', value: nil }) }
it { is_expected.to match({ code_departement: '01', value: nil, id: champ.id }) }
end
context 'when the value is an array of two elements' do
let(:value) { ['01', '200042935'] }
it { is_expected.to match({ code_departement: '01', value: '200042935' }) }
it { is_expected.to match({ code_departement: '01', value: '200042935', id: champ.id }) }
end
context 'when the value is an array of three or more elements' do
let(:value) { ['01', '200042935', 'hello'] }
it { is_expected.to match({ code_departement: '01', value: '200042935' }) }
it { is_expected.to match({ code_departement: '01', value: '200042935', id: champ.id }) }
end
end

View file

@ -10,7 +10,7 @@ RSpec.describe TypesDeChamp::PrefillPaysTypeDeChamp, type: :model do
end
describe '#possible_values' do
let(:expected_values) { "Un <a href=\"https://en.wikipedia.org/wiki/ISO_3166-2\" target=\"_blank\">code pays ISO 3166-2</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>" }
let(:expected_values) { "Un <a href=\"https://en.wikipedia.org/wiki/ISO_3166-2\" target=\"_blank\" rel=\"noopener noreferrer\">code pays ISO 3166-2</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 }

View file

@ -17,7 +17,7 @@ RSpec.describe TypesDeChamp::PrefillRegionTypeDeChamp, type: :model do
end
describe '#possible_values', vcr: { cassette_name: 'api_geo_regions' } do
let(:expected_values) { "Un <a href=\"https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise\" target=\"_blank\">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/#{type_de_champ.id}\">Voir toutes les valeurs possibles</a>" }
let(:expected_values) { "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/#{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 }