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 ) }
2022-03-09 10:29:16 +01:00
let ( :dossier ) { create ( :dossier , :en_construction ) }
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
2022-06-13 13:44:06 +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 ) }
2022-06-13 13:44:06 +02:00
it { expect ( subject . body ) . to include ( targeted_user_link_url ( TargetedUserLink . where ( target_model : avis ) . first ) ) }
it { expect { subject . body } . to change { TargetedUserLink . where ( target_model : avis ) . count } . from ( 0 ) . to ( 1 ) }
2021-04-12 10:35:52 +02:00
context 'when the dossier has been deleted before the avis was sent' do
2022-03-09 10:29:16 +01:00
before { dossier . update ( hidden_by_user_at : 1 . hour . ago ) }
2021-04-12 10:35:52 +02:00
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