Notification Mailer: use send_notification for all the mails
This commit is contained in:
parent
70b2020656
commit
6c560e65eb
4 changed files with 22 additions and 43 deletions
|
@ -95,40 +95,46 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.initiated_mail).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
||||
def refuse
|
||||
create_dossier_facade params[:dossier_id]
|
||||
|
||||
@facade.dossier.next_step! 'gestionnaire', 'refuse'
|
||||
dossier = @facade.dossier
|
||||
|
||||
dossier.next_step! 'gestionnaire', 'refuse'
|
||||
flash.notice = 'Dossier considéré comme refusé.'
|
||||
|
||||
NotificationMailer.dossier_refused(@facade.dossier).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.refused_mail).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
||||
def without_continuation
|
||||
create_dossier_facade params[:dossier_id]
|
||||
|
||||
@facade.dossier.next_step! 'gestionnaire', 'without_continuation'
|
||||
dossier = @facade.dossier
|
||||
|
||||
dossier.next_step! 'gestionnaire', 'without_continuation'
|
||||
flash.notice = 'Dossier considéré comme sans suite.'
|
||||
|
||||
NotificationMailer.dossier_without_continuation(@facade.dossier).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.without_continuation_mail).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
||||
def close
|
||||
create_dossier_facade params[:dossier_id]
|
||||
|
||||
@facade.dossier.next_step! 'gestionnaire', 'close'
|
||||
dossier = @facade.dossier
|
||||
|
||||
dossier.next_step! 'gestionnaire', 'close'
|
||||
flash.notice = 'Dossier traité avec succès.'
|
||||
|
||||
NotificationMailer.dossier_closed(@facade.dossier).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.closed_mail).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: @facade.dossier.id)
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
||||
def follow
|
||||
|
|
|
@ -15,22 +15,6 @@ class NotificationMailer < ApplicationMailer
|
|||
send_mail dossier, "Nouveau message pour votre dossier TPS N°#{dossier.id}"
|
||||
end
|
||||
|
||||
def dossier_submitted dossier
|
||||
send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été déposé"
|
||||
end
|
||||
|
||||
def dossier_without_continuation dossier
|
||||
send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été classé sans suite"
|
||||
end
|
||||
|
||||
def dossier_refused dossier
|
||||
send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été refusé"
|
||||
end
|
||||
|
||||
def dossier_closed dossier
|
||||
send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été accepté"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def vars_mailer dossier
|
||||
|
|
|
@ -262,7 +262,8 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:dossier_refused).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(RefusedMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
|
@ -287,7 +288,8 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:dossier_without_continuation).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(WithoutContinuationMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
|
@ -311,7 +313,8 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:dossier_closed).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(ClosedMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
|
|
|
@ -21,18 +21,4 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
it { expect(subject.body).to include("Pour le consulter, merci de vous rendre sur #{users_dossier_recapitulatif_url(dossier_id: dossier.id)}") }
|
||||
it { expect(subject.subject).to eq("Nouveau message pour votre dossier TPS N°#{dossier.id}") }
|
||||
end
|
||||
|
||||
describe ".dossier_submitted" do
|
||||
let(:user) { create(:user) }
|
||||
let(:dossier) { create(:dossier, user: user) }
|
||||
|
||||
subject(:subject) { described_class.dossier_submitted(dossier) }
|
||||
|
||||
before { dossier.reload }
|
||||
|
||||
it { expect(subject.body).to match("Nous vous confirmons que votre dossier N°#{dossier.id} a été déposé") }
|
||||
it { expect(subject.body).to match("auprès de #{dossier.procedure.organisation} avec succès") }
|
||||
it { expect(subject.body).to match("ce jour à #{dossier.updated_at}.") }
|
||||
it { expect(subject.subject).to eq("Votre dossier TPS N°#{dossier.id} a été déposé") }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue