tech(refactor): deplace les service d'expiration usager/dossier dans un namespace dedié

This commit is contained in:
Martin 2023-11-07 07:24:57 +01:00 committed by mfo
parent fb51710309
commit 99529c611d
11 changed files with 22 additions and 22 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,4 +1,4 @@
class ExpiredDossiersDeletionService
class Expired::DossiersDeletionService
include MailRateLimitable
def process_expired_dossiers_brouillon

View file

@ -1,4 +1,4 @@
class ExpiredUsersDeletionService
class Expired::UsersDeletionService
include MailRateLimitable
RETENTION_AFTER_NOTICE_IN_WEEK = 2

View file

@ -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

View file

@ -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

View file

@ -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 }

View file

@ -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) }