tech(refactor): deplace les service d'expiration usager/dossier dans un namespace dedié
This commit is contained in:
parent
fb51710309
commit
99529c611d
11 changed files with 22 additions and 22 deletions
|
@ -2,6 +2,6 @@ class Cron::ExpiredDossiersBrouillonDeletionJob < Cron::CronJob
|
||||||
self.schedule_expression = "every day at 10 pm"
|
self.schedule_expression = "every day at 10 pm"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
ExpiredDossiersDeletionService.new.process_expired_dossiers_brouillon
|
Expired::DossiersDeletionService.new.process_expired_dossiers_brouillon
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,6 @@ class Cron::ExpiredDossiersEnConstructionDeletionJob < Cron::CronJob
|
||||||
self.schedule_expression = "every day at 3 pm"
|
self.schedule_expression = "every day at 3 pm"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
ExpiredDossiersDeletionService.new.process_expired_dossiers_en_construction
|
Expired::DossiersDeletionService.new.process_expired_dossiers_en_construction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,6 @@ class Cron::ExpiredDossiersTermineDeletionJob < Cron::CronJob
|
||||||
self.schedule_expression = "every day at 7 am"
|
self.schedule_expression = "every day at 7 am"
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
ExpiredDossiersDeletionService.new.process_expired_dossiers_termine
|
Expired::DossiersDeletionService.new.process_expired_dossiers_termine
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,6 @@ class Cron::ExpiredUsersDeletionJob < Cron::CronJob
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank?
|
return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank?
|
||||||
ExpiredUsersDeletionService.process_expired
|
Expired::UsersDeletionService.process_expired
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,7 +69,7 @@ class UserMailer < ApplicationMailer
|
||||||
|
|
||||||
def notify_inactive_close_to_deletion(user)
|
def notify_inactive_close_to_deletion(user)
|
||||||
@user = 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)
|
mail(to: user.email, subject: @subject)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class ExpiredDossiersDeletionService
|
class Expired::DossiersDeletionService
|
||||||
include MailRateLimitable
|
include MailRateLimitable
|
||||||
|
|
||||||
def process_expired_dossiers_brouillon
|
def process_expired_dossiers_brouillon
|
|
@ -1,4 +1,4 @@
|
||||||
class ExpiredUsersDeletionService
|
class Expired::UsersDeletionService
|
||||||
include MailRateLimitable
|
include MailRateLimitable
|
||||||
|
|
||||||
RETENTION_AFTER_NOTICE_IN_WEEK = 2
|
RETENTION_AFTER_NOTICE_IN_WEEK = 2
|
|
@ -7,7 +7,7 @@ namespace :after_party do
|
||||||
.en_construction_close_to_expiration
|
.en_construction_close_to_expiration
|
||||||
.without_en_construction_expiration_notice_sent
|
.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
|
BATCH_SIZE = 1000
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,15 @@ describe Cron::ExpiredUsersDeletionJob do
|
||||||
context 'when env[EXPIRE_USER_DELETION_JOB_LIMIT] is present' 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') }
|
before { expect(ENV).to receive(:[]).with('EXPIRE_USER_DELETION_JOB_LIMIT').and_return('anything') }
|
||||||
|
|
||||||
it 'calls ExpiredUsersDeletionService.process_expired' do
|
it 'calls Expired::UsersDeletionService.process_expired' do
|
||||||
expect(ExpiredUsersDeletionService).to receive(:process_expired)
|
expect(Expired::UsersDeletionService).to receive(:process_expired)
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when env[EXPIRE_USER_DELETION_JOB_LIMIT] is absent' do
|
context 'when env[EXPIRE_USER_DELETION_JOB_LIMIT] is absent' do
|
||||||
it 'does not call ExpiredUsersDeletionService.process_expired' do
|
it 'does not call Expired::UsersDeletionService.process_expired' do
|
||||||
expect(ExpiredUsersDeletionService).not_to receive(:process_expired)
|
expect(Expired::UsersDeletionService).not_to receive(:process_expired)
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
describe ExpiredDossiersDeletionService do
|
describe Expired::DossiersDeletionService do
|
||||||
let(:warning_period) { 1.month + 5.days }
|
let(:warning_period) { 1.month + 5.days }
|
||||||
let(:conservation_par_defaut) { 3.months }
|
let(:conservation_par_defaut) { 3.months }
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
@ -6,7 +6,7 @@ describe ExpiredDossiersDeletionService do
|
||||||
let(:procedure) { create(:procedure, :published, procedure_opts) }
|
let(:procedure) { create(:procedure, :published, procedure_opts) }
|
||||||
let(:procedure_2) { create(:procedure, :published, procedure_opts) }
|
let(:procedure_2) { create(:procedure, :published, procedure_opts) }
|
||||||
let(:reference_date) { Date.parse("March 8") }
|
let(:reference_date) { Date.parse("March 8") }
|
||||||
let(:service) { ExpiredDossiersDeletionService.new }
|
let(:service) { Expired::DossiersDeletionService.new }
|
||||||
describe '#process_expired_dossiers_brouillon' do
|
describe '#process_expired_dossiers_brouillon' do
|
||||||
before { Timecop.freeze(reference_date) }
|
before { Timecop.freeze(reference_date) }
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
|
@ -1,9 +1,9 @@
|
||||||
describe ExpiredUsersDeletionService do
|
describe Expired::UsersDeletionService do
|
||||||
let(:last_signed_in_not_expired) { (ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR - 1).years.ago }
|
let(:last_signed_in_not_expired) { (Expired::UsersDeletionService::EXPIRABLE_AFTER_IN_YEAR - 1).years.ago }
|
||||||
let(:last_signed_in_expired) { (ExpiredUsersDeletionService::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(:before_close_to_expiration) { nil }
|
||||||
let(:notified_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) { (ExpiredUsersDeletionService::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
|
let(:mail_double) do
|
||||||
dbl = double()
|
dbl = double()
|
||||||
expect(dbl).to receive(:deliver_later).with(wait: 0)
|
expect(dbl).to receive(:deliver_later).with(wait: 0)
|
||||||
|
@ -13,7 +13,7 @@ describe ExpiredUsersDeletionService do
|
||||||
before { user && dossier }
|
before { user && dossier }
|
||||||
|
|
||||||
describe '#process_expired' do
|
describe '#process_expired' do
|
||||||
subject { ExpiredUsersDeletionService.new.process_expired }
|
subject { Expired::UsersDeletionService.new.process_expired }
|
||||||
|
|
||||||
context 'when user has an expirable dossier' do
|
context 'when user has an expirable dossier' do
|
||||||
let(:dossier) { create(:dossier, user:, created_at: last_signed_in_expired) }
|
let(:dossier) { create(:dossier, user:, created_at: last_signed_in_expired) }
|
||||||
|
@ -116,7 +116,7 @@ describe ExpiredUsersDeletionService do
|
||||||
|
|
||||||
describe '#expiring_users_without_dossiers' do
|
describe '#expiring_users_without_dossiers' do
|
||||||
let(:dossier) { nil }
|
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
|
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) }
|
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
|
describe '#expiring_users_with_dossiers' do
|
||||||
let(:user) { create(:user) }
|
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
|
context 'when user has a dossier created 1 year ago' do
|
||||||
let(:dossier) { create(:dossier, user:, created_at: last_signed_in_not_expired) }
|
let(:dossier) { create(:dossier, user:, created_at: last_signed_in_not_expired) }
|
Loading…
Reference in a new issue