add warning in gi pages in rule does not match tdc

This commit is contained in:
Eric Leroy-Terquem 2023-05-15 11:40:03 +02:00 committed by LeSim
parent 6e88c49470
commit 50abf496fd
2 changed files with 46 additions and 1 deletions

View file

@ -88,11 +88,17 @@ class GroupeInstructeur < ApplicationRecord
def routing_to_configure?
rule = routing_rule
!(rule.is_a?(Logic::Eq) && rule.left.is_a?(Logic::ChampValue) && rule.right.is_a?(Logic::Constant))
return true if !(rule.is_a?(Logic::Eq) && rule.left.is_a?(Logic::ChampValue) && rule.right.is_a?(Logic::Constant))
!routing_rule_matches_tdc?
end
private
def routing_rule_matches_tdc?
routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: routing_rule.left.stable_id)
routing_rule.right.value.in?(routing_tdc.options['drop_down_options'])
end
def toggle_routing
procedure.update!(routing_enabled: procedure.groupe_instructeurs.active.many?)
procedure.update!(instructeurs_self_management_enabled: true) if procedure.routing_enabled?

View file

@ -60,6 +60,45 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
expect(assigns(:available_instructeur_emails)).to match_array(['instructeur_3@ministere-a.gouv.fr', 'instructeur_4@ministere-b.gouv.fr'])
end
end
context 'group without routing rule' do
before { get :show, params: { procedure_id: procedure.id, id: gi_1_1.id } }
it do
expect(response).to have_http_status(:ok)
expect(response.body).to include('à configurer')
end
end
context 'group with routing rule matching tdc' do
let!(:drop_down_tdc) { create(:type_de_champ_drop_down_list, procedure: procedure, drop_down_options: options) }
let(:options) { procedure.groupe_instructeurs.pluck(:label) }
before do
gi_1_1.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant(gi_1_1.label)))
get :show, params: { procedure_id: procedure.id, id: gi_1_1.id }
end
it do
expect(response).to have_http_status(:ok)
expect(response.body).not_to include('à configurer')
end
end
context 'group with routing rule not matching tdc' do
let!(:drop_down_tdc) { create(:type_de_champ_drop_down_list, procedure: procedure, drop_down_options: options) }
let(:options) { ['parmesan', 'brie', 'morbier'] }
before do
gi_1_1.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant(gi_1_1.label)))
get :show, params: { procedure_id: procedure.id, id: gi_1_1.id }
end
it do
expect(response).to have_http_status(:ok)
expect(response.body).to include('à configurer')
end
end
end
describe '#create' do