diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 6fa255a64..dbfce2464 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -420,7 +420,7 @@ class Dossier < ApplicationRecord when 'tous' visible_by_administration.all_state when 'supprimes_recemment' - hidden_by_administration.termine + hidden_by_administration.state_termine when 'archives' visible_by_administration.archived when 'expirant' diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index bf387fe6c..1ce2ebbf0 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -114,6 +114,11 @@ FactoryBot.define do hidden_at { Time.zone.now } end + trait :hidden_by_administration do + hidden_by_administration_at { 1.day.ago } + hidden_by_reason { DeletedDossier.reasons.fetch(:instructeur_request) } + end + trait :with_dossier_link do after(:create) do |dossier, _evaluator| # create linked dossier diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 68c7df9e5..f52242650 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -23,6 +23,43 @@ describe Dossier, type: :model do it { expect(Dossier.brouillons_recently_updated).to eq([dossier_en_brouillon_2, dossier_en_brouillon]) } end + + describe 'by_statut' do + let(:procedure) { create(:procedure) } + let(:dossier_en_construction) { create(:dossier, :en_construction, procedure:) } + let(:dossier_en_instruction) { create(:dossier, :en_instruction, procedure:) } + let(:dossier_accepte) { create(:dossier, :accepte, procedure:) } + let(:dossier_refuse) { create(:dossier, :refuse, procedure:) } + let(:dossier_accepte_archive) { create(:dossier, :accepte, :archived, procedure:) } + let(:dossier_accepte_deleted) { create(:dossier, :accepte, :hidden_by_administration, procedure:) } + let(:dossier_accepte_archive_deleted) { create(:dossier, :accepte, :archived, :hidden_by_administration, procedure:) } + + let!(:dossiers) { [dossier_en_construction, dossier_en_instruction, dossier_accepte, dossier_refuse] } + + context 'tous' do + it do + expect(procedure.dossiers.by_statut('tous')).to match_array(dossiers - [dossier_accepte_archive, dossier_accepte_archive_deleted]) + end + end + + context 'a-suivre' do + it do + expect(procedure.dossiers.by_statut('a-suivre')).to match_array([dossier_en_construction, dossier_en_instruction]) + end + end + + context 'supprimes_recemment' do + it do + expect(procedure.dossiers.by_statut('supprimes_recemment')).to match_array([dossier_accepte_deleted, dossier_accepte_archive_deleted]) + end + end + + context 'archives' do + it do + expect(procedure.dossiers.by_statut('archives')).to match_array([dossier_accepte_archive]) + end + end + end end describe 'validations' do