demarches-normaliennes/spec/mailers/avis_mailer_spec.rb

29 lines
1.4 KiB
Ruby
Raw Normal View History

RSpec.describe AvisMailer, type: :mailer do
describe '.avis_invitation' do
2021-02-28 22:20:24 +01:00
let(:claimant) { create(:instructeur) }
let(:expert) { create(:expert) }
let(:dossier) { create(:dossier) }
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) }
let(:avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, introduction: 'intro') }
subject { described_class.avis_invitation(avis.reload) }
it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") }
2018-12-04 11:06:04 +01:00
it { expect(subject.body).to have_text("Vous avez été invité par\r\n#{avis.claimant.email}\r\nà donner votre avis sur le dossier nº #{avis.dossier.id} de la démarche :\r\n#{avis.dossier.procedure.libelle}") }
it { expect(subject.body).to include(avis.introduction) }
2020-05-20 16:32:06 +02:00
it { expect(subject.body).to include(instructeur_avis_url(avis.dossier.procedure.id, avis)) }
context 'when the recipient is not already registered' do
2021-02-28 22:20:24 +01:00
it { expect(subject.body).to include(sign_up_expert_avis_url(avis.dossier.procedure.id, avis.id, avis.expert.email)) }
end
context 'when the dossier has been deleted before the avis was sent' do
before { dossier.update(hidden_at: Time.zone.now) }
it 'doesnt send the email' do
expect(subject.body).to be_blank
end
end
end
end