Merge pull request #11025 from demarches-simplifiees/add-spec-for-sorted-by-labels

Ajout d'un test suite au bug de tri par labels
This commit is contained in:
LeSim 2024-11-12 11:17:42 +00:00 committed by GitHub
commit 22ab0f4eca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View file

@ -58,8 +58,8 @@ class DossierFilterService
.pluck(:id)
.uniq
when 'dossier_labels'
dossiers.includes(table)
.order("#{sanitized_column(table, column)} #{order}")
dossiers.includes(:labels)
.order("labels.name #{order}")
.pluck(:id)
.uniq
when 'self', 'user', 'individual', 'etablissement', 'groupe_instructeur'

View file

@ -273,6 +273,28 @@ describe DossierFilterService do
it { is_expected.to eq([dossier_no, dossier_yes].map(&:id)) }
end
context 'for labels table' do
let(:column) { procedure.find_column(label: 'Labels') }
let(:label_a) { Label.create(name: "a", color: 'green-bourgeon', procedure:) }
let(:label_z) { Label.create(name: "z", color: 'green-bourgeon', procedure:) }
let!(:dossier_z) { create(:dossier, procedure:) }
let!(:dossier_a) { create(:dossier, procedure:) }
let!(:dossier_no_label) { create(:dossier, procedure:) }
let!(:dossier_label_a) { DossierLabel.create(dossier: dossier_a, label: label_a) }
let!(:dossier_label_z) { DossierLabel.create(dossier: dossier_z, label: label_z) }
context 'asc' do
let(:order) { 'asc' }
it { is_expected.to eq([dossier_a, dossier_z, dossier_no_label].map(&:id)) }
end
context 'desc' do
let(:order) { 'desc' }
it { is_expected.to eq([dossier_no_label, dossier_z, dossier_a].map(&:id)) }
end
end
context 'for other tables' do
# All other columns and tables work the same so its ok to test only one
let(:column) { procedure.find_column(label: 'Établissement code postal') }