feat(conditional): can condition and route with pays tdc
This commit is contained in:
parent
b02f95336f
commit
b29893a843
3 changed files with 41 additions and 3 deletions
|
@ -12,7 +12,8 @@ class Logic::ChampValue < Logic::Term
|
||||||
:epci,
|
:epci,
|
||||||
:departements,
|
:departements,
|
||||||
:regions,
|
:regions,
|
||||||
:address
|
:address,
|
||||||
|
:pays
|
||||||
)
|
)
|
||||||
|
|
||||||
CHAMP_VALUE_TYPE = {
|
CHAMP_VALUE_TYPE = {
|
||||||
|
@ -56,7 +57,7 @@ class Logic::ChampValue < Logic::Term
|
||||||
targeted_champ.selected
|
targeted_champ.selected
|
||||||
when "Champs::MultipleDropDownListChamp"
|
when "Champs::MultipleDropDownListChamp"
|
||||||
targeted_champ.selected_options
|
targeted_champ.selected_options
|
||||||
when "Champs::RegionChamp"
|
when "Champs::RegionChamp", "Champs::PaysChamp"
|
||||||
targeted_champ.code
|
targeted_champ.code
|
||||||
when "Champs::DepartementChamp"
|
when "Champs::DepartementChamp"
|
||||||
{
|
{
|
||||||
|
@ -81,7 +82,7 @@ class Logic::ChampValue < Logic::Term
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
||||||
CHAMP_VALUE_TYPE.fetch(:number)
|
CHAMP_VALUE_TYPE.fetch(:number)
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list),
|
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list),
|
||||||
MANAGED_TYPE_DE_CHAMP.fetch(:regions)
|
MANAGED_TYPE_DE_CHAMP.fetch(:regions), MANAGED_TYPE_DE_CHAMP.fetch(:pays)
|
||||||
CHAMP_VALUE_TYPE.fetch(:enum)
|
CHAMP_VALUE_TYPE.fetch(:enum)
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:communes)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:communes)
|
||||||
CHAMP_VALUE_TYPE.fetch(:commune_enum)
|
CHAMP_VALUE_TYPE.fetch(:commune_enum)
|
||||||
|
@ -128,6 +129,8 @@ class Logic::ChampValue < Logic::Term
|
||||||
APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
elsif operator_name.in?([Logic::InDepartementOperator.name, Logic::NotInDepartementOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:address)])
|
elsif operator_name.in?([Logic::InDepartementOperator.name, Logic::NotInDepartementOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:address)])
|
||||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
|
elsif tdc.type_champ == MANAGED_TYPE_DE_CHAMP.fetch(:pays)
|
||||||
|
APIGeoService.countries.map { ["#{_1[:name]} – #{_1[:code]}", _1[:code]] }
|
||||||
else
|
else
|
||||||
tdc.drop_down_options_with_other.map { _1.is_a?(Array) ? _1 : [_1, _1] }
|
tdc.drop_down_options_with_other.map { _1.is_a?(Array) ? _1 : [_1, _1] }
|
||||||
end
|
end
|
||||||
|
|
|
@ -131,6 +131,18 @@ describe Conditions::ChampsConditionsComponent, type: :component do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'pays' do
|
||||||
|
let(:pays) { create(:type_de_champ_pays) }
|
||||||
|
let(:upper_tdcs) { [pays] }
|
||||||
|
let(:condition) { empty_operator(champ_value(pays.stable_id), constant(true)) }
|
||||||
|
let(:pays_options) { APIGeoService.countries.map { "#{_1[:name]} – #{_1[:code]}" } }
|
||||||
|
|
||||||
|
it do
|
||||||
|
expect(page).to have_select('type_de_champ[condition_form][rows][][operator_name]', with_options: ['Est'])
|
||||||
|
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: (['Sélectionner'] + pays_options))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'address' do
|
context 'address' do
|
||||||
let(:address) { create(:type_de_champ_address) }
|
let(:address) { create(:type_de_champ_address) }
|
||||||
let(:upper_tdcs) { [address] }
|
let(:upper_tdcs) { [address] }
|
||||||
|
|
|
@ -181,6 +181,29 @@ describe RoutingEngine, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a pays type de champ' do
|
||||||
|
let(:procedure) do
|
||||||
|
create(:procedure, types_de_champ_public: [{ type: :pays }]).tap do |p|
|
||||||
|
p.groupe_instructeurs.create(label: 'a third group')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:pays_tdc) { procedure.draft_revision.types_de_champ.first }
|
||||||
|
|
||||||
|
context 'with a matching rule' do
|
||||||
|
before do
|
||||||
|
gi_2.update(routing_rule: ds_eq(champ_value(pays_tdc.stable_id), constant('BE')))
|
||||||
|
dossier.champs.first.update_columns(
|
||||||
|
value: "Belgique"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to eq(gi_2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'routing rules priorities' do
|
context 'routing rules priorities' do
|
||||||
let(:procedure) do
|
let(:procedure) do
|
||||||
create(:procedure,
|
create(:procedure,
|
||||||
|
|
Loading…
Reference in a new issue