Mail for receive dossier is now send.
This commit is contained in:
parent
12ebab66cc
commit
f03733f3ff
9 changed files with 112 additions and 18 deletions
|
@ -54,6 +54,8 @@ class Backoffice::DossiersController < ApplicationController
|
|||
@facade.dossier.next_step! 'gestionnaire', 'receive'
|
||||
flash.notice = 'Dossier considéré comme reçu.'
|
||||
|
||||
NotificationMailer.dossier_received(@facade.dossier).deliver_now!
|
||||
|
||||
render 'show'
|
||||
end
|
||||
|
||||
|
|
|
@ -3,6 +3,10 @@ class NotificationMailer < ApplicationMailer
|
|||
send_mail dossier, "Nouveau commentaire pour votre dossier TPS N°#{dossier.id}"
|
||||
end
|
||||
|
||||
def dossier_received dossier
|
||||
send_mail dossier, MailTemplate.replace_tags(dossier.procedure.mail_received.object, dossier)
|
||||
end
|
||||
|
||||
def dossier_validated dossier
|
||||
send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été validé"
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ class MailReceived < MailTemplate
|
|||
self.body ||= "Bonjour,
|
||||
<br>
|
||||
<br>
|
||||
Votre administration vous confirme la bonne réception de votre dossier complet. Celui-ci sera instruit dans le délais légal déclaré par votre interlocuteur.<br>
|
||||
Votre administration vous confirme la bonne réception de votre dossier n°--numero_dossier-- complet. Celui-ci sera instruit dans le délais légal déclaré par votre interlocuteur.<br>
|
||||
<br>
|
||||
En vous souhaitant une bonne journée,
|
||||
<br>
|
||||
|
|
|
@ -1,10 +1,33 @@
|
|||
class MailTemplate < ActiveRecord::Base
|
||||
belongs_to :procedure
|
||||
|
||||
enum balises: {
|
||||
enum tags: {
|
||||
numero_dossier: {
|
||||
attr: 'dossier.id',
|
||||
description: "Permet d'afficher le numéro de dossier de l'utilisateur."
|
||||
},
|
||||
libelle_procedure: {
|
||||
description: "Permet d'afficher le libellé de la procédure."
|
||||
}
|
||||
}
|
||||
|
||||
def self.replace_tags string, dossier
|
||||
@dossier = dossier
|
||||
|
||||
tags.inject(string) do |acc, tag|
|
||||
acc.gsub!("--#{tag.first}--", replace_tag(tag.first.to_sym)) || acc
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.replace_tag tag
|
||||
case tag
|
||||
when :numero_dossier
|
||||
@dossier.id.to_s
|
||||
when :libelle_procedure
|
||||
@dossier.procedure.libelle
|
||||
else
|
||||
'--BALISE_NON_RECONNUE--'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
Balise
|
||||
%th
|
||||
Description
|
||||
- MailTemplate.balises.each do |balise|
|
||||
- MailTemplate.tags.each do |balise|
|
||||
%tr
|
||||
%td.center
|
||||
%b.text-success
|
||||
|
|
1
app/views/notification_mailer/dossier_received.text.erb
Normal file
1
app/views/notification_mailer/dossier_received.text.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= MailTemplate.replace_tags @dossier.procedure.mail_received.body, @dossier %>
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe Backoffice::DossiersController, type: :controller do
|
||||
before do
|
||||
@request.env['HTTP_REFERER'] = TPS::Application::URL
|
||||
@request.env['HTTP_REFERER'] = TPS::Application::URL
|
||||
end
|
||||
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
|
@ -125,11 +125,24 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
it 'change state to received' do
|
||||
post :receive, dossier_id: dossier_id
|
||||
subject { post :receive, dossier_id: dossier_id }
|
||||
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('received')
|
||||
context 'when it post a receive instruction' do
|
||||
before do
|
||||
subject
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it 'change state to received' do
|
||||
expect(dossier.state).to eq('received')
|
||||
end
|
||||
end
|
||||
|
||||
it 'Notification email is send' do
|
||||
expect(NotificationMailer).to receive(:dossier_received).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -34,4 +34,14 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
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
|
||||
|
||||
describe '.dossier_received' do
|
||||
let(:user) { create(:user) }
|
||||
let(:dossier) { create(:dossier, user: user) }
|
||||
|
||||
subject(:subject) { described_class.dossier_received(dossier) }
|
||||
|
||||
it { expect(subject.subject).to eq("[TPS] Accusé de réception pour votre dossier n°#{dossier.id}") }
|
||||
it { expect(subject.body).to match("Votre administration vous confirme la bonne réception de votre dossier n°#{dossier.id}") }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,22 +6,63 @@ describe MailTemplate do
|
|||
|
||||
it { is_expected.to belong_to(:procedure) }
|
||||
|
||||
describe '.balises' do
|
||||
subject { MailTemplate.balises }
|
||||
describe '.tags' do
|
||||
subject { MailTemplate.tags }
|
||||
|
||||
it { expect(subject.size).to eq 1 }
|
||||
it { expect(subject.size).to eq 2 }
|
||||
|
||||
describe 'numero_dossier' do
|
||||
subject { super().first }
|
||||
|
||||
it { expect(subject.first).to eq 'numero_dossier' }
|
||||
subject { super()['numero_dossier'] }
|
||||
|
||||
describe 'attr and description value' do
|
||||
subject { super().second }
|
||||
|
||||
it { expect(subject[:attr]).to eq 'dossier.id' }
|
||||
it { expect(subject[:description]).to eq "Permet d'afficher le numéro de dossier de l'utilisateur." }
|
||||
it { expect(subject['description']).to eq "Permet d'afficher le numéro de dossier de l'utilisateur." }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'numero_dossier' do
|
||||
subject { super()['libelle_procedure'] }
|
||||
|
||||
describe 'attr and description value' do
|
||||
|
||||
it { expect(subject['description']).to eq "Permet d'afficher le libellé de la procédure." }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.replace_tags' do
|
||||
let(:dossier) { create :dossier }
|
||||
let(:procedure) { dossier.procedure }
|
||||
let(:mail_received) { procedure.mail_received }
|
||||
|
||||
describe 'for tag --numero_dossier--' do
|
||||
before do
|
||||
procedure.mail_received.update_column(:object, '[TPS] Dossier n°--numero_dossier--')
|
||||
end
|
||||
|
||||
subject { MailTemplate.replace_tags procedure.mail_received.object, dossier }
|
||||
|
||||
it { expect(subject).to eq "[TPS] Dossier n°#{dossier.id}" }
|
||||
end
|
||||
|
||||
describe 'for tag --libelle_procedure--' do
|
||||
before do
|
||||
procedure.mail_received.update_column(:object, '[TPS] Dossier pour la procédure --libelle_procedure--')
|
||||
end
|
||||
|
||||
subject { MailTemplate.replace_tags procedure.mail_received.object, dossier }
|
||||
|
||||
it { expect(subject).to eq "[TPS] Dossier pour la procédure #{procedure.libelle}" }
|
||||
end
|
||||
|
||||
describe 'multiple tags' do
|
||||
before do
|
||||
procedure.mail_received.update_column(:object, '[TPS] Dossier n°--numero_dossier-- pour la procédure --libelle_procedure-- et encore le numéro : --numero_dossier--')
|
||||
end
|
||||
|
||||
subject { MailTemplate.replace_tags procedure.mail_received.object, dossier }
|
||||
|
||||
it { expect(subject).to eq "[TPS] Dossier n°#{dossier.id} pour la procédure #{procedure.libelle} et encore le numéro : #{dossier.id}" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue