Merge pull request #10492 from demarches-simplifiees/fix-sql-request-all-procedures

Correctif ETQ admin je peux consulter la page "toutes les démarches" sans zone sélectionnée
This commit is contained in:
Kara Diaby 2024-06-05 15:19:35 +00:00 committed by GitHub
commit e3492fc44a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 18 deletions

View file

@ -14,7 +14,7 @@ ProcedureDetail = Struct.new(:id, :libelle, :published_at, :aasm_state, :estimat
end
def parsed_latest_zone_labels
# Replace curly braces with square brackets to make it a valid JSON array
return [] if latest_zone_labels.nil? || latest_zone_labels.strip.empty?
JSON.parse(latest_zone_labels.tr('{', '[').tr('}', ']'))
rescue JSON::ParserError
[]

View file

@ -31,7 +31,7 @@
- if show_detail
%tr.procedure{ id: "procedure_detail_#{procedure.id}" }
%td.fr-highlight--beige-gris-galet{ colspan: '8' }
%td.fr-highlight--green-emeraude{ colspan: '8' }
.fr-container
.fr-col-6
- procedure.administrateurs.uniq.each do |admin|

View file

@ -95,9 +95,6 @@ describe Administrateurs::ProceduresController, type: :controller do
let!(:draft_procedure) { create(:procedure) }
let!(:published_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2) }
let!(:closed_procedure) { create(:procedure, :closed) }
let!(:procedure_detail_draft) { ProcedureDetail.new(id: draft_procedure.id, latest_zone_labels: '{ "zone1", "zone2" }') }
let!(:procedure_detail_published) { ProcedureDetail.new(id: published_procedure.id, latest_zone_labels: '{ "zone3", "zone4" }') }
let!(:procedure_detail_closed) { ProcedureDetail.new(id: closed_procedure.id, latest_zone_labels: '{ "zone5", "zone6" }') }
subject { get :all }
@ -124,19 +121,6 @@ describe Administrateurs::ProceduresController, type: :controller do
expect(assigns(:procedures).any? { |p| p.id == draft_procedure.id }).to be_falsey
end
context 'with parsed latest zone labels' do
it 'parses the latest zone labels correctly' do
expect(procedure_detail_draft.parsed_latest_zone_labels).to eq(["zone1", "zone2"])
expect(procedure_detail_published.parsed_latest_zone_labels).to eq(["zone3", "zone4"])
expect(procedure_detail_closed.parsed_latest_zone_labels).to eq(["zone5", "zone6"])
end
it 'returns an empty array for invalid JSON' do
procedure_detail_draft.latest_zone_labels = '{ invalid json }'
expect(procedure_detail_draft.parsed_latest_zone_labels).to eq([])
end
end
context 'for default admin zones' do
let(:zone1) { create(:zone) }
let(:zone2) { create(:zone) }

View file

@ -1776,6 +1776,37 @@ describe Procedure do
end
end
describe "#parsed_latest_zone_labels" do
let!(:draft_procedure) { create(:procedure) }
let!(:published_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2) }
let!(:closed_procedure) { create(:procedure, :closed) }
let!(:procedure_detail_draft) { ProcedureDetail.new(id: draft_procedure.id, latest_zone_labels: '{ "zone1", "zone2" }') }
let!(:procedure_detail_published) { ProcedureDetail.new(id: published_procedure.id, latest_zone_labels: '{ "zone3", "zone4" }') }
let!(:procedure_detail_closed) { ProcedureDetail.new(id: closed_procedure.id, latest_zone_labels: '{ "zone5", "zone6" }') }
context 'with parsed latest zone labels' do
it 'parses the latest zone labels correctly' do
expect(procedure_detail_draft.parsed_latest_zone_labels).to eq(["zone1", "zone2"])
expect(procedure_detail_published.parsed_latest_zone_labels).to eq(["zone3", "zone4"])
expect(procedure_detail_closed.parsed_latest_zone_labels).to eq(["zone5", "zone6"])
end
it 'returns an empty array for invalid JSON' do
procedure_detail_draft.latest_zone_labels = '{ invalid json }'
expect(procedure_detail_draft.parsed_latest_zone_labels).to eq([])
end
it 'returns an empty array when latest_zone_labels is nil' do
procedure_detail_draft.latest_zone_labels = nil
expect(procedure_detail_draft.parsed_latest_zone_labels).to eq([])
end
it 'returns an empty array when latest_zone_labels is empty' do
procedure_detail_draft.latest_zone_labels = ''
expect(procedure_detail_draft.parsed_latest_zone_labels).to eq([])
end
end
end
private
def create_dossier_with_pj_of_size(size, procedure)