self_destruct_scheduler_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Scheduler::SelfDestructScheduler do
  4. let(:worker) { described_class.new }
  5. describe '#perform' do
  6. let!(:account) { Fabricate(:account, domain: nil, suspended_at: nil) }
  7. context 'when not in self destruct mode' do
  8. before do
  9. allow(SelfDestructHelper).to receive(:self_destruct?).and_return(false)
  10. end
  11. it 'returns without processing' do
  12. worker.perform
  13. expect(account.reload.suspended_at).to be_nil
  14. end
  15. end
  16. context 'when in self-destruct mode' do
  17. before do
  18. allow(SelfDestructHelper).to receive(:self_destruct?).and_return(true)
  19. end
  20. context 'when sidekiq is overwhelmed' do
  21. before do
  22. stats = instance_double(Sidekiq::Stats, enqueued: described_class::MAX_ENQUEUED**2)
  23. allow(Sidekiq::Stats).to receive(:new).and_return(stats)
  24. end
  25. it 'returns without processing' do
  26. worker.perform
  27. expect(account.reload.suspended_at).to be_nil
  28. end
  29. end
  30. context 'when sidekiq is operational' do
  31. it 'suspends local non-suspended accounts' do
  32. worker.perform
  33. expect(account.reload.suspended_at).to_not be_nil
  34. end
  35. it 'suspends local suspended accounts marked for deletion' do
  36. account.update(suspended_at: 10.days.ago)
  37. deletion_request = Fabricate(:account_deletion_request, account: account)
  38. worker.perform
  39. expect(account.reload.suspended_at).to be > 1.day.ago
  40. expect { deletion_request.reload }.to raise_error(ActiveRecord::RecordNotFound)
  41. end
  42. end
  43. end
  44. end
  45. end