2016-12-15 17:59:01 +01:00
|
|
|
|
require "spec_helper"
|
2015-12-15 11:02:07 +01:00
|
|
|
|
|
|
|
|
|
RSpec.describe NotificationMailer, type: :mailer do
|
2017-10-13 18:35:12 +02:00
|
|
|
|
shared_examples_for "create a commentaire not notified" do
|
|
|
|
|
it do
|
|
|
|
|
expect { subject.deliver_now }.to change { Commentaire.count }.by(1)
|
|
|
|
|
expect { subject.deliver_now }.to_not change { Notification.count }
|
|
|
|
|
|
|
|
|
|
subject.deliver_now
|
|
|
|
|
commentaire = Commentaire.last
|
2018-01-08 17:26:13 +01:00
|
|
|
|
expect(commentaire.body).to include(email_template.subject_for_dossier(dossier), email_template.body_for_dossier(dossier))
|
2017-10-13 18:35:12 +02:00
|
|
|
|
expect(commentaire.dossier).to eq(dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
let(:dossier) { create(:dossier, user: user) }
|
|
|
|
|
|
2017-03-05 20:20:29 +01:00
|
|
|
|
describe '.send_notification' do
|
2018-01-08 17:26:13 +01:00
|
|
|
|
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }
|
2017-06-09 22:29:48 +02:00
|
|
|
|
let(:attestation) { nil }
|
|
|
|
|
let(:notifications_count_before) { Notification.count }
|
|
|
|
|
|
2017-10-13 18:35:12 +02:00
|
|
|
|
subject { described_class.send_notification(dossier, email_template, attestation) }
|
2017-03-05 20:20:29 +01:00
|
|
|
|
|
2018-01-08 17:26:13 +01:00
|
|
|
|
it { expect(subject.subject).to eq(email_template.subject_for_dossier) }
|
2017-10-13 18:35:12 +02:00
|
|
|
|
it { expect(subject.body).to eq(email_template.body_for_dossier) }
|
2017-06-09 22:29:48 +02:00
|
|
|
|
it { expect(subject.attachments['attestation.pdf']).to eq(nil) }
|
|
|
|
|
|
|
|
|
|
context 'when an attestation is provided' do
|
|
|
|
|
let(:attestation) { 'attestation' }
|
|
|
|
|
|
|
|
|
|
it do
|
|
|
|
|
expect(subject.attachments['attestation.pdf'].content_type)
|
|
|
|
|
.to eq('application/pdf; filename=attestation.pdf')
|
|
|
|
|
|
|
|
|
|
expect(subject.attachments['attestation.pdf'].body).to eq('attestation')
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-05-11 18:07:37 +02:00
|
|
|
|
|
2017-10-13 18:35:12 +02:00
|
|
|
|
it_behaves_like "create a commentaire not notified"
|
|
|
|
|
end
|
2017-05-11 18:07:37 +02:00
|
|
|
|
|
2017-10-13 18:35:12 +02:00
|
|
|
|
describe '.send_dossier_received' do
|
|
|
|
|
subject { described_class.send_dossier_received(dossier.id) }
|
|
|
|
|
let(:email_template) { create(:received_mail) }
|
2017-05-11 18:07:37 +02:00
|
|
|
|
|
2017-10-13 18:35:12 +02:00
|
|
|
|
before do
|
|
|
|
|
dossier.procedure.received_mail = email_template
|
2017-05-11 18:07:37 +02:00
|
|
|
|
end
|
2017-10-13 18:35:12 +02:00
|
|
|
|
|
|
|
|
|
it do
|
2018-01-08 17:26:13 +01:00
|
|
|
|
expect(subject.subject).to eq(email_template.subject)
|
2017-10-13 18:35:12 +02:00
|
|
|
|
expect(subject.body).to eq(email_template.body)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it_behaves_like "create a commentaire not notified"
|
2017-03-05 20:20:29 +01:00
|
|
|
|
end
|
|
|
|
|
|
2015-12-15 11:02:07 +01:00
|
|
|
|
describe ".new_answer" do
|
|
|
|
|
subject(:subject) { described_class.new_answer(dossier) }
|
|
|
|
|
|
2017-01-03 11:36:08 +01:00
|
|
|
|
it { expect(subject.body).to match('Un nouveau message est disponible dans votre espace TPS.') }
|
2015-12-15 15:33:21 +01:00
|
|
|
|
it { expect(subject.body).to include("Pour le consulter, merci de vous rendre sur #{users_dossier_recapitulatif_url(dossier_id: dossier.id)}") }
|
2017-04-06 18:16:11 +02:00
|
|
|
|
it { expect(subject.subject).to eq("Nouveau message pour votre dossier TPS nº #{dossier.id}") }
|
2015-12-15 11:02:07 +01:00
|
|
|
|
end
|
|
|
|
|
end
|