demarches-normaliennes/spec/mailers/notification_mailer_spec.rb
Simon Lehericey e60ce35ae8 [Fix #196] Attestation: join the attestation to the closed mail
Add a upper limit to the attachment size as it could be a problem with Mailjet and receiver
(https://www.mailjet.com/support/what-is-the-size-limit-for-attachments-files-sent-via-mailjet,289.htm)

If the attestation cannot be sent, it is logged in sentry
2017-06-16 12:11:10 +02:00

51 lines
2 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
describe '.send_notification' do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user) }
let(:email) { instance_double('email', object_for_dossier: 'object', body_for_dossier: 'body') }
let(:attestation) { nil }
let(:notifications_count_before) { Notification.count }
subject { described_class.send_notification(dossier, email, attestation) }
it { expect(subject.subject).to eq(email.object_for_dossier) }
it { expect(subject.body).to eq(email.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 "creates a commentaire, which is not notified" do
described_class.send_notification(dossier, email).deliver_now
commentaire = Commentaire.last
notifications_count_after = Notification.count
expect(commentaire.dossier).to eq(dossier)
expect(commentaire.email).to eq("contact@tps.apientreprise.fr")
expect(commentaire.body).to eq("[object]<br><br>body")
expect(notifications_count_before).to eq(notifications_count_after)
end
end
describe ".new_answer" do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user) }
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