feat(sva): instructeurs can filter by sva/svr decision before a date

This commit is contained in:
Colin Darie 2023-06-08 18:58:47 +02:00
parent f1504e9724
commit 168189c3ac
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
6 changed files with 44 additions and 6 deletions

View file

@ -12,8 +12,10 @@ module DossierFilteringConcern
scope :filter_by_datetimes, lambda { |column, dates|
if dates.present?
case column
when 'sva_svr_decision_before'
state_not_termine.where("dossiers.sva_svr_decision_on": ..dates.sort.first)
when *DATE_SINCE_MAPPING.keys
where("dossiers.#{DATE_SINCE_MAPPING.fetch(column)} >= ?", dates.sort.first)
where("dossiers.#{DATE_SINCE_MAPPING.fetch(column)}": dates.sort.first..)
else
dates
.map { |date| self.where(column => date..(date + 1.day)) }

View file

@ -38,6 +38,8 @@ class ProcedurePresentation < ApplicationRecord
validate :check_filters_max_length
def self_fields
sva_svr_enabled = procedure.sva_svr_enabled?
[
field_hash('self', 'created_at', type: :date),
field_hash('self', 'updated_at', type: :date),
@ -45,14 +47,15 @@ class ProcedurePresentation < ApplicationRecord
field_hash('self', 'en_construction_at', type: :date),
field_hash('self', 'en_instruction_at', type: :date),
field_hash('self', 'processed_at', type: :date),
field_hash('self', 'sva_svr_decision_on', type: :date),
sva_svr_enabled && field_hash('self', 'sva_svr_decision_on', type: :date),
sva_svr_enabled && field_hash('self', 'sva_svr_decision_before', type: :date, virtual: true),
field_hash('self', 'updated_since', type: :date, virtual: true),
field_hash('self', 'depose_since', type: :date, virtual: true),
field_hash('self', 'en_construction_since', type: :date, virtual: true),
field_hash('self', 'en_instruction_since', type: :date, virtual: true),
field_hash('self', 'processed_since', type: :date, virtual: true),
field_hash('self', 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', virtual: true)
]
].compact_blank
end
def fields

View file

@ -17,7 +17,8 @@ en:
en_construction_since: Submitted since
en_instruction_since: Instructed since
processed_since: Finished since
sva_svr_decision_on: SVA decision
sva_svr_decision_on: SVA decision date
sva_svr_decision_before: SVA decision date before
user:
email: Requester
followers_instructeurs:

View file

@ -17,7 +17,8 @@ fr:
en_construction_since: En construction depuis
en_instruction_since: En instruction depuis
processed_since: Terminé depuis
sva_svr_decision_on: Décision SVA
sva_svr_decision_on: Date décision SVA
sva_svr_decision_before: Date décision SVA avant
user:
email: Demandeur
followers_instructeurs:

View file

@ -1,4 +1,6 @@
describe ProcedurePresentation do
include ActiveSupport::Testing::TimeHelpers
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{}], types_de_champ_private: [{}]) }
let(:instructeur) { create(:instructeur) }
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) }
@ -113,6 +115,18 @@ describe ProcedurePresentation do
it { is_expected.to include(name_field, surname_field, gender_field) }
end
context 'when the procedure is sva/svr' do
let(:procedure) { create(:procedure, :for_individual, :sva) }
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
let(:decision_on) { { "label" => "Date décision SVA", "table" => "self", "column" => "sva_svr_decision_on", 'classname' => '', 'virtual' => false, "type" => :date, "scope" => '', "value_column" => :value } }
let(:decision_before_field) { { "label" => "Date décision SVA avant", "table" => "self", "column" => "sva_svr_decision_before", 'classname' => '', 'virtual' => true, "type" => :date, "scope" => '', "value_column" => :value } }
subject { procedure_presentation.fields }
it { is_expected.to include(decision_on, decision_before_field) }
end
end
describe "#displayable_fields_for_select" do
@ -466,6 +480,23 @@ describe ProcedurePresentation do
it { is_expected.to match_array([kept_dossier.id, later_dossier.id]) }
end
context 'for sva_svr_decision_before column' do
before do
travel_to Time.zone.local(2023, 6, 10, 10)
end
let(:procedure) { create(:procedure, :published, :sva, types_de_champ_public: [{}], types_de_champ_private: [{}]) }
let(:filter) { [{ 'table' => 'self', 'column' => 'sva_svr_decision_before', 'value' => '15/06/2023' }] }
let!(:kept_dossier) { create(:dossier, :en_instruction, procedure:, sva_svr_decision_on: Date.current) }
let!(:later_dossier) { create(:dossier, :en_instruction, procedure:, sva_svr_decision_on: Date.current + 2.days) }
let!(:discarded_dossier) { create(:dossier, :en_instruction, procedure:, sva_svr_decision_on: Date.current + 10.days) }
let!(:en_construction_dossier) { create(:dossier, :en_construction, procedure:, sva_svr_decision_on: Date.current + 2.days) }
let!(:accepte_dossier) { create(:dossier, :accepte, procedure:, sva_svr_decision_on: Date.current + 2.days) }
it { is_expected.to match_array([kept_dossier.id, later_dossier.id, en_construction_dossier.id]) }
end
context 'ignore time of day' do
let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018 19:30' }] }

View file

@ -25,7 +25,7 @@ describe "procedure filters" do
procedure.update!(sva_svr: SVASVRConfiguration.new(decision: :sva).attributes)
visit instructeur_procedure_path(procedure)
within ".dossiers-table" do
expect(page).to have_link("Décision SVA")
expect(page).to have_link("Date décision SVA")
expect(page).to have_link(new_unfollow_dossier.user.email)
end
end