2017-05-02 15:37:06 +02:00
RSpec . describe AvisMailer , type : :mailer do
2017-06-07 18:18:24 +02:00
describe '.avis_invitation' do
2021-02-28 22:20:24 +01:00
let ( :claimant ) { create ( :instructeur ) }
let ( :expert ) { create ( :expert ) }
let ( :dossier ) { create ( :dossier ) }
2021-03-23 12:25:57 +01:00
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' ) }
2017-05-02 15:37:06 +02:00
2021-04-12 10:35:52 +02:00
subject { described_class . avis_invitation ( avis . reload ) }
2017-05-02 15:37:06 +02:00
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 } " ) }
2017-05-02 15:37:06 +02:00
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 ) ) }
2018-08-08 13:19:23 +02:00
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 ) ) }
2018-08-08 13:19:23 +02:00
end
2021-04-12 10:35:52 +02:00
context 'when the dossier has been deleted before the avis was sent' do
before { dossier . update ( hidden_at : Time . zone . now ) }
it 'doesn’ t send the email' do
expect ( subject . body ) . to be_blank
end
end
2017-05-02 15:37:06 +02:00
end
end