feat(routing): make routing engine work with departement champ
This commit is contained in:
parent
2827db5263
commit
7e3fc68c53
2 changed files with 61 additions and 37 deletions
|
@ -44,6 +44,8 @@ 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::DepartementChamp"
|
||||||
|
targeted_champ.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,6 @@ describe RoutingEngine, type: :model do
|
||||||
include Logic
|
include Logic
|
||||||
|
|
||||||
describe '.compute' do
|
describe '.compute' do
|
||||||
let(:procedure) do
|
|
||||||
create(:procedure,
|
|
||||||
types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }]).tap do |p|
|
|
||||||
p.groupe_instructeurs.create(label: 'a second group')
|
|
||||||
p.groupe_instructeurs.create(label: 'a third group')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first }
|
|
||||||
|
|
||||||
let(:dossier) { create(:dossier, procedure:) }
|
let(:dossier) { create(:dossier, procedure:) }
|
||||||
let(:defaut_groupe) { procedure.defaut_groupe_instructeur }
|
let(:defaut_groupe) { procedure.defaut_groupe_instructeur }
|
||||||
let(:gi_2) { procedure.groupe_instructeurs.find_by(label: 'a second group') }
|
let(:gi_2) { procedure.groupe_instructeurs.find_by(label: 'a second group') }
|
||||||
|
@ -21,43 +11,75 @@ describe RoutingEngine, type: :model do
|
||||||
dossier.groupe_instructeur
|
dossier.groupe_instructeur
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without any rules' do
|
context 'with a drop down list type de champ' do
|
||||||
it { is_expected.to eq(defaut_groupe) }
|
let(:procedure) do
|
||||||
end
|
create(:procedure,
|
||||||
|
types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }]).tap do |p|
|
||||||
context 'without any matching rules' do
|
p.groupe_instructeurs.create(label: 'a second group')
|
||||||
before do
|
p.groupe_instructeurs.create(label: 'a third group')
|
||||||
procedure.groupe_instructeurs.each do |gi|
|
|
||||||
gi.update(routing_rule: constant(false))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq(defaut_groupe) }
|
let(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first }
|
||||||
|
|
||||||
|
context 'without any rules' do
|
||||||
|
it { is_expected.to eq(defaut_groupe) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without any matching rules' do
|
||||||
|
before do
|
||||||
|
procedure.groupe_instructeurs.each do |gi|
|
||||||
|
gi.update(routing_rule: constant(false))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to eq(defaut_groupe) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with rules not configured yet' do
|
||||||
|
before do
|
||||||
|
procedure.groupe_instructeurs.each do |gi|
|
||||||
|
gi.update(routing_rule: ds_eq(empty, empty))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to eq(defaut_groupe) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a matching rule' do
|
||||||
|
before do
|
||||||
|
gi_2.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')))
|
||||||
|
dossier.champs.first.update(value: 'Lyon')
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to eq(gi_2) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a closed gi with a matching rule' do
|
||||||
|
before { gi_2.update(routing_rule: constant(true), closed: true) }
|
||||||
|
|
||||||
|
it { is_expected.to eq(defaut_groupe) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with rules not configured yet' do
|
context 'with a departements type de champ' do
|
||||||
before do
|
let(:procedure) do
|
||||||
procedure.groupe_instructeurs.each do |gi|
|
create(:procedure, types_de_champ_public: [{ type: :departements }]).tap do |p|
|
||||||
gi.update(routing_rule: ds_eq(empty, empty))
|
p.groupe_instructeurs.create(label: 'a second group')
|
||||||
|
p.groupe_instructeurs.create(label: 'a third group')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq(defaut_groupe) }
|
let(:departements_tdc) { procedure.draft_revision.types_de_champ.first }
|
||||||
end
|
|
||||||
|
|
||||||
context 'with a matching rule' do
|
context 'with a matching rule' do
|
||||||
before do
|
before do
|
||||||
gi_2.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')))
|
gi_2.update(routing_rule: ds_eq(champ_value(departements_tdc.stable_id), constant('43 – Haute-Loire')))
|
||||||
dossier.champs.first.update(value: 'Lyon')
|
dossier.champs.first.update(value: 'Haute-Loire')
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to eq(gi_2) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq(gi_2) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with a closed gi with a matching rule' do
|
|
||||||
before { gi_2.update(routing_rule: constant(true), closed: true) }
|
|
||||||
|
|
||||||
it { is_expected.to eq(defaut_groupe) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue