2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-12 15:47:05 +02:00
|
|
|
describe ProcedureOverview, type: :model do
|
|
|
|
let(:procedure) { create(:procedure, libelle: 'libelle') }
|
2018-10-25 15:19:29 +02:00
|
|
|
let(:friday) { Time.zone.local(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai
|
|
|
|
let(:monday) { Time.zone.local(2017, 5, 8) }
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2017-11-29 16:07:39 +01:00
|
|
|
before { Timecop.freeze(friday) }
|
|
|
|
after { Timecop.return }
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2020-01-20 14:23:01 +01:00
|
|
|
let(:procedure_overview) { ProcedureOverview.new(procedure, monday, [procedure.defaut_groupe_instructeur]) }
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
describe 'dossiers_en_instruction_count' do
|
|
|
|
let!(:en_instruction_dossier) do
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), created_at: monday)
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
it { expect(procedure_overview.dossiers_en_instruction_count).to eq(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'old_dossiers_en_instruction' do
|
|
|
|
let!(:old_dossier_en_instruction) do
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_instruction_at: monday - 1.month)
|
2017-06-27 18:00:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:dossier_en_instruction) do
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_instruction_at: monday)
|
2017-06-27 18:00:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(procedure_overview.old_dossiers_en_instruction).to match([old_dossier_en_instruction])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'dossiers_en_construction_count' do
|
|
|
|
let!(:dossier_en_construction) do
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction), created_at: monday)
|
2017-06-27 18:00:05 +02:00
|
|
|
end
|
2022-11-29 16:14:24 +01:00
|
|
|
let(:dossier_en_construction_deleted_by_user) do
|
|
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction), created_at: monday)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
dossier_en_construction_deleted_by_user.update(hidden_by_user_at: Time.zone.now)
|
|
|
|
end
|
2017-06-27 18:00:05 +02:00
|
|
|
|
|
|
|
it { expect(procedure_overview.dossiers_en_construction_count).to eq(1) }
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'created_dossiers_count' do
|
|
|
|
let!(:created_dossier_during_the_week) do
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, procedure: procedure, created_at: monday, state: Dossier.states.fetch(:en_instruction))
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
let!(:created_dossier_during_the_week_but_in_brouillon) do
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, procedure: procedure, created_at: monday, state: Dossier.states.fetch(:brouillon))
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:created_dossier_before_the_week) do
|
2018-08-28 14:10:55 +02:00
|
|
|
create(:dossier, procedure: procedure, created_at: (monday - 1.week), state: Dossier.states.fetch(:en_instruction))
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure_overview.created_dossiers_count).to eq(1) }
|
|
|
|
end
|
|
|
|
|
2020-01-15 14:57:40 +01:00
|
|
|
describe 'with a procedure routee' do
|
2023-06-29 11:45:20 +02:00
|
|
|
let!(:gi_2) { create(:groupe_instructeur, label: 'groupe instructeur 2', procedure: procedure) }
|
|
|
|
let!(:gi_3) { create(:groupe_instructeur, label: 'groupe instructeur 3', procedure: procedure) }
|
2020-01-15 14:57:40 +01:00
|
|
|
|
|
|
|
def create_dossier_in_group(g)
|
|
|
|
create(:dossier, procedure: procedure, created_at: monday, state: Dossier.states.fetch(:en_instruction), groupe_instructeur: g)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:created_dossier_during_the_week_on_group_2) { create_dossier_in_group(gi_2) }
|
|
|
|
let!(:created_dossier_during_the_week_on_group_3_a) { create_dossier_in_group(gi_3) }
|
|
|
|
let!(:created_dossier_during_the_week_on_group_3_b) { create_dossier_in_group(gi_3) }
|
|
|
|
|
|
|
|
let(:procedure_overview_gi_2) { ProcedureOverview.new(procedure, monday, [gi_2]) }
|
|
|
|
let(:procedure_overview_gi_3) { ProcedureOverview.new(procedure, monday, [gi_3]) }
|
|
|
|
let(:procedure_overview_default) { ProcedureOverview.new(procedure, monday, [procedure.defaut_groupe_instructeur]) }
|
|
|
|
|
|
|
|
it { expect(procedure_overview_gi_2.created_dossiers_count).to eq(1) }
|
|
|
|
it { expect(procedure_overview_gi_3.created_dossiers_count).to eq(2) }
|
|
|
|
it { expect(procedure_overview_default.created_dossiers_count).to eq(0) }
|
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
describe 'had_some_activities?' do
|
|
|
|
subject { procedure_overview.had_some_activities? }
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
before :each do
|
|
|
|
procedure_overview.dossiers_en_instruction_count = 0
|
|
|
|
procedure_overview.dossiers_en_construction_count = 0
|
|
|
|
procedure_overview.created_dossiers_count = 0
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
context 'when there are no activities' do
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
context 'when there are some dossiers en instruction' do
|
|
|
|
before { procedure_overview.dossiers_en_instruction_count = 2 }
|
|
|
|
it { is_expected.to be true }
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
context 'when there are some dossiers en construction' do
|
|
|
|
before { procedure_overview.dossiers_en_construction_count = 2 }
|
|
|
|
it { is_expected.to be true }
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
context 'when there are some created dossiers' do
|
|
|
|
before { procedure_overview.created_dossiers_count = 2 }
|
|
|
|
it { is_expected.to be true }
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|