4cb747fdb6
Test helpers are separated between two files: spec_helper and rails_helper. This separation is meant to allow tests that do not require Rails (like testing standalone libs) to boot faster. The spec_helper file is always loaded, through `--require spec_helper` in the `.rspec` config file. When needed, the rails_helper file is expected to be required manually. This is fine, but: - Many test files have a redundant `require 'spec_helper'` line; - Many test files should require `rails_helper`, but don't. Not requiring `rails_helper` will cause the Rails-concerned section of the test environment not to be configured–which may cause subtle bugs (like the test database not being properly initialized). Moreover, Spring loads all the Rails files on preloading anyway. So the gains from using only `spec_helper` are thin. To streamline this process, this commit: - Configures `.rspec` to require `rails_helper` by default; - Remove all manual requires to spec_helper or rails_helper. Reference: https://stackoverflow.com/questions/24145329/how-is-spec-rails-helper-rb-different-from-spec-spec-helper-rb-do-i-need-it
171 lines
7.2 KiB
Ruby
171 lines
7.2 KiB
Ruby
RSpec.describe DossierMailer, type: :mailer do
|
||
let(:to_email) { 'instructeur@exemple.gouv.fr' }
|
||
|
||
shared_examples 'a dossier notification' do
|
||
it 'is sent from a no-reply address' do
|
||
expect(subject.from.first).to eq(Mail::Address.new(NO_REPLY_EMAIL).address)
|
||
end
|
||
|
||
it 'includes the contact informations in the footer' do
|
||
expect(subject.body).to include('ne pas répondre')
|
||
end
|
||
end
|
||
|
||
describe '.notify_new_draft' do
|
||
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
|
||
|
||
subject { described_class.notify_new_draft(dossier) }
|
||
|
||
it { expect(subject.subject).to include("brouillon") }
|
||
it { expect(subject.subject).to include(dossier.procedure.libelle) }
|
||
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
|
||
|
||
describe '.notify_new_answer' do
|
||
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
|
||
|
||
subject { described_class.notify_new_answer(dossier) }
|
||
|
||
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)) }
|
||
|
||
it_behaves_like 'a dossier notification'
|
||
end
|
||
|
||
describe '.notify_deletion_to_user' do
|
||
let(:deleted_dossier) { build(:deleted_dossier) }
|
||
|
||
subject { described_class.notify_deletion_to_user(deleted_dossier, to_email) }
|
||
|
||
it { expect(subject.subject).to eq("Votre dossier nº #{deleted_dossier.dossier_id} a bien été supprimé") }
|
||
it { expect(subject.body).to include("Votre dossier") }
|
||
it { expect(subject.body).to include(deleted_dossier.dossier_id) }
|
||
it { expect(subject.body).to include("a bien été supprimé") }
|
||
it { expect(subject.body).to include(deleted_dossier.procedure.libelle) }
|
||
end
|
||
|
||
describe '.notify_deletion_to_administration' do
|
||
let(:deleted_dossier) { build(:deleted_dossier) }
|
||
|
||
subject { described_class.notify_deletion_to_administration(deleted_dossier, to_email) }
|
||
|
||
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") }
|
||
it { expect(subject.body).to include(deleted_dossier.dossier_id) }
|
||
it { expect(subject.body).to include(deleted_dossier.procedure.libelle) }
|
||
end
|
||
|
||
describe '.notify_revert_to_instruction' do
|
||
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
|
||
|
||
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
|
||
|
||
describe '.notify_brouillon_near_deletion' do
|
||
let(:dossier) { create(:dossier) }
|
||
|
||
before do
|
||
duree = dossier.procedure.duree_conservation_dossiers_dans_ds
|
||
@date_suppression = dossier.created_at + duree.months
|
||
end
|
||
|
||
subject { described_class.notify_brouillon_near_deletion([dossier], dossier.user.email) }
|
||
|
||
it { expect(subject.body).to include("n° #{dossier.id} ") }
|
||
it { expect(subject.body).to include(dossier.procedure.libelle) }
|
||
end
|
||
|
||
describe '.notify_brouillon_deletion' do
|
||
let(:dossier) { create(:dossier) }
|
||
|
||
subject { described_class.notify_brouillon_deletion([dossier.hash_for_deletion_mail], dossier.user.email) }
|
||
|
||
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
|
||
|
||
describe '.notify_automatic_deletion_to_user' do
|
||
let(:dossier) { create(:dossier) }
|
||
let(:deleted_dossier) { DeletedDossier.create_from_dossier(dossier, :expired) }
|
||
|
||
before do
|
||
duree = dossier.procedure.duree_conservation_dossiers_dans_ds
|
||
@date_suppression = dossier.created_at + duree.months
|
||
end
|
||
|
||
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).to include("nous nous excusons de la gène occasionnée") }
|
||
end
|
||
|
||
describe '.notify_automatic_deletion_to_administration' do
|
||
let(:dossier) { create(:dossier) }
|
||
let(:deleted_dossier) { DeletedDossier.create_from_dossier(dossier, :expired) }
|
||
|
||
subject { described_class.notify_automatic_deletion_to_administration([deleted_dossier], dossier.user.email) }
|
||
|
||
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
|
||
|
||
describe '.notify_en_construction_near_deletion_to_administration' do
|
||
let(:dossier) { create(:dossier) }
|
||
|
||
before do
|
||
duree = dossier.procedure.duree_conservation_dossiers_dans_ds
|
||
@date_suppression = dossier.created_at + duree.months
|
||
end
|
||
|
||
subject { described_class.notify_en_construction_near_deletion_to_administration([dossier], 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") }
|
||
it { expect(subject.body).to include("Vous avez <b>un mois</b> pour commencer l’instruction du dossier.") }
|
||
end
|
||
|
||
describe '.notify_en_construction_near_deletion_to_user' do
|
||
let(:dossier) { create(:dossier) }
|
||
|
||
before do
|
||
duree = dossier.procedure.duree_conservation_dossiers_dans_ds
|
||
@date_suppression = dossier.created_at + duree.months
|
||
end
|
||
|
||
subject { described_class.notify_en_construction_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 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") }
|
||
it { expect(subject.body).to include("Vous pouvez retrouver votre dossier pendant encore <b>un mois</b>. Vous n’avez rien à faire.") }
|
||
end
|
||
|
||
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) }
|
||
|
||
it { expect(subject.subject).to eq("Un dossier a changé de groupe instructeur") }
|
||
it { expect(subject.body).to include("n°#{dossier.id}") }
|
||
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
|
||
end
|