Skip to content

Commit

Permalink
fix(routing): can create simple routing with communes and epci tdc
Browse files Browse the repository at this point in the history
  • Loading branch information
E-L-T committed Jan 31, 2024
1 parent 17a471e commit b04f152
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/controllers/administrateurs/groupe_instructeurs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ def create_simple_routing
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)
Expand Down Expand Up @@ -457,9 +463,10 @@ def flash_message_for_invalid_csv
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,46 @@ def remove_instructeur(instructeur)
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
Expand Down

0 comments on commit b04f152

Please sign in to comment.