2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
describe Instructeur, type: :model do
|
2016-07-18 18:24:29 +02:00
|
|
|
let(:admin) { create :administrateur }
|
2021-12-21 19:06:38 +01:00
|
|
|
let(:procedure) { create :procedure, :published, administrateur: admin }
|
|
|
|
let(:procedure_2) { create :procedure, :published, administrateur: admin }
|
|
|
|
let(:procedure_3) { create :procedure, :published, administrateur: admin }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create :instructeur, administrateurs: [admin] }
|
2021-12-21 19:06:38 +01:00
|
|
|
let(:procedure_assign) { assign(procedure) }
|
2016-07-18 18:24:29 +02:00
|
|
|
|
|
|
|
before do
|
2021-12-21 19:06:38 +01:00
|
|
|
procedure_assign
|
2018-12-03 13:51:45 +01:00
|
|
|
assign(procedure_2)
|
2021-12-21 19:06:38 +01:00
|
|
|
procedure_3
|
2016-07-18 18:24:29 +02:00
|
|
|
end
|
|
|
|
|
2022-03-02 11:26:53 +01:00
|
|
|
describe 'associations' do
|
2024-02-07 17:19:50 +01:00
|
|
|
it { is_expected.to have_many(:archives) }
|
|
|
|
it { is_expected.to have_many(:exports) }
|
2022-03-02 11:26:53 +01:00
|
|
|
it { is_expected.to have_and_belong_to_many(:administrateurs) }
|
2022-11-18 15:26:31 +01:00
|
|
|
it { is_expected.to have_many(:batch_operations) }
|
2022-03-02 11:26:53 +01:00
|
|
|
end
|
|
|
|
|
2017-07-17 11:28:14 +02:00
|
|
|
describe 'follow' do
|
|
|
|
let(:dossier) { create :dossier }
|
|
|
|
let(:already_followed_dossier) { create :dossier }
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
before { instructeur.followed_dossiers << already_followed_dossier }
|
2017-07-17 11:28:14 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when a instructeur follow a dossier for the first time' do
|
|
|
|
before { instructeur.follow(dossier) }
|
2017-07-17 11:28:14 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(instructeur.follow?(dossier)).to be true }
|
2017-07-17 11:28:14 +02:00
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when a instructeur follows a dossier already followed' do
|
|
|
|
before { instructeur.follow(already_followed_dossier) }
|
2017-07-17 11:28:14 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(instructeur.follow?(already_followed_dossier)).to be true }
|
2017-07-17 11:28:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-05 14:10:49 +02:00
|
|
|
describe '#unfollow' do
|
|
|
|
let(:already_followed_dossier) { create(:dossier) }
|
2019-08-06 11:02:54 +02:00
|
|
|
before { instructeur.followed_dossiers << already_followed_dossier }
|
2017-10-05 14:10:49 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when a instructeur unfollow a dossier already followed' do
|
2017-10-05 14:10:49 +02:00
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur.unfollow(already_followed_dossier)
|
2017-10-05 14:10:49 +02:00
|
|
|
already_followed_dossier.reload
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(instructeur.follow?(already_followed_dossier)).to be false }
|
|
|
|
it { expect(instructeur.previously_followed_dossiers).to include(already_followed_dossier) }
|
2017-10-05 14:10:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-18 18:24:29 +02:00
|
|
|
describe '#follow?' do
|
|
|
|
let!(:dossier) { create :dossier, procedure: procedure }
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
subject { instructeur.follow?(dossier) }
|
2016-07-18 18:24:29 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when instructeur follow a dossier' do
|
2016-07-18 18:24:29 +02:00
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
create :follow, dossier_id: dossier.id, instructeur_id: instructeur.id
|
2016-07-18 18:24:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when instructeur not follow a dossier' do
|
2016-07-18 18:24:29 +02:00
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-20 11:24:32 +01:00
|
|
|
describe "#assign_to_procedure" do
|
2019-08-06 11:02:54 +02:00
|
|
|
subject { instructeur.assign_to_procedure(procedure_to_assign) }
|
2018-02-20 11:24:32 +01:00
|
|
|
|
|
|
|
context "with a procedure not already assigned" do
|
|
|
|
let(:procedure_to_assign) { procedure_3 }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect { subject }.to change(instructeur.procedures, :count) }
|
2019-08-20 16:59:45 +02:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(instructeur.groupe_instructeurs).to include(procedure_to_assign.defaut_groupe_instructeur)
|
|
|
|
end
|
2018-02-20 11:24:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with an already assigned procedure" do
|
|
|
|
let(:procedure_to_assign) { procedure }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect { subject }.not_to change(instructeur.procedures, :count) }
|
2018-02-20 11:24:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 16:47:18 +02:00
|
|
|
describe 'last_week_overview' do
|
2019-08-06 11:02:54 +02:00
|
|
|
let!(:instructeur2) { create(:instructeur) }
|
|
|
|
subject { instructeur2.last_week_overview }
|
2018-10-25 15:19:29 +02:00
|
|
|
let(:friday) { Time.zone.local(2017, 5, 12) }
|
2018-10-25 15:07:15 +02:00
|
|
|
let(:monday) { Time.zone.now.beginning_of_week }
|
2017-05-12 16:47:18 +02:00
|
|
|
|
2017-11-29 16:07:39 +01:00
|
|
|
before { Timecop.freeze(friday) }
|
2017-10-05 16:10:00 +02:00
|
|
|
after { Timecop.return }
|
|
|
|
|
2017-05-12 16:47:18 +02:00
|
|
|
context 'when no procedure published was active last week' do
|
2019-08-20 18:03:33 +02:00
|
|
|
let!(:procedure) { create(:procedure, :published, libelle: 'procedure') }
|
|
|
|
|
|
|
|
before { instructeur2.assign_to_procedure(procedure) }
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when the instructeur has no notifications' do
|
2017-05-12 16:47:18 +02:00
|
|
|
it { is_expected.to eq(nil) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a procedure published was active' do
|
2019-08-20 18:03:33 +02:00
|
|
|
let!(:procedure) { create(:procedure, :published, libelle: 'procedure') }
|
2017-05-12 16:47:18 +02:00
|
|
|
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
|
|
|
|
|
|
|
|
before :each do
|
2019-08-20 18:03:33 +02:00
|
|
|
instructeur2.assign_to_procedure(procedure)
|
2017-05-12 16:47:18 +02:00
|
|
|
expect_any_instance_of(Procedure).to receive(:procedure_overview).and_return(procedure_overview)
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(instructeur2.last_week_overview[:procedure_overviews]).to match([procedure_overview]) }
|
2017-05-12 16:47:18 +02:00
|
|
|
end
|
|
|
|
|
2020-02-11 15:51:15 +01:00
|
|
|
context 'when a procedure published was active and weekly notifications is disable' do
|
|
|
|
let!(:procedure) { create(:procedure, :published, libelle: 'procedure') }
|
|
|
|
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
instructeur2.assign_to_procedure(procedure)
|
|
|
|
AssignTo
|
|
|
|
.where(instructeur: instructeur2, groupe_instructeur: procedure.groupe_instructeurs.first)
|
|
|
|
.update(weekly_email_notifications_enabled: false)
|
|
|
|
allow_any_instance_of(Procedure).to receive(:procedure_overview).and_return(procedure_overview)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(instructeur2.last_week_overview).to be_nil }
|
|
|
|
end
|
|
|
|
|
2017-05-12 16:47:18 +02:00
|
|
|
context 'when a procedure not published was active with no notifications' do
|
2019-08-20 18:03:33 +02:00
|
|
|
let!(:procedure) { create(:procedure, libelle: 'procedure') }
|
2017-05-12 16:47:18 +02:00
|
|
|
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
|
|
|
|
|
|
|
|
before :each do
|
2019-08-20 18:03:33 +02:00
|
|
|
instructeur2.assign_to_procedure(procedure)
|
2017-05-12 16:47:18 +02:00
|
|
|
allow_any_instance_of(Procedure).to receive(:procedure_overview).and_return(procedure_overview)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(nil) }
|
|
|
|
end
|
|
|
|
end
|
2017-05-16 15:20:38 +02:00
|
|
|
|
2018-10-23 11:39:54 +02:00
|
|
|
describe "procedure_presentation_and_errors_for_procedure_id" do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:procedure_presentation_and_errors) { instructeur.procedure_presentation_and_errors_for_procedure_id(procedure_id) }
|
2018-10-23 11:39:54 +02:00
|
|
|
let(:procedure_presentation) { procedure_presentation_and_errors.first }
|
|
|
|
let(:errors) { procedure_presentation_and_errors.second }
|
2017-10-02 17:03:38 +02:00
|
|
|
|
2018-10-23 11:20:16 +02:00
|
|
|
context 'with explicit presentation' do
|
|
|
|
let(:procedure_id) { procedure.id }
|
|
|
|
let!(:pp) { ProcedurePresentation.create(assign_to: procedure_assign) }
|
|
|
|
|
|
|
|
it { expect(procedure_presentation).to eq(pp) }
|
2018-10-23 11:39:54 +02:00
|
|
|
it { expect(errors).to be_nil }
|
2018-10-23 11:20:16 +02:00
|
|
|
end
|
|
|
|
|
2018-10-23 11:48:25 +02:00
|
|
|
context 'with invalid presentation' do
|
|
|
|
let(:procedure_id) { procedure.id }
|
|
|
|
before do
|
|
|
|
pp = ProcedurePresentation.create(assign_to: procedure_assign, displayed_fields: [{ 'table' => 'invalid', 'column' => 'random' }])
|
|
|
|
pp.save(:validate => false)
|
|
|
|
end
|
|
|
|
|
2022-10-21 17:24:16 +02:00
|
|
|
it 'recreates a valid prsentation' do
|
|
|
|
expect(procedure_presentation).to be_persisted
|
|
|
|
end
|
|
|
|
it { expect(procedure_presentation).to be_valid }
|
2018-10-23 11:48:25 +02:00
|
|
|
it { expect(errors).to be_present }
|
|
|
|
end
|
|
|
|
|
2018-10-23 11:20:16 +02:00
|
|
|
context 'with default presentation' do
|
|
|
|
let(:procedure_id) { procedure_2.id }
|
|
|
|
|
2022-10-21 17:24:16 +02:00
|
|
|
it { expect(procedure_presentation).to be_persisted }
|
2018-10-23 11:39:54 +02:00
|
|
|
it { expect(errors).to be_nil }
|
2018-10-23 11:20:16 +02:00
|
|
|
end
|
2017-10-02 17:03:38 +02:00
|
|
|
end
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
describe '#notifications_for_dossier' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_construction, :followed) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { dossier.follows.first.instructeur }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
subject { instructeur.notifications_for_dossier(dossier) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when the instructeur has just followed the dossier' do
|
2024-09-10 16:09:43 +02:00
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on public champs' do
|
2023-11-28 17:28:03 +01:00
|
|
|
before {
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_public.first.update(value: 'toto')
|
2023-11-28 17:28:03 +01:00
|
|
|
dossier.update(last_champ_updated_at: Time.zone.now)
|
|
|
|
}
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2024-09-10 16:09:43 +02:00
|
|
|
it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) }
|
2020-02-26 22:43:59 +01:00
|
|
|
end
|
|
|
|
|
2021-10-04 10:07:04 +02:00
|
|
|
context 'when there is a modification on identity' do
|
|
|
|
before { dossier.update(identity_updated_at: Time.zone.now) }
|
|
|
|
|
2024-09-10 16:09:43 +02:00
|
|
|
it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) }
|
2021-10-04 10:07:04 +02:00
|
|
|
end
|
|
|
|
|
2020-02-26 22:43:59 +01:00
|
|
|
context 'when there is a modification on groupe instructeur' do
|
|
|
|
let(:groupe_instructeur) { create(:groupe_instructeur, instructeurs: [instructeur], procedure: dossier.procedure) }
|
2023-07-05 17:48:18 +02:00
|
|
|
before { dossier.assign_to_groupe_instructeur(groupe_instructeur, DossierAssignment.modes.fetch(:auto)) }
|
2020-02-26 22:43:59 +01:00
|
|
|
|
2024-09-10 16:09:43 +02:00
|
|
|
it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on private champs' do
|
2023-11-28 17:28:03 +01:00
|
|
|
before {
|
2024-09-27 15:37:11 +02:00
|
|
|
dossier.project_champs_private.first.update(value: 'toto')
|
2023-11-28 17:28:03 +01:00
|
|
|
dossier.update(last_champ_private_updated_at: Time.zone.now)
|
|
|
|
}
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2024-09-10 16:09:43 +02:00
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: true, avis: false, messagerie: false, pieces_jointes: false }) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on avis' do
|
2023-11-28 17:28:03 +01:00
|
|
|
before {
|
|
|
|
create(:avis, dossier: dossier)
|
|
|
|
dossier.update(last_avis_updated_at: Time.zone.now)
|
|
|
|
}
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2024-09-10 16:09:43 +02:00
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: true, messagerie: false, pieces_jointes: false }) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'messagerie' do
|
|
|
|
context 'when there is a new commentaire' do
|
2024-09-10 16:09:43 +02:00
|
|
|
context 'without a file' do
|
|
|
|
before {
|
|
|
|
create(:commentaire, dossier: dossier, email: 'a@b.com')
|
|
|
|
dossier.update(last_commentaire_updated_at: Time.zone.now)
|
|
|
|
}
|
|
|
|
|
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: true, pieces_jointes: false }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a file' do
|
|
|
|
before {
|
|
|
|
create(:commentaire, :with_file, dossier: dossier, email: 'a@b.com')
|
|
|
|
dossier.update(last_commentaire_updated_at: Time.zone.now, last_commentaire_piece_jointe_updated_at: Time.zone.now)
|
|
|
|
}
|
|
|
|
|
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: true, pieces_jointes: true }) }
|
|
|
|
end
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a new commentaire issued by tps' do
|
2018-05-31 15:43:57 +02:00
|
|
|
before { create(:commentaire, dossier: dossier, email: CONTACT_EMAIL) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2024-09-10 16:09:43 +02:00
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-07 18:03:03 +02:00
|
|
|
describe '#notifications_for_groupe_instructeurs' do
|
2023-06-20 15:46:12 +02:00
|
|
|
# a procedure, two groups, 2 instructeurs
|
2021-10-04 10:05:27 +02:00
|
|
|
let(:procedure) { create(:simple_procedure, :routee, :with_type_de_champ_private, :for_individual) }
|
2021-04-07 18:03:03 +02:00
|
|
|
let(:gi_p1) { procedure.groupe_instructeurs.last }
|
2022-12-02 18:15:43 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_construction, :with_individual, :followed, procedure: procedure, groupe_instructeur: gi_p1) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { dossier.follows.first.instructeur }
|
2021-04-07 18:03:03 +02:00
|
|
|
let!(:instructeur_2) { create(:instructeur, groupe_instructeurs: [gi_p1]) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2021-11-12 08:27:02 +01:00
|
|
|
# another procedure, dossier followed by a third instructeur
|
2022-12-02 18:15:43 +01:00
|
|
|
let!(:dossier_on_procedure_2) { create(:dossier, :en_construction, :followed) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let!(:instructeur_on_procedure_2) { dossier_on_procedure_2.follows.first.instructeur }
|
2021-04-07 18:03:03 +02:00
|
|
|
let(:gi_p2) { dossier.groupe_instructeur }
|
|
|
|
|
2020-07-30 11:05:39 +02:00
|
|
|
let(:now) { Time.zone.parse("14/09/1867") }
|
|
|
|
let(:follow) { instructeur.follows.find_by(dossier: dossier) }
|
|
|
|
let(:follow2) { instructeur_2.follows.find_by(dossier: dossier) }
|
2021-04-07 18:03:03 +02:00
|
|
|
|
2020-07-30 11:05:39 +02:00
|
|
|
let(:seen_at_instructeur) { now - 1.hour }
|
|
|
|
let(:seen_at_instructeur2) { now - 1.hour }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur_2.followed_dossiers << dossier
|
2020-07-30 11:05:39 +02:00
|
|
|
Timecop.freeze(now)
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
2020-07-30 11:05:39 +02:00
|
|
|
after { Timecop.return }
|
|
|
|
|
2021-04-07 18:03:03 +02:00
|
|
|
subject { instructeur.notifications_for_groupe_instructeurs(gi_p1)[:en_cours] }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when the instructeur has just followed the dossier' do
|
2017-10-05 16:10:00 +02:00
|
|
|
it { is_expected.to match([]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on public champs' do
|
2020-07-30 11:05:39 +02:00
|
|
|
before do
|
|
|
|
dossier.update!(last_champ_updated_at: now)
|
|
|
|
follow.update_attribute('demande_seen_at', seen_at_instructeur)
|
|
|
|
follow2.update_attribute('demande_seen_at', seen_at_instructeur2)
|
|
|
|
end
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2021-04-07 18:03:03 +02:00
|
|
|
it { is_expected.to match([dossier.id]) }
|
|
|
|
it { expect(instructeur_2.notifications_for_groupe_instructeurs(gi_p1)[:en_cours]).to match([dossier.id]) }
|
|
|
|
it { expect(instructeur_on_procedure_2.notifications_for_groupe_instructeurs(gi_p2)[:en_cours]).to match([]) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
context 'and there is a modification on private champs' do
|
2024-09-27 15:37:11 +02:00
|
|
|
before { dossier.project_champs_private.first.update_attribute('value', 'toto') }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2021-04-07 18:03:03 +02:00
|
|
|
it { is_expected.to match([dossier.id]) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when instructeur update it s public champs last seen' do
|
2020-07-30 11:05:39 +02:00
|
|
|
let(:seen_at_instructeur) { now + 1.hour }
|
|
|
|
let(:seen_at_instructeur2) { now - 1.hour }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
it { is_expected.to match([]) }
|
2021-04-07 18:03:03 +02:00
|
|
|
it { expect(instructeur_2.notifications_for_groupe_instructeurs(gi_p1)[:en_cours]).to match([dossier.id]) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on public champs on a followed dossier from another procedure' do
|
2024-09-27 15:37:11 +02:00
|
|
|
before { dossier_on_procedure_2.project_champs_public.first.update_attribute('value', 'toto') }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
it { is_expected.to match([]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on private champs' do
|
2020-07-30 11:05:39 +02:00
|
|
|
before do
|
|
|
|
dossier.update!(last_champ_private_updated_at: now)
|
|
|
|
follow.update_attribute('annotations_privees_seen_at', seen_at_instructeur)
|
|
|
|
end
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2021-04-07 18:03:03 +02:00
|
|
|
it { is_expected.to match([dossier.id]) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on avis' do
|
2020-07-30 11:05:39 +02:00
|
|
|
before do
|
|
|
|
dossier.update!(last_avis_updated_at: Time.zone.now)
|
|
|
|
follow.update_attribute('avis_seen_at', seen_at_instructeur)
|
|
|
|
end
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2021-04-07 18:03:03 +02:00
|
|
|
it { is_expected.to match([dossier.id]) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
2021-10-04 10:05:27 +02:00
|
|
|
context 'the identity' do
|
|
|
|
context 'when there is a modification on the identity' do
|
|
|
|
before do
|
|
|
|
dossier.update!(identity_updated_at: Time.zone.now)
|
|
|
|
follow.update_attribute('demande_seen_at', seen_at_instructeur)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match([dossier.id]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-05 16:10:00 +02:00
|
|
|
context 'the messagerie' do
|
|
|
|
context 'when there is a new commentaire' do
|
2020-07-30 11:05:39 +02:00
|
|
|
before do
|
|
|
|
dossier.update!(last_commentaire_updated_at: Time.zone.now)
|
|
|
|
follow.update_attribute('messagerie_seen_at', seen_at_instructeur)
|
|
|
|
end
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2021-04-07 18:03:03 +02:00
|
|
|
it { is_expected.to match([dossier.id]) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a new commentaire issued by tps' do
|
2018-05-31 15:43:57 +02:00
|
|
|
before { create(:commentaire, dossier: dossier, email: CONTACT_EMAIL) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
it { is_expected.to match([]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-10 18:16:58 +02:00
|
|
|
describe '#procedure_ids_with_notifications' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_construction, :followed) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { dossier.follows.first.instructeur }
|
2017-10-05 16:10:00 +02:00
|
|
|
let(:procedure) { dossier.procedure }
|
|
|
|
|
2020-09-10 18:16:58 +02:00
|
|
|
subject { instructeur.procedure_ids_with_notifications(:en_cours) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
context 'when there is a modification on public champs' do
|
2020-07-30 11:05:39 +02:00
|
|
|
before { dossier.update!(last_champ_updated_at: Time.zone.now) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
2020-09-10 18:16:58 +02:00
|
|
|
it { is_expected.to match([procedure.id]) }
|
2017-10-05 16:10:00 +02:00
|
|
|
end
|
|
|
|
end
|
2017-10-24 11:41:22 +02:00
|
|
|
|
|
|
|
describe '#mark_tab_as_seen' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_construction, :followed) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { dossier.follows.first.instructeur }
|
2018-10-25 15:17:33 +02:00
|
|
|
let(:freeze_date) { Time.zone.parse('12/12/2012') }
|
2017-10-24 11:41:22 +02:00
|
|
|
|
|
|
|
context 'when demande is acknowledged' do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:follow) { instructeur.follows.find_by(dossier: dossier) }
|
2017-10-24 11:41:22 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
Timecop.freeze(freeze_date)
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur.mark_tab_as_seen(dossier, :demande)
|
2017-10-24 11:41:22 +02:00
|
|
|
end
|
2017-11-29 16:07:39 +01:00
|
|
|
after { Timecop.return }
|
2017-10-24 11:41:22 +02:00
|
|
|
|
|
|
|
it { expect(follow.demande_seen_at).to eq(freeze_date) }
|
|
|
|
end
|
|
|
|
end
|
2018-12-03 13:51:45 +01:00
|
|
|
|
2019-01-10 10:41:03 +01:00
|
|
|
describe '#young_login_token?' do
|
2019-08-06 11:02:54 +02:00
|
|
|
let!(:instructeur) { create(:instructeur) }
|
2019-01-10 10:41:03 +01:00
|
|
|
|
|
|
|
context 'when there is a token' do
|
2019-08-06 11:02:54 +02:00
|
|
|
let!(:good_token) { instructeur.create_trusted_device_token }
|
2019-01-10 10:41:03 +01:00
|
|
|
|
|
|
|
context 'when the token has just been created' do
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(instructeur.young_login_token?).to be true }
|
2019-01-10 10:41:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the token is a bit old' do
|
2019-08-06 11:02:54 +02:00
|
|
|
before { instructeur.trusted_device_tokens.first.update(created_at: (TrustedDeviceToken::LOGIN_TOKEN_YOUTH + 1.minute).ago) }
|
|
|
|
it { expect(instructeur.young_login_token?).to be false }
|
2019-01-10 10:41:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no token' do
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(instructeur.young_login_token?).to be_falsey }
|
2019-01-10 10:41:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-13 17:59:33 +01:00
|
|
|
describe '#email_notification_data' do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2019-03-13 17:59:33 +01:00
|
|
|
let(:procedure_to_assign) { create(:procedure) }
|
|
|
|
|
|
|
|
before do
|
2020-07-20 16:13:51 +02:00
|
|
|
create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, daily_email_notifications_enabled: true)
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dossier in construction exists' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure_to_assign) }
|
2019-03-13 17:59:33 +01:00
|
|
|
|
|
|
|
it do
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(instructeur.email_notification_data).to eq([
|
2019-03-13 17:59:33 +01:00
|
|
|
{
|
|
|
|
nb_en_construction: 1,
|
2020-03-13 10:24:25 +01:00
|
|
|
nb_en_instruction: 0,
|
|
|
|
nb_accepted: 0,
|
2019-03-13 17:59:33 +01:00
|
|
|
nb_notification: 0,
|
|
|
|
procedure_id: procedure_to_assign.id,
|
|
|
|
procedure_libelle: procedure_to_assign.libelle
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a notification exists' do
|
|
|
|
before do
|
2021-04-07 18:03:03 +02:00
|
|
|
allow(instructeur).to receive(:notifications_for_groupe_instructeurs)
|
|
|
|
.with([procedure_to_assign.groupe_instructeurs.first.id])
|
|
|
|
.and_return(en_cours: [1, 2, 3], termines: [])
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(instructeur.email_notification_data).to eq([
|
2019-03-13 17:59:33 +01:00
|
|
|
{
|
|
|
|
nb_en_construction: 0,
|
2020-03-13 10:24:25 +01:00
|
|
|
nb_en_instruction: 0,
|
|
|
|
nb_accepted: 0,
|
2019-03-13 17:59:33 +01:00
|
|
|
nb_notification: 3,
|
|
|
|
procedure_id: procedure_to_assign.id,
|
|
|
|
procedure_libelle: procedure_to_assign.libelle
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 10:24:25 +01:00
|
|
|
context 'when a declarated dossier in instruction exists' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure_to_assign) }
|
2020-03-13 10:24:25 +01:00
|
|
|
|
|
|
|
before do
|
2022-12-02 18:15:43 +01:00
|
|
|
procedure_to_assign.update!(declarative_with_state: "en_instruction")
|
|
|
|
dossier.process_declarative!
|
2020-03-13 10:24:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure_to_assign.declarative_with_state).to eq("en_instruction") }
|
|
|
|
it { expect(dossier.state).to eq("en_instruction") }
|
|
|
|
it do
|
|
|
|
expect(instructeur.email_notification_data).to eq([
|
|
|
|
{
|
|
|
|
nb_en_construction: 0,
|
|
|
|
nb_en_instruction: 1,
|
|
|
|
nb_accepted: 0,
|
|
|
|
nb_notification: 0,
|
|
|
|
procedure_id: procedure_to_assign.id,
|
|
|
|
procedure_libelle: procedure_to_assign.libelle
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a declarated dossier in accepte processed at today exists' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure_to_assign) }
|
2020-03-13 10:24:25 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
procedure_to_assign.update(declarative_with_state: "accepte")
|
2022-12-02 18:15:43 +01:00
|
|
|
dossier.process_declarative!
|
2020-03-13 10:24:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure_to_assign.declarative_with_state).to eq("accepte") }
|
|
|
|
it { expect(dossier.state).to eq("accepte") }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(instructeur.email_notification_data).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a declarated dossier in accepte processed at yesterday exists' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure_to_assign) }
|
2020-03-13 10:24:25 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
procedure_to_assign.update(declarative_with_state: "accepte")
|
2022-12-02 18:15:43 +01:00
|
|
|
dossier.process_declarative!
|
2020-07-02 11:02:50 +02:00
|
|
|
dossier.traitements.last.update(processed_at: Time.zone.yesterday.beginning_of_day)
|
2020-03-13 10:24:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure_to_assign.declarative_with_state).to eq("accepte") }
|
|
|
|
it { expect(dossier.state).to eq("accepte") }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(instructeur.email_notification_data).to eq([
|
|
|
|
{
|
|
|
|
nb_en_construction: 0,
|
|
|
|
nb_en_instruction: 0,
|
|
|
|
nb_accepted: 1,
|
|
|
|
nb_notification: 0,
|
|
|
|
procedure_id: procedure_to_assign.id,
|
|
|
|
procedure_libelle: procedure_to_assign.libelle
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-13 17:59:33 +01:00
|
|
|
context 'otherwise' do
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(instructeur.email_notification_data).to eq([]) }
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-18 11:46:28 +02:00
|
|
|
describe '#procedures' do
|
|
|
|
let(:procedure_a) { create(:procedure) }
|
|
|
|
let(:instructeur_a) { create(:instructeur, groupe_instructeurs: [procedure_a.defaut_groupe_instructeur]) }
|
|
|
|
|
|
|
|
before do
|
2021-03-03 11:32:42 +01:00
|
|
|
gi2 = procedure_a.groupe_instructeurs.create(label: 'gi2')
|
2019-09-18 11:46:28 +02:00
|
|
|
|
|
|
|
instructeur_a.groupe_instructeurs << gi2
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(instructeur_a.procedures.all.to_ary).to eq([procedure_a]) }
|
|
|
|
end
|
|
|
|
|
2020-01-30 10:48:28 +01:00
|
|
|
describe "#can_be_deleted?" do
|
|
|
|
subject { instructeur.can_be_deleted? }
|
|
|
|
|
|
|
|
context 'when the instructeur is an administrateur' do
|
2024-06-01 22:50:48 +02:00
|
|
|
let!(:administrateur) { administrateurs(:default_admin) }
|
2020-01-30 10:48:28 +01:00
|
|
|
let(:instructeur) { administrateur.instructeur }
|
|
|
|
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the instructeur's procedures have other instructeurs" do
|
|
|
|
let(:instructeur_not_admin) { create(:instructeur) }
|
|
|
|
let(:autre_instructeur) { create(:instructeur) }
|
|
|
|
|
|
|
|
it "can be deleted" do
|
|
|
|
assign(procedure, instructeur_assigne: instructeur_not_admin)
|
|
|
|
assign(procedure, instructeur_assigne: autre_instructeur)
|
|
|
|
expect(autre_instructeur.can_be_deleted?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the instructeur's procedures is the only one" do
|
|
|
|
let(:instructeur_not_admin) { create :instructeur }
|
|
|
|
let(:autre_procedure) { create :procedure }
|
|
|
|
it "can be deleted" do
|
|
|
|
assign(autre_procedure, instructeur_assigne: instructeur_not_admin)
|
|
|
|
expect(instructeur_not_admin.can_be_deleted?).to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-09 12:08:41 +02:00
|
|
|
describe "#dossiers_count_summary" do
|
|
|
|
let(:instructeur_2) { create(:instructeur) }
|
2021-04-09 12:25:50 +02:00
|
|
|
let(:instructeur_3) { create(:instructeur) }
|
2021-12-01 14:39:03 +01:00
|
|
|
let(:procedure) { create(:procedure, instructeurs: [instructeur_2, instructeur_3], procedure_expires_when_termine_enabled: true) }
|
2023-03-24 10:21:37 +01:00
|
|
|
let(:gi_1) { procedure.defaut_groupe_instructeur }
|
2023-06-29 11:45:20 +02:00
|
|
|
let(:gi_2) { create(:groupe_instructeur, label: '2', procedure: procedure) }
|
|
|
|
let(:gi_3) { create(:groupe_instructeur, label: '3', procedure: procedure) }
|
2021-04-09 12:08:41 +02:00
|
|
|
|
|
|
|
subject do
|
|
|
|
instructeur_2.dossiers_count_summary([gi_1.id, gi_2.id])
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in, and belonging to gi_1, gi_2" do
|
|
|
|
before do
|
|
|
|
instructeur.groupe_instructeurs << gi_2
|
|
|
|
end
|
|
|
|
|
|
|
|
context "without any dossier" do
|
|
|
|
it { expect(subject['a_suivre']).to eq(0) }
|
|
|
|
it { expect(subject['suivis']).to eq(0) }
|
|
|
|
it { expect(subject['traites']).to eq(0) }
|
|
|
|
it { expect(subject['tous']).to eq(0) }
|
|
|
|
it { expect(subject['archives']).to eq(0) }
|
2021-12-01 14:39:03 +01:00
|
|
|
it { expect(subject['expirant']).to eq(0) }
|
2021-04-09 12:08:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a new brouillon dossier' do
|
|
|
|
let!(:brouillon_dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
|
|
|
it { expect(subject['a_suivre']).to eq(0) }
|
|
|
|
it { expect(subject['suivis']).to eq(0) }
|
|
|
|
it { expect(subject['traites']).to eq(0) }
|
|
|
|
it { expect(subject['tous']).to eq(0) }
|
|
|
|
it { expect(subject['archives']).to eq(0) }
|
2021-12-01 14:39:03 +01:00
|
|
|
it { expect(subject['expirant']).to eq(0) }
|
2021-04-09 12:08:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a new dossier without follower' do
|
|
|
|
let!(:new_unfollow_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
|
|
|
|
|
|
|
it { expect(subject['a_suivre']).to eq(1) }
|
|
|
|
it { expect(subject['suivis']).to eq(0) }
|
|
|
|
it { expect(subject['traites']).to eq(0) }
|
|
|
|
it { expect(subject['tous']).to eq(1) }
|
|
|
|
it { expect(subject['archives']).to eq(0) }
|
2021-12-01 14:39:03 +01:00
|
|
|
it { expect(subject['expirant']).to eq(0) }
|
2021-04-09 12:08:41 +02:00
|
|
|
|
|
|
|
context 'and dossiers without follower on each of the others groups' do
|
|
|
|
let!(:new_unfollow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
|
|
|
|
let!(:new_unfollow_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3) }
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
|
|
it { expect(subject['a_suivre']).to eq(2) }
|
|
|
|
it { expect(subject['tous']).to eq(2) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a new dossier with a follower' do
|
|
|
|
let!(:new_followed_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
instructeur_2.followed_dossiers << new_followed_dossier
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject['a_suivre']).to eq(0) }
|
|
|
|
it { expect(subject['suivis']).to eq(1) }
|
|
|
|
it { expect(subject['traites']).to eq(0) }
|
|
|
|
it { expect(subject['tous']).to eq(1) }
|
|
|
|
it { expect(subject['archives']).to eq(0) }
|
2021-12-01 14:39:03 +01:00
|
|
|
it { expect(subject['expirant']).to eq(0) }
|
2021-04-09 12:08:41 +02:00
|
|
|
|
2021-04-09 12:25:50 +02:00
|
|
|
context 'and another one follows the same dossier' do
|
|
|
|
before do
|
|
|
|
instructeur_3.followed_dossiers << new_followed_dossier
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject['a_suivre']).to eq(0) }
|
|
|
|
it { expect(subject['suivis']).to eq(1) }
|
|
|
|
it { expect(subject['traites']).to eq(0) }
|
|
|
|
it { expect(subject['tous']).to eq(1) }
|
|
|
|
it { expect(subject['archives']).to eq(0) }
|
2021-12-01 14:39:03 +01:00
|
|
|
it { expect(subject['expirant']).to eq(0) }
|
2021-04-09 12:25:50 +02:00
|
|
|
end
|
|
|
|
|
2021-04-09 12:08:41 +02:00
|
|
|
context 'and dossier with a follower on each of the others groups' do
|
|
|
|
let!(:new_follow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
|
|
|
|
let!(:new_follow_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
instructeur_2.followed_dossiers << new_follow_dossier_on_gi_2 << new_follow_dossier_on_gi_3
|
|
|
|
end
|
|
|
|
|
|
|
|
# followed dossiers on another groupe should not be displayed
|
|
|
|
it { expect(subject['suivis']).to eq(2) }
|
|
|
|
it { expect(subject['tous']).to eq(2) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and dossier with a follower is unfollowed' do
|
|
|
|
before do
|
|
|
|
instructeur_2.unfollow(new_followed_dossier)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject['a_suivre']).to eq(1) }
|
|
|
|
it { expect(subject['suivis']).to eq(0) }
|
|
|
|
it { expect(subject['tous']).to eq(1) }
|
2021-12-01 14:39:03 +01:00
|
|
|
it { expect(subject['expirant']).to eq(0) }
|
2021-04-09 12:08:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a termine dossier' do
|
|
|
|
let!(:termine_dossier) { create(:dossier, :accepte, procedure: procedure) }
|
|
|
|
|
|
|
|
it { expect(subject['a_suivre']).to eq(0) }
|
|
|
|
it { expect(subject['suivis']).to eq(0) }
|
|
|
|
it { expect(subject['traites']).to eq(1) }
|
|
|
|
it { expect(subject['tous']).to eq(1) }
|
|
|
|
it { expect(subject['archives']).to eq(0) }
|
2021-12-01 14:39:03 +01:00
|
|
|
it { expect(subject['expirant']).to eq(0) }
|
2021-04-09 12:08:41 +02:00
|
|
|
|
|
|
|
context 'and terminer dossiers on each of the others groups' do
|
|
|
|
let!(:termine_dossier_on_gi_2) { create(:dossier, :accepte, groupe_instructeur: gi_2) }
|
|
|
|
let!(:termine_dossier_on_gi_3) { create(:dossier, :accepte, groupe_instructeur: gi_3) }
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
|
|
it { expect(subject['a_suivre']).to eq(0) }
|
|
|
|
it { expect(subject['suivis']).to eq(0) }
|
2021-12-06 06:12:40 +01:00
|
|
|
it { expect(subject['traites']).to eq(2) }
|
|
|
|
it { expect(subject['tous']).to eq(2) }
|
2021-04-09 12:08:41 +02:00
|
|
|
it { expect(subject['archives']).to eq(0) }
|
2021-12-01 14:39:03 +01:00
|
|
|
it { expect(subject['expirant']).to eq(0) }
|
2021-04-09 12:08:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an archives dossier' do
|
|
|
|
let!(:archives_dossier) { create(:dossier, :en_instruction, procedure: procedure, archived: true) }
|
|
|
|
|
2024-07-30 11:28:54 +02:00
|
|
|
it do
|
|
|
|
expect(subject['a_suivre']).to eq(0)
|
|
|
|
expect(subject['suivis']).to eq(0)
|
|
|
|
expect(subject['traites']).to eq(0)
|
|
|
|
expect(subject['tous']).to eq(0)
|
|
|
|
expect(subject['archives']).to eq(1)
|
|
|
|
expect(subject['supprimes']).to eq(0)
|
|
|
|
expect(subject['expirant']).to eq(0)
|
|
|
|
end
|
2021-04-09 12:08:41 +02:00
|
|
|
|
|
|
|
context 'and terminer dossiers on each of the others groups' do
|
|
|
|
let!(:archives_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2, archived: true) }
|
|
|
|
let!(:archives_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3, archived: true) }
|
|
|
|
|
|
|
|
it { expect(subject['archives']).to eq(2) }
|
|
|
|
end
|
|
|
|
end
|
2021-12-01 14:39:03 +01:00
|
|
|
|
|
|
|
context 'with an expirants dossier' do
|
2022-03-09 10:29:16 +01:00
|
|
|
let!(:expiring_dossier_termine_deleted) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago, hidden_by_administration_at: 2.days.ago) }
|
2024-07-17 16:03:21 +02:00
|
|
|
let!(:expiring_dossier_termine_auto_deleted) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago, hidden_by_expired_at: 2.days.ago) }
|
2021-12-01 14:39:03 +01:00
|
|
|
let!(:expiring_dossier_termine) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago) }
|
|
|
|
let!(:expiring_dossier_en_construction) { create(:dossier, :en_construction, en_construction_at: 175.days.ago, procedure: procedure) }
|
|
|
|
before { subject }
|
|
|
|
|
2024-07-30 11:28:54 +02:00
|
|
|
it do
|
|
|
|
expect(subject['a_suivre']).to eq(1)
|
|
|
|
expect(subject['suivis']).to eq(0)
|
|
|
|
expect(subject['traites']).to eq(1)
|
|
|
|
expect(subject['tous']).to eq(2)
|
|
|
|
expect(subject['archives']).to eq(0)
|
|
|
|
expect(subject['supprimes']).to eq(2)
|
|
|
|
expect(subject['expirant']).to eq(2)
|
|
|
|
end
|
2021-12-01 14:39:03 +01:00
|
|
|
end
|
2021-04-09 12:08:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-07 14:34:01 +02:00
|
|
|
describe '#merge' do
|
|
|
|
let(:old_instructeur) { create(:instructeur) }
|
|
|
|
let(:new_instructeur) { create(:instructeur) }
|
|
|
|
|
|
|
|
subject { new_instructeur.merge(old_instructeur) }
|
|
|
|
|
2021-10-12 11:04:06 +02:00
|
|
|
context 'when the old instructeur does not exist' do
|
|
|
|
let(:old_instructeur) { nil }
|
|
|
|
|
|
|
|
it { expect { subject }.not_to raise_error }
|
|
|
|
end
|
|
|
|
|
2021-10-07 14:34:01 +02:00
|
|
|
context 'when an procedure is assigned to the old instructeur' do
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.defaut_groupe_instructeur.instructeurs << old_instructeur
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'transfers the assignment' do
|
|
|
|
expect(new_instructeur.procedures).to match_array(procedure)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when both instructeurs are assigned to the same procedure' do
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.defaut_groupe_instructeur.instructeurs << old_instructeur
|
|
|
|
procedure.defaut_groupe_instructeur.instructeurs << new_instructeur
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'keeps the assignment' do
|
|
|
|
expect(new_instructeur.procedures).to match_array(procedure)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dossier is followed by an old instructeur' do
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
old_instructeur.followed_dossiers << dossier
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'transfers the dossier' do
|
|
|
|
expect(new_instructeur.followed_dossiers).to match_array(dossier)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when both instructeurs follow the same dossier' do
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
old_instructeur.followed_dossiers << dossier
|
|
|
|
new_instructeur.followed_dossiers << dossier
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change anything' do
|
|
|
|
expect(new_instructeur.followed_dossiers.pluck(:id)).to match_array(dossier.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the old instructeur is on on admin list' do
|
2024-06-01 22:50:48 +02:00
|
|
|
let(:administrateur) { administrateurs(:default_admin) }
|
2021-10-07 14:34:01 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
administrateur.instructeurs << old_instructeur
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is replaced by the new one' do
|
|
|
|
expect(administrateur.reload.instructeurs).to match_array(new_instructeur)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when both are on the same admin list' do
|
2024-06-01 22:50:48 +02:00
|
|
|
let(:administrateur) { administrateurs(:default_admin) }
|
2021-10-07 14:34:01 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
administrateur.instructeurs << old_instructeur
|
|
|
|
administrateur.instructeurs << new_instructeur
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes the old one' do
|
|
|
|
expect(administrateur.reload.instructeurs).to match_array(new_instructeur)
|
|
|
|
end
|
|
|
|
end
|
2022-05-17 15:20:33 +02:00
|
|
|
|
|
|
|
context 'when old instructeur has avis' do
|
|
|
|
let(:avis) { create(:avis, claimant: old_instructeur) }
|
|
|
|
before do
|
|
|
|
avis
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
it 'reassign avis to new_instructeur' do
|
|
|
|
avis.reload
|
|
|
|
expect(avis.claimant).to eq(new_instructeur)
|
|
|
|
end
|
|
|
|
end
|
2021-10-07 14:34:01 +02:00
|
|
|
end
|
|
|
|
|
2018-12-03 13:51:45 +01:00
|
|
|
private
|
|
|
|
|
2020-01-30 10:48:28 +01:00
|
|
|
def assign(procedure_to_assign, instructeur_assigne: instructeur)
|
|
|
|
create :assign_to, instructeur: instructeur_assigne, procedure: procedure_to_assign, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur
|
2018-12-03 13:51:45 +01:00
|
|
|
end
|
2015-09-22 10:15:12 +02:00
|
|
|
end
|