Merge pull request #9955 from demarches-simplifiees/fix-simple-routing
ETQ admin je peux faire un routage simple à partir d'un type de champ communes ou epci
This commit is contained in:
commit
7b539c72b1
2 changed files with 51 additions and 4 deletions
|
@ -45,10 +45,16 @@ module Administrateurs
|
|||
case tdc.type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:departements)
|
||||
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
create_groups_from_territorial_tdc(tdc_options, stable_id)
|
||||
rule_operator = :ds_eq
|
||||
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||
when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:epci)
|
||||
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
rule_operator = :ds_in_departement
|
||||
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||
when TypeDeChamp.type_champs.fetch(:regions)
|
||||
rule_operator = :ds_eq
|
||||
tdc_options = APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
create_groups_from_territorial_tdc(tdc_options, stable_id)
|
||||
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||
tdc_options = tdc.drop_down_options.reject(&:empty?)
|
||||
create_groups_from_drop_down_list_tdc(tdc_options, stable_id)
|
||||
|
@ -457,9 +463,10 @@ module Administrateurs
|
|||
flash[:alert] = "Importation impossible, veuillez importer un csv suivant #{view_context.link_to('ce modèle', "/csv/import-instructeurs-test.csv")} pour une procédure sans routage ou #{view_context.link_to('celui-ci', "/csv/#{I18n.locale}/import-groupe-test.csv")} pour une procédure routée"
|
||||
end
|
||||
|
||||
def create_groups_from_territorial_tdc(tdc_options, stable_id)
|
||||
def create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||
tdc_options.each do |label, code|
|
||||
routing_rule = ds_eq(champ_value(stable_id), constant(code))
|
||||
routing_rule = send(rule_operator, champ_value(stable_id), constant(code))
|
||||
|
||||
@procedure
|
||||
.groupe_instructeurs
|
||||
.find_or_create_by(label: label)
|
||||
|
|
|
@ -773,6 +773,46 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
expect(procedure3.routing_enabled).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a communes type de champ' do
|
||||
let!(:procedure3) do
|
||||
create(:procedure,
|
||||
types_de_champ_public: [{ type: :communes }],
|
||||
administrateurs: [admin])
|
||||
end
|
||||
|
||||
let!(:communes_tdc) { procedure3.draft_revision.types_de_champ.first }
|
||||
|
||||
before { post :create_simple_routing, params: { procedure_id: procedure3.id, create_simple_routing: { stable_id: communes_tdc.stable_id } } }
|
||||
|
||||
it do
|
||||
expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure3))
|
||||
expect(flash.notice).to eq 'Les groupes instructeurs ont été ajoutés'
|
||||
expect(procedure3.groupe_instructeurs.pluck(:label)).to include("01 – Ain")
|
||||
expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_in_departement(champ_value(communes_tdc.stable_id), constant('01')))
|
||||
expect(procedure3.routing_enabled).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an epci type de champ' do
|
||||
let!(:procedure3) do
|
||||
create(:procedure,
|
||||
types_de_champ_public: [{ type: :epci }],
|
||||
administrateurs: [admin])
|
||||
end
|
||||
|
||||
let!(:epci_tdc) { procedure3.draft_revision.types_de_champ.first }
|
||||
|
||||
before { post :create_simple_routing, params: { procedure_id: procedure3.id, create_simple_routing: { stable_id: epci_tdc.stable_id } } }
|
||||
|
||||
it do
|
||||
expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure3))
|
||||
expect(flash.notice).to eq 'Les groupes instructeurs ont été ajoutés'
|
||||
expect(procedure3.groupe_instructeurs.pluck(:label)).to include("01 – Ain")
|
||||
expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_in_departement(champ_value(epci_tdc.stable_id), constant('01')))
|
||||
expect(procedure3.routing_enabled).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#wizard' do
|
||||
|
|
Loading…
Reference in a new issue