2018-07-16 14:39:04 +02:00
RSpec . describe DossierMailer , type : :mailer do
2019-08-06 11:02:54 +02:00
let ( :to_email ) { 'instructeur@exemple.gouv.fr' }
2018-07-16 14:39:04 +02:00
2019-07-22 15:49:11 +02:00
shared_examples 'a dossier notification' do
2019-09-10 13:29:06 +02:00
it 'is sent from a no-reply address' do
expect ( subject . from . first ) . to eq ( Mail :: Address . new ( NO_REPLY_EMAIL ) . address )
end
2019-07-22 15:49:11 +02:00
it 'includes the contact informations in the footer' do
expect ( subject . body ) . to include ( 'ne pas répondre' )
end
end
2018-11-20 11:50:25 +01:00
describe '.notify_new_draft' do
2021-11-19 13:48:52 +01:00
let ( :dossier ) { create ( :dossier , procedure : create ( :simple_procedure , :with_auto_archive ) ) }
2018-11-20 11:50:25 +01:00
2022-12-21 17:18:19 +01:00
subject { described_class . with ( dossier : ) . notify_new_draft }
2018-11-20 11:50:25 +01:00
it { expect ( subject . subject ) . to include ( " brouillon " ) }
2018-11-20 17:45:50 +01:00
it { expect ( subject . subject ) . to include ( dossier . procedure . libelle ) }
2018-11-20 11:50:25 +01:00
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . to include ( dossier_url ( dossier ) ) }
2021-05-26 15:16:30 +02:00
it { expect ( subject . body ) . to include ( " Vous pouvez déposer votre dossier jusqu’ au " ) }
2020-05-27 11:33:04 +02:00
it { expect ( subject . body ) . to include ( " heure de " ) }
2019-07-22 15:49:11 +02:00
it_behaves_like 'a dossier notification'
2018-11-20 11:50:25 +01:00
end
2021-07-22 14:33:39 +02:00
describe '.notify_new_answer with dossier brouillon' do
2022-02-16 18:26:45 +01:00
let ( :service ) { build ( :service ) }
let ( :procedure ) { create ( :simple_procedure , service : service ) }
let ( :dossier ) { create ( :dossier , procedure : procedure ) }
2021-11-16 15:12:05 +01:00
let ( :commentaire ) { create ( :commentaire , dossier : dossier ) }
subject { described_class . with ( commentaire : commentaire ) . notify_new_answer }
2018-11-20 11:50:25 +01:00
2021-07-22 14:33:39 +02:00
it { expect ( subject . subject ) . to include ( " Nouveau message " ) }
it { expect ( subject . subject ) . to include ( dossier . id . to_s ) }
2022-02-16 18:26:45 +01:00
it { expect ( subject . body ) . to include ( dossier . procedure . service . email ) }
2021-07-22 14:33:39 +02:00
it { expect ( subject . body ) . not_to include ( messagerie_dossier_url ( dossier ) ) }
it_behaves_like 'a dossier notification'
2022-02-16 18:26:45 +01:00
context 'when there is no associated service' do
let ( :service ) { nil }
it { expect { subject } . not_to raise_error }
end
2021-07-22 14:33:39 +02:00
end
describe '.notify_new_answer with dossier en construction' do
2021-11-19 13:48:52 +01:00
let ( :dossier ) { create ( :dossier , :en_construction , procedure : create ( :simple_procedure ) ) }
2021-11-16 15:12:05 +01:00
let ( :commentaire ) { create ( :commentaire , dossier : dossier ) }
2021-11-19 13:48:52 +01:00
2021-11-16 15:12:05 +01:00
subject { described_class . with ( commentaire : commentaire ) . notify_new_answer }
2021-07-22 14:33:39 +02:00
2018-11-20 11:50:25 +01:00
it { expect ( subject . subject ) . to include ( " Nouveau message " ) }
it { expect ( subject . subject ) . to include ( dossier . id . to_s ) }
it { expect ( subject . body ) . to include ( messagerie_dossier_url ( dossier ) ) }
2019-07-22 15:49:11 +02:00
it_behaves_like 'a dossier notification'
2018-11-20 11:50:25 +01:00
end
2021-11-16 15:12:05 +01:00
describe '.notify_new_answer with commentaire discarded' do
2021-11-19 13:48:52 +01:00
let ( :dossier ) { create ( :dossier , procedure : create ( :simple_procedure ) ) }
2021-11-16 15:12:05 +01:00
let ( :commentaire ) { create ( :commentaire , dossier : dossier , discarded_at : 2 . minutes . ago ) }
subject { described_class . with ( commentaire : commentaire ) . notify_new_answer }
it { expect ( subject . perform_deliveries ) . to be_falsy }
end
2022-01-19 14:43:30 +01:00
def notify_deletion_to_administration ( deleted_dossier , to_email )
@subject = default_i18n_subject ( dossier_id : deleted_dossier . dossier_id )
@deleted_dossier = deleted_dossier
2018-07-16 14:39:04 +02:00
2022-01-19 14:43:30 +01:00
mail ( to : to_email , subject : @subject )
2018-07-16 14:39:04 +02:00
end
describe '.notify_deletion_to_administration' do
let ( :deleted_dossier ) { build ( :deleted_dossier ) }
subject { described_class . notify_deletion_to_administration ( deleted_dossier , to_email ) }
2020-03-19 09:49:25 +01:00
it { expect ( subject . subject ) . to eq ( " Le dossier nº #{ deleted_dossier . dossier_id } a été supprimé à la demande de l’ usager " ) }
it { expect ( subject . body ) . to include ( " À la demande de l’ usager " ) }
2018-07-16 14:39:04 +02:00
it { expect ( subject . body ) . to include ( deleted_dossier . dossier_id ) }
2018-07-16 15:38:03 +02:00
it { expect ( subject . body ) . to include ( deleted_dossier . procedure . libelle ) }
2018-07-16 14:39:04 +02:00
end
2019-09-10 11:05:04 +02:00
describe '.notify_revert_to_instruction' do
2021-11-19 13:48:52 +01:00
let ( :dossier ) { create ( :dossier , procedure : create ( :simple_procedure ) ) }
2019-09-10 11:05:04 +02:00
subject { described_class . notify_revert_to_instruction ( dossier ) }
it { expect ( subject . subject ) . to include ( 'réexaminé' ) }
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . to include ( dossier_url ( dossier ) ) }
it_behaves_like 'a dossier notification'
end
2019-12-03 15:51:16 +01:00
describe '.notify_brouillon_near_deletion' do
let ( :dossier ) { create ( :dossier ) }
2020-03-19 09:49:25 +01:00
subject { described_class . notify_brouillon_near_deletion ( [ dossier ] , dossier . user . email ) }
2019-12-03 15:51:16 +01:00
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } " ) }
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
end
2019-11-28 18:03:23 +01:00
describe '.notify_brouillon_deletion' do
let ( :dossier ) { create ( :dossier ) }
2020-03-19 09:49:25 +01:00
subject { described_class . notify_brouillon_deletion ( [ dossier . hash_for_deletion_mail ] , dossier . user . email ) }
2019-11-28 18:03:23 +01:00
it { expect ( subject . subject ) . to eq ( " Un dossier en brouillon a été supprimé automatiquement " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } ( #{ dossier . procedure . libelle } ) " ) }
end
2020-02-18 17:15:32 +01:00
describe '.notify_automatic_deletion_to_user' do
2022-03-09 10:29:16 +01:00
let ( :deleted_dossier ) { create ( :deleted_dossier , dossier : dossier , reason : :expired ) }
2020-04-01 17:08:50 +02:00
describe 'en_construction' do
let ( :dossier ) { create ( :dossier , :en_construction ) }
2020-02-18 17:15:32 +01:00
2020-04-01 17:08:50 +02:00
subject { described_class . notify_automatic_deletion_to_user ( [ deleted_dossier ] , dossier . user . email ) }
2020-02-18 17:15:32 +01:00
2020-04-01 17:08:50 +02:00
it { expect ( subject . to ) . to eq ( [ dossier . user . email ] ) }
it { expect ( subject . subject ) . to eq ( " Un dossier a été supprimé automatiquement " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } " ) }
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . to include ( " nous nous excusons de la gène occasionnée " ) }
end
2020-04-02 15:05:16 +02:00
describe 'termine' do
let ( :dossier ) { create ( :dossier , :accepte ) }
subject { described_class . notify_automatic_deletion_to_user ( [ deleted_dossier ] , dossier . user . email ) }
it { expect ( subject . to ) . to eq ( [ dossier . user . email ] ) }
it { expect ( subject . subject ) . to eq ( " Un dossier a été supprimé automatiquement " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } " ) }
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . not_to include ( " nous nous excusons de la gène occasionnée " ) }
end
2020-02-18 17:15:32 +01:00
end
2020-02-18 17:18:06 +01:00
describe '.notify_automatic_deletion_to_administration' do
2022-03-09 10:29:16 +01:00
let ( :dossier ) { create ( :dossier , :en_construction ) }
let ( :deleted_dossier ) { create ( :deleted_dossier , dossier : dossier , reason : :expired ) }
2020-02-18 17:18:06 +01:00
2020-03-19 09:49:25 +01:00
subject { described_class . notify_automatic_deletion_to_administration ( [ deleted_dossier ] , dossier . user . email ) }
2020-02-18 17:18:06 +01:00
it { expect ( subject . subject ) . to eq ( " Un dossier a été supprimé automatiquement " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } ( #{ dossier . procedure . libelle } ) " ) }
end
2020-02-18 17:18:14 +01:00
2020-04-01 17:08:50 +02:00
describe '.notify_near_deletion_to_administration' do
describe 'en_construction' do
let ( :dossier ) { create ( :dossier , :en_construction ) }
2020-02-18 17:18:14 +01:00
2020-04-01 17:08:50 +02:00
subject { described_class . notify_near_deletion_to_administration ( [ dossier ] , dossier . user . email ) }
2020-02-18 17:18:14 +01:00
2020-04-01 17:08:50 +02:00
it { expect ( subject . subject ) . to eq ( " Un dossier en construction va bientôt être supprimé " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } " ) }
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . to include ( " PDF " ) }
2021-08-26 10:14:23 +02:00
it { expect ( subject . body ) . to include ( " Vous avez <b>deux semaines</b> pour commencer l’ instruction du dossier. " ) }
2020-04-01 17:08:50 +02:00
end
2020-04-02 15:05:16 +02:00
describe 'termine' do
let ( :dossier ) { create ( :dossier , :accepte ) }
subject { described_class . notify_near_deletion_to_administration ( [ dossier ] , dossier . user . email ) }
it { expect ( subject . subject ) . to eq ( " Un dossier dont le traitement est terminé va bientôt être supprimé " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } " ) }
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . to include ( " PDF " ) }
2021-08-26 10:14:23 +02:00
it { expect ( subject . body ) . to include ( " Vous avez <b>deux semaines</b> pour archiver le dossier. " ) }
2020-04-02 15:05:16 +02:00
end
2020-02-18 17:18:14 +01:00
end
2020-04-01 17:08:50 +02:00
describe '.notify_near_deletion_to_user' do
describe 'en_construction' do
let ( :dossier ) { create ( :dossier , :en_construction ) }
2020-02-18 17:18:14 +01:00
2020-04-01 17:08:50 +02:00
subject { described_class . notify_near_deletion_to_user ( [ dossier ] , dossier . user . email ) }
2020-02-18 17:18:14 +01:00
2020-04-01 17:08:50 +02:00
it { expect ( subject . to ) . to eq ( [ dossier . user . email ] ) }
it { expect ( subject . subject ) . to eq ( " Un dossier en construction va bientôt être supprimé " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } " ) }
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . to include ( " PDF " ) }
2021-08-26 10:14:23 +02:00
it { expect ( subject . body ) . to include ( " Vous pouvez retrouver votre dossier pendant encore <b>deux semaines</b>. Vous n’ avez rien à faire. " ) }
2021-05-26 15:16:30 +02:00
it { expect ( subject . body ) . to include ( " Si vous souhaitez conserver votre dossier plus longtemps, vous pouvez <b>prolonger sa durée de conservation</b> dans l’ interface. " ) }
2020-04-01 17:08:50 +02:00
end
2020-04-02 15:05:16 +02:00
describe 'termine' do
let ( :dossier ) { create ( :dossier , :accepte ) }
subject { described_class . notify_near_deletion_to_user ( [ dossier ] , dossier . user . email ) }
it { expect ( subject . to ) . to eq ( [ dossier . user . email ] ) }
it { expect ( subject . subject ) . to eq ( " Un dossier dont le traitement est terminé va bientôt être supprimé " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } " ) }
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . to include ( " PDF " ) }
2021-08-26 10:14:23 +02:00
it { expect ( subject . body ) . to include ( " Vous pouvez retrouver votre dossier pendant encore <b>deux semaines</b>. Vous n’ avez rien à faire. " ) }
2020-04-02 15:05:16 +02:00
end
2020-02-18 17:18:14 +01:00
end
2020-02-25 18:16:21 +01:00
describe '.notify_groupe_instructeur_changed_to_instructeur' do
let ( :dossier ) { create ( :dossier ) }
let ( :instructeur ) { create ( :instructeur ) }
subject { described_class . notify_groupe_instructeur_changed ( instructeur , dossier ) }
2021-09-01 18:52:01 +02:00
it { expect ( subject . subject ) . to eq ( " Le dossier nº #{ dossier . id } a changé de groupe instructeur " ) }
it { expect ( subject . body ) . to include ( " n° #{ dossier . id } " ) }
2020-02-25 18:16:21 +01:00
it { expect ( subject . body ) . to include ( dossier . procedure . libelle ) }
it { expect ( subject . body ) . to include ( " Suite à cette modification, vous ne suivez plus ce dossier. " ) }
end
2018-07-16 14:39:04 +02:00
end