demarches-normaliennes/spec/mailers/notification_mailer_spec.rb

67 lines
2.4 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

require "spec_helper"
RSpec.describe NotificationMailer, type: :mailer do
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
expect(commentaire.body).to include(email_template.object_for_dossier(dossier), email_template.body_for_dossier(dossier))
expect(commentaire.dossier).to eq(dossier)
end
end
let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user) }
describe '.send_notification' do
let(:email_template) { instance_double('email_template', object_for_dossier: 'object', body_for_dossier: 'body') }
let(:attestation) { nil }
let(:notifications_count_before) { Notification.count }
subject { described_class.send_notification(dossier, email_template, attestation) }
it { expect(subject.subject).to eq(email_template.object_for_dossier) }
it { expect(subject.body).to eq(email_template.body_for_dossier) }
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
it_behaves_like "create a commentaire not notified"
end
describe '.send_dossier_received' do
subject { described_class.send_dossier_received(dossier.id) }
let(:email_template) { create(:received_mail) }
before do
dossier.procedure.received_mail = email_template
end
it do
expect(subject.subject).to eq(email_template.object)
expect(subject.body).to eq(email_template.body)
end
it_behaves_like "create a commentaire not notified"
end
describe ".new_answer" do
subject(:subject) { described_class.new_answer(dossier) }
it { expect(subject.body).to match('Un nouveau message est disponible dans votre espace TPS.') }
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
end