amelioration(ExpiredUsersDeletionService): ajoute le rate limit a l'envoie des mails
This commit is contained in:
parent
5229160408
commit
8790ac4978
4 changed files with 41 additions and 31 deletions
|
@ -1,15 +1,23 @@
|
|||
describe ExpiredUsersDeletionService do
|
||||
let(:mail_double) do
|
||||
dbl = double()
|
||||
expect(dbl).to receive(:deliver_later).with(wait: 0)
|
||||
dbl
|
||||
end
|
||||
|
||||
before { user && dossier }
|
||||
|
||||
describe '#process_expired' do
|
||||
subject { ExpiredUsersDeletionService.new.process_expired }
|
||||
|
||||
context 'when user has an expirable dossier' do
|
||||
let(:dossier) { create(:dossier, user:, created_at: 3.years.ago) }
|
||||
|
||||
context 'when user was not notified' do
|
||||
let(:user) { create(:user, inactive_close_to_expiration_notice_sent_at: nil) }
|
||||
subject { ExpiredUsersDeletionService.process_expired }
|
||||
|
||||
it 'update user.inactive_close_to_expiration_notice_sent_at ' do
|
||||
expect(UserMailer).to receive(:notify_inactive_close_to_deletion).with(user).and_return(double(perform_later: true))
|
||||
expect(UserMailer).to receive(:notify_inactive_close_to_deletion).with(user).and_return(mail_double)
|
||||
expect { subject }
|
||||
.to change { user.reload.inactive_close_to_expiration_notice_sent_at }
|
||||
.from(nil).to(anything)
|
||||
|
@ -18,7 +26,6 @@ describe ExpiredUsersDeletionService do
|
|||
|
||||
context 'user has been notified 1 week ago' do
|
||||
let(:user) { create(:user, inactive_close_to_expiration_notice_sent_at: 1.week.ago) }
|
||||
subject { ExpiredUsersDeletionService.process_expired }
|
||||
|
||||
it 'do nothing' do
|
||||
expect { subject }.not_to change { Dossier.count }
|
||||
|
@ -28,7 +35,6 @@ describe ExpiredUsersDeletionService do
|
|||
|
||||
context 'user has been notified 3 weeks ago' do
|
||||
let(:user) { create(:user, inactive_close_to_expiration_notice_sent_at: 3.weeks.ago) }
|
||||
subject { ExpiredUsersDeletionService.process_expired }
|
||||
|
||||
it 'destroys user and dossier' do
|
||||
expect { subject }.to change { Dossier.count }.by(-1)
|
||||
|
@ -42,10 +48,9 @@ describe ExpiredUsersDeletionService do
|
|||
|
||||
context 'when user was not notified' do
|
||||
let(:user) { create(:user, last_sign_in_at: 3.years.ago, inactive_close_to_expiration_notice_sent_at: nil) }
|
||||
subject { ExpiredUsersDeletionService.process_expired }
|
||||
|
||||
it 'update user.inactive_close_to_expiration_notice_sent_at ' do
|
||||
expect(UserMailer).to receive(:notify_inactive_close_to_deletion).with(user).and_return(double(perform_later: true))
|
||||
expect(UserMailer).to receive(:notify_inactive_close_to_deletion).with(user).and_return(mail_double)
|
||||
expect { subject }
|
||||
.to change { user.reload.inactive_close_to_expiration_notice_sent_at }
|
||||
.from(nil).to(anything)
|
||||
|
@ -54,7 +59,6 @@ describe ExpiredUsersDeletionService do
|
|||
|
||||
context 'when user has been notified 1 week ago' do
|
||||
let(:user) { create(:user, last_sign_in_at: 3.years.ago, inactive_close_to_expiration_notice_sent_at: 1.week.ago) }
|
||||
subject { ExpiredUsersDeletionService.process_expired }
|
||||
|
||||
it 'do nothing' do
|
||||
expect { subject }.not_to change { Dossier.count }
|
||||
|
@ -64,7 +68,6 @@ describe ExpiredUsersDeletionService do
|
|||
|
||||
context 'when user has been notified 3 weeks ago' do
|
||||
let(:user) { create(:user, last_sign_in_at: 3.years.ago, inactive_close_to_expiration_notice_sent_at: 3.weeks.ago) }
|
||||
subject { ExpiredUsersDeletionService.process_expired }
|
||||
|
||||
it 'destroys user and dossier' do
|
||||
subject
|
||||
|
@ -76,7 +79,7 @@ describe ExpiredUsersDeletionService do
|
|||
|
||||
describe '#expiring_users_without_dossiers' do
|
||||
let(:dossier) { nil }
|
||||
subject { ExpiredUsersDeletionService.expiring_users_without_dossiers }
|
||||
subject { ExpiredUsersDeletionService.new.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: 1.year.ago) }
|
||||
|
@ -91,7 +94,7 @@ describe ExpiredUsersDeletionService do
|
|||
|
||||
describe '#expiring_users_with_dossiers' do
|
||||
let(:user) { create(:user) }
|
||||
subject { ExpiredUsersDeletionService.expiring_users_with_dossiers }
|
||||
subject { ExpiredUsersDeletionService.new.expiring_users_with_dossiers }
|
||||
|
||||
context 'when user has a dossier created 1 year ago' do
|
||||
let(:dossier) { create(:dossier, user:, created_at: 1.year.ago) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue