diff --git a/app/jobs/cron/expired_dossiers_brouillon_deletion_job.rb b/app/jobs/cron/expired_dossiers_brouillon_deletion_job.rb index 5243db046..7c13ae623 100644 --- a/app/jobs/cron/expired_dossiers_brouillon_deletion_job.rb +++ b/app/jobs/cron/expired_dossiers_brouillon_deletion_job.rb @@ -2,6 +2,6 @@ class Cron::ExpiredDossiersBrouillonDeletionJob < Cron::CronJob self.schedule_expression = "every day at 10 pm" def perform(*args) - ExpiredDossiersDeletionService.new.process_expired_dossiers_brouillon + Expired::DossiersDeletionService.new.process_expired_dossiers_brouillon end end diff --git a/app/jobs/cron/expired_dossiers_en_construction_deletion_job.rb b/app/jobs/cron/expired_dossiers_en_construction_deletion_job.rb index 84f5b3406..4de43fe6d 100644 --- a/app/jobs/cron/expired_dossiers_en_construction_deletion_job.rb +++ b/app/jobs/cron/expired_dossiers_en_construction_deletion_job.rb @@ -2,6 +2,6 @@ class Cron::ExpiredDossiersEnConstructionDeletionJob < Cron::CronJob self.schedule_expression = "every day at 3 pm" def perform(*args) - ExpiredDossiersDeletionService.new.process_expired_dossiers_en_construction + Expired::DossiersDeletionService.new.process_expired_dossiers_en_construction end end diff --git a/app/jobs/cron/expired_dossiers_termine_deletion_job.rb b/app/jobs/cron/expired_dossiers_termine_deletion_job.rb index ce47f3f5a..b97ce35e2 100644 --- a/app/jobs/cron/expired_dossiers_termine_deletion_job.rb +++ b/app/jobs/cron/expired_dossiers_termine_deletion_job.rb @@ -2,6 +2,6 @@ class Cron::ExpiredDossiersTermineDeletionJob < Cron::CronJob self.schedule_expression = "every day at 7 am" def perform(*args) - ExpiredDossiersDeletionService.new.process_expired_dossiers_termine + Expired::DossiersDeletionService.new.process_expired_dossiers_termine end end diff --git a/app/jobs/cron/expired_users_deletion_job.rb b/app/jobs/cron/expired_users_deletion_job.rb index 8057a06a5..395f8ccdb 100644 --- a/app/jobs/cron/expired_users_deletion_job.rb +++ b/app/jobs/cron/expired_users_deletion_job.rb @@ -3,6 +3,6 @@ class Cron::ExpiredUsersDeletionJob < Cron::CronJob def perform(*args) return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank? - ExpiredUsersDeletionService.process_expired + Expired::UsersDeletionService.process_expired end end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index a5a2f98b6..e5434de97 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -69,7 +69,7 @@ class UserMailer < ApplicationMailer def notify_inactive_close_to_deletion(user) @user = user - @subject = "Votre compte sera supprimé dans #{ExpiredUsersDeletionService::RETENTION_AFTER_NOTICE_IN_WEEK} semaines" + @subject = "Votre compte sera supprimé dans #{Expired::UsersDeletionService::RETENTION_AFTER_NOTICE_IN_WEEK} semaines" mail(to: user.email, subject: @subject) end diff --git a/app/services/expired_dossiers_deletion_service.rb b/app/services/expired/dossiers_deletion_service.rb similarity index 99% rename from app/services/expired_dossiers_deletion_service.rb rename to app/services/expired/dossiers_deletion_service.rb index 13ed8eb0e..added6eaf 100644 --- a/app/services/expired_dossiers_deletion_service.rb +++ b/app/services/expired/dossiers_deletion_service.rb @@ -1,4 +1,4 @@ -class ExpiredDossiersDeletionService +class Expired::DossiersDeletionService include MailRateLimitable def process_expired_dossiers_brouillon diff --git a/app/services/expired_users_deletion_service.rb b/app/services/expired/users_deletion_service.rb similarity index 98% rename from app/services/expired_users_deletion_service.rb rename to app/services/expired/users_deletion_service.rb index 8a8f8e0fb..36226021f 100644 --- a/app/services/expired_users_deletion_service.rb +++ b/app/services/expired/users_deletion_service.rb @@ -1,4 +1,4 @@ -class ExpiredUsersDeletionService +class Expired::UsersDeletionService include MailRateLimitable RETENTION_AFTER_NOTICE_IN_WEEK = 2 diff --git a/lib/tasks/deployment/20200401123317_process_expired_dossiers_en_construction.rake b/lib/tasks/deployment/20200401123317_process_expired_dossiers_en_construction.rake index 23c0692b9..b371b1a62 100644 --- a/lib/tasks/deployment/20200401123317_process_expired_dossiers_en_construction.rake +++ b/lib/tasks/deployment/20200401123317_process_expired_dossiers_en_construction.rake @@ -7,7 +7,7 @@ namespace :after_party do .en_construction_close_to_expiration .without_en_construction_expiration_notice_sent - ExpiredDossiersDeletionService.send_expiration_notices(dossiers_close_to_expiration, :en_construction_close_to_expiration_notice_sent_at) + Expired::DossiersDeletionService.send_expiration_notices(dossiers_close_to_expiration, :en_construction_close_to_expiration_notice_sent_at) BATCH_SIZE = 1000 diff --git a/spec/jobs/cron/expired_users_deletion_job_spec.rb b/spec/jobs/cron/expired_users_deletion_job_spec.rb index 647f86335..6434a73a3 100644 --- a/spec/jobs/cron/expired_users_deletion_job_spec.rb +++ b/spec/jobs/cron/expired_users_deletion_job_spec.rb @@ -4,15 +4,15 @@ describe Cron::ExpiredUsersDeletionJob do context 'when env[EXPIRE_USER_DELETION_JOB_LIMIT] is present' do before { expect(ENV).to receive(:[]).with('EXPIRE_USER_DELETION_JOB_LIMIT').and_return('anything') } - it 'calls ExpiredUsersDeletionService.process_expired' do - expect(ExpiredUsersDeletionService).to receive(:process_expired) + it 'calls Expired::UsersDeletionService.process_expired' do + expect(Expired::UsersDeletionService).to receive(:process_expired) subject end end context 'when env[EXPIRE_USER_DELETION_JOB_LIMIT] is absent' do - it 'does not call ExpiredUsersDeletionService.process_expired' do - expect(ExpiredUsersDeletionService).not_to receive(:process_expired) + it 'does not call Expired::UsersDeletionService.process_expired' do + expect(Expired::UsersDeletionService).not_to receive(:process_expired) subject end end diff --git a/spec/services/expired_dossiers_deletion_service_spec.rb b/spec/services/expired/expired_dossiers_deletion_service_spec.rb similarity index 99% rename from spec/services/expired_dossiers_deletion_service_spec.rb rename to spec/services/expired/expired_dossiers_deletion_service_spec.rb index 767390bc5..b21cd1cc8 100644 --- a/spec/services/expired_dossiers_deletion_service_spec.rb +++ b/spec/services/expired/expired_dossiers_deletion_service_spec.rb @@ -1,4 +1,4 @@ -describe ExpiredDossiersDeletionService do +describe Expired::DossiersDeletionService do let(:warning_period) { 1.month + 5.days } let(:conservation_par_defaut) { 3.months } let(:user) { create(:user) } @@ -6,7 +6,7 @@ describe ExpiredDossiersDeletionService do let(:procedure) { create(:procedure, :published, procedure_opts) } let(:procedure_2) { create(:procedure, :published, procedure_opts) } let(:reference_date) { Date.parse("March 8") } - let(:service) { ExpiredDossiersDeletionService.new } + let(:service) { Expired::DossiersDeletionService.new } describe '#process_expired_dossiers_brouillon' do before { Timecop.freeze(reference_date) } after { Timecop.return } diff --git a/spec/services/expired_users_deletion_service_spec.rb b/spec/services/expired/expired_users_deletion_service_spec.rb similarity index 91% rename from spec/services/expired_users_deletion_service_spec.rb rename to spec/services/expired/expired_users_deletion_service_spec.rb index 0767394ab..8871e2280 100644 --- a/spec/services/expired_users_deletion_service_spec.rb +++ b/spec/services/expired/expired_users_deletion_service_spec.rb @@ -1,9 +1,9 @@ -describe ExpiredUsersDeletionService do - let(:last_signed_in_not_expired) { (ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR - 1).years.ago } - let(:last_signed_in_expired) { (ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR + 1).years.ago } +describe Expired::UsersDeletionService do + let(:last_signed_in_not_expired) { (Expired::UsersDeletionService::EXPIRABLE_AFTER_IN_YEAR - 1).years.ago } + let(:last_signed_in_expired) { (Expired::UsersDeletionService::EXPIRABLE_AFTER_IN_YEAR + 1).years.ago } let(:before_close_to_expiration) { nil } - let(:notified_close_to_expiration) { (ExpiredUsersDeletionService::RETENTION_AFTER_NOTICE_IN_WEEK - 1).weeks.ago } - let(:due_close_to_expiration) { (ExpiredUsersDeletionService::RETENTION_AFTER_NOTICE_IN_WEEK + 1).weeks.ago } + let(:notified_close_to_expiration) { (Expired::UsersDeletionService::RETENTION_AFTER_NOTICE_IN_WEEK - 1).weeks.ago } + let(:due_close_to_expiration) { (Expired::UsersDeletionService::RETENTION_AFTER_NOTICE_IN_WEEK + 1).weeks.ago } let(:mail_double) do dbl = double() expect(dbl).to receive(:deliver_later).with(wait: 0) @@ -13,7 +13,7 @@ describe ExpiredUsersDeletionService do before { user && dossier } describe '#process_expired' do - subject { ExpiredUsersDeletionService.new.process_expired } + subject { Expired::UsersDeletionService.new.process_expired } context 'when user has an expirable dossier' do let(:dossier) { create(:dossier, user:, created_at: last_signed_in_expired) } @@ -116,7 +116,7 @@ describe ExpiredUsersDeletionService do describe '#expiring_users_without_dossiers' do let(:dossier) { nil } - subject { ExpiredUsersDeletionService.new.send(:expiring_users_without_dossiers) } + subject { Expired::UsersDeletionService.new.send(:expiring_users_without_dossiers) } context 'when user last_sign_in_at is 1 year ago and has no dossier' do let(:user) { create(:user, last_sign_in_at: last_signed_in_not_expired) } @@ -146,7 +146,7 @@ describe ExpiredUsersDeletionService do describe '#expiring_users_with_dossiers' do let(:user) { create(:user) } - subject { ExpiredUsersDeletionService.new.send(:expiring_users_with_dossiers) } + subject { Expired::UsersDeletionService.new.send(:expiring_users_with_dossiers) } context 'when user has a dossier created 1 year ago' do let(:dossier) { create(:dossier, user:, created_at: last_signed_in_not_expired) }