instructors : receive daily emails for declarative folders
This commit is contained in:
parent
50af70ad7c
commit
395af2fbb0
5 changed files with 181 additions and 0 deletions
|
@ -152,6 +152,8 @@ class Instructeur < ApplicationRecord
|
|||
|
||||
h = {
|
||||
nb_en_construction: groupe.dossiers.en_construction.count,
|
||||
nb_en_instruction: groupe.dossiers.en_instruction.count,
|
||||
nb_accepted: groupe.dossiers.accepte.where(processed_at: Time.zone.yesterday.beginning_of_day..Time.zone.yesterday.end_of_day).count,
|
||||
nb_notification: notifications_for_procedure(procedure, :not_archived).count
|
||||
}
|
||||
|
||||
|
@ -161,6 +163,14 @@ class Instructeur < ApplicationRecord
|
|||
acc << h
|
||||
end
|
||||
|
||||
[["en_instruction", h[:nb_en_instruction]], ["accepte", h[:nb_accepted]]].each do |state, count|
|
||||
if procedure.declarative_with_state == state && count > 0
|
||||
h[:procedure_id] = procedure.id
|
||||
h[:procedure_libelle] = procedure.libelle
|
||||
acc << h
|
||||
end
|
||||
end
|
||||
|
||||
acc
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,5 +16,12 @@
|
|||
- if datum[:nb_notification] > 0
|
||||
%br
|
||||
#{datum[:nb_notification]} #{'notification'.pluralize(datum[:nb_notification])}
|
||||
- if datum[:nb_en_instruction] > 0
|
||||
%br
|
||||
#{datum[:nb_en_instruction]} #{'dossier'.pluralize(datum[:nb_en_instruction])}
|
||||
- if datum[:nb_accepted] > 0
|
||||
%br
|
||||
#{datum[:nb_accepted]} #{'dossier'.pluralize(datum[:nb_accepted])}
|
||||
|
||||
|
||||
= render partial: "layouts/mailers/signature"
|
||||
|
|
|
@ -401,6 +401,8 @@ describe Instructeur, type: :model do
|
|||
expect(instructeur.email_notification_data).to eq([
|
||||
{
|
||||
nb_en_construction: 1,
|
||||
nb_en_instruction: 0,
|
||||
nb_accepted: 0,
|
||||
nb_notification: 0,
|
||||
procedure_id: procedure_to_assign.id,
|
||||
procedure_libelle: procedure_to_assign.libelle
|
||||
|
@ -420,6 +422,8 @@ describe Instructeur, type: :model do
|
|||
expect(instructeur.email_notification_data).to eq([
|
||||
{
|
||||
nb_en_construction: 0,
|
||||
nb_en_instruction: 0,
|
||||
nb_accepted: 0,
|
||||
nb_notification: 3,
|
||||
procedure_id: procedure_to_assign.id,
|
||||
procedure_libelle: procedure_to_assign.libelle
|
||||
|
@ -428,6 +432,75 @@ describe Instructeur, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when a declarated dossier in instruction exists' do
|
||||
let!(:dossier) { create(:dossier, procedure: procedure_to_assign, state: Dossier.states.fetch(:en_construction)) }
|
||||
|
||||
before do
|
||||
procedure_to_assign.update(declarative_with_state: "en_instruction")
|
||||
DeclarativeProceduresJob.new.perform
|
||||
dossier.reload
|
||||
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
|
||||
let!(:dossier) { create(:dossier, procedure: procedure_to_assign, state: Dossier.states.fetch(:en_construction)) }
|
||||
|
||||
before do
|
||||
procedure_to_assign.update(declarative_with_state: "accepte")
|
||||
DeclarativeProceduresJob.new.perform
|
||||
dossier.reload
|
||||
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
|
||||
let!(:dossier) { create(:dossier, procedure: procedure_to_assign, state: Dossier.states.fetch(:en_construction)) }
|
||||
|
||||
before do
|
||||
procedure_to_assign.update(declarative_with_state: "accepte")
|
||||
DeclarativeProceduresJob.new.perform
|
||||
dossier.update(processed_at: Time.zone.yesterday.beginning_of_day)
|
||||
dossier.reload
|
||||
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
|
||||
|
||||
context 'otherwise' do
|
||||
it { expect(instructeur.email_notification_data).to eq([]) }
|
||||
end
|
||||
|
|
|
@ -47,6 +47,49 @@ describe NotificationService do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when a declarative dossier in instruction exists on this procedure' do
|
||||
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
before do
|
||||
procedure.update(declarative_with_state: "en_instruction")
|
||||
DeclarativeProceduresJob.new.perform
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it do
|
||||
subject
|
||||
expect(InstructeurMailer).to have_received(:send_notifications)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a declarative dossier in accepte on yesterday exists on this procedure' do
|
||||
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
before do
|
||||
procedure.update(declarative_with_state: "accepte")
|
||||
DeclarativeProceduresJob.new.perform
|
||||
dossier.update(processed_at: Time.zone.yesterday.beginning_of_day)
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it do
|
||||
subject
|
||||
expect(InstructeurMailer).to have_received(:send_notifications)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a declarative dossier in accepte on today exists on this procedure' do
|
||||
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
before do
|
||||
procedure.update(declarative_with_state: "accepte")
|
||||
DeclarativeProceduresJob.new.perform
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it do
|
||||
subject
|
||||
expect(InstructeurMailer).not_to have_received(:send_notifications)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is a notification on this procedure' do
|
||||
before do
|
||||
allow_any_instance_of(Instructeur).to receive(:notifications_for_procedure)
|
||||
|
|
|
@ -16,6 +16,8 @@ describe 'instructeur_mailer/send_notifications.html.haml', type: :view do
|
|||
procedure_libelle: 'une superbe démarche',
|
||||
procedure_id: 213,
|
||||
nb_en_construction: 1,
|
||||
nb_en_instruction: 0,
|
||||
nb_accepted: 0,
|
||||
nb_notification: 0
|
||||
}
|
||||
]
|
||||
|
@ -27,6 +29,50 @@ describe 'instructeur_mailer/send_notifications.html.haml', type: :view do
|
|||
it { expect(rendered).not_to have_text('notification') }
|
||||
end
|
||||
|
||||
context 'when there is one declarated dossier in instruction' do
|
||||
let(:data) do
|
||||
[
|
||||
{
|
||||
procedure_libelle: 'une superbe démarche',
|
||||
procedure_id: 213,
|
||||
nb_en_construction: 0,
|
||||
nb_en_instruction: 1,
|
||||
nb_accepted: 0,
|
||||
nb_notification: 0
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
it { expect(rendered).to have_link('une superbe démarche', href: procedure_url(213)) }
|
||||
it { expect(rendered).to have_text('une superbe démarche') }
|
||||
it { expect(rendered).to have_text('1 dossier') }
|
||||
it { expect(rendered).not_to have_text('notification') }
|
||||
it { expect(rendered).not_to have_text('construction') }
|
||||
it { expect(rendered).not_to have_text('accepte') }
|
||||
end
|
||||
|
||||
context 'when there is one declarated dossier in accepte' do
|
||||
let(:data) do
|
||||
[
|
||||
{
|
||||
procedure_libelle: 'une superbe démarche',
|
||||
procedure_id: 213,
|
||||
nb_en_construction: 0,
|
||||
nb_en_instruction: 0,
|
||||
nb_accepted: 1,
|
||||
nb_notification: 0
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
it { expect(rendered).to have_link('une superbe démarche', href: procedure_url(213)) }
|
||||
it { expect(rendered).to have_text('une superbe démarche') }
|
||||
it { expect(rendered).to have_text('1 dossier') }
|
||||
it { expect(rendered).not_to have_text('notification') }
|
||||
it { expect(rendered).not_to have_text('construction') }
|
||||
it { expect(rendered).not_to have_text('instruction') }
|
||||
end
|
||||
|
||||
context 'when there is one notification' do
|
||||
let(:data) do
|
||||
[
|
||||
|
@ -34,6 +80,8 @@ describe 'instructeur_mailer/send_notifications.html.haml', type: :view do
|
|||
procedure_libelle: 'une superbe démarche',
|
||||
procedure_id: 213,
|
||||
nb_en_construction: 0,
|
||||
nb_en_instruction: 0,
|
||||
nb_accepted: 0,
|
||||
nb_notification: 1
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue