Expand coverage for Scheduler::IpCleanupScheduler
worker (#32499)
This commit is contained in:
parent
2d008108a4
commit
c292ed07fe
2 changed files with 50 additions and 3 deletions
6
spec/fabricators/ip_block_fabricator.rb
Normal file
6
spec/fabricators/ip_block_fabricator.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:ip_block) do
|
||||
severity { :sign_up_requires_approval }
|
||||
ip { sequence(:ip) { |n| "10.0.0.#{n}" } }
|
||||
end
|
|
@ -5,9 +5,50 @@ require 'rails_helper'
|
|||
RSpec.describe Scheduler::IpCleanupScheduler do
|
||||
let(:worker) { described_class.new }
|
||||
|
||||
describe 'perform' do
|
||||
it 'runs without error' do
|
||||
expect { worker.perform }.to_not raise_error
|
||||
describe '#perform' do
|
||||
context 'with IP-related data past retention times' do
|
||||
let!(:future_ip_block) { Fabricate :ip_block, expires_at: 1.week.from_now }
|
||||
let!(:old_ip_block) { Fabricate :ip_block, expires_at: 1.week.ago }
|
||||
let!(:session_past_retention) { Fabricate :session_activation, ip: '10.0.0.0', updated_at: 18.months.ago }
|
||||
let!(:inactive_user) { Fabricate :user, current_sign_in_at: 18.months.ago, sign_up_ip: '10.0.0.0' }
|
||||
let!(:old_login_activity) { Fabricate :login_activity, created_at: 18.months.ago }
|
||||
let!(:old_token) { Fabricate :access_token, last_used_at: 18.months.ago, last_used_ip: '10.0.0.0' }
|
||||
|
||||
before { stub_const 'Scheduler::IpCleanupScheduler::SESSION_RETENTION_PERIOD', 10.years.to_i.seconds }
|
||||
|
||||
it 'deletes the expired block' do
|
||||
expect { worker.perform }
|
||||
.to_not raise_error
|
||||
expect { old_ip_block.reload }
|
||||
.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect { old_login_activity.reload }
|
||||
.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect(session_past_retention.reload.ip)
|
||||
.to be_nil
|
||||
expect(inactive_user.reload.sign_up_ip)
|
||||
.to be_nil
|
||||
expect(old_token.reload.last_used_ip)
|
||||
.to be_nil
|
||||
expect(future_ip_block.reload)
|
||||
.to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'with old session data' do
|
||||
let!(:new_activation) { Fabricate :session_activation, updated_at: 1.week.ago }
|
||||
let!(:old_activation) { Fabricate :session_activation, updated_at: 1.month.ago }
|
||||
|
||||
before { stub_const 'Scheduler::IpCleanupScheduler::SESSION_RETENTION_PERIOD', 10.days.to_i.seconds }
|
||||
|
||||
it 'clears old sessions' do
|
||||
expect { worker.perform }
|
||||
.to_not raise_error
|
||||
|
||||
expect { old_activation.reload }
|
||||
.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect(new_activation.reload)
|
||||
.to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue