user_cleanup_scheduler_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Scheduler::UserCleanupScheduler do
  4. subject { described_class.new }
  5. let!(:new_unconfirmed_user) { Fabricate(:user) }
  6. let!(:old_unconfirmed_user) { Fabricate(:user) }
  7. let!(:confirmed_user) { Fabricate(:user) }
  8. let!(:moderation_note) { Fabricate(:account_moderation_note, account: Fabricate(:account), target_account: old_unconfirmed_user.account) }
  9. describe '#perform' do
  10. before do
  11. # Need to update the already-existing users because their initialization overrides confirmation_sent_at
  12. new_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: Time.now.utc)
  13. old_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: 1.week.ago)
  14. confirmed_user.update!(confirmed_at: 1.day.ago)
  15. end
  16. it 'deletes the old unconfirmed user' do
  17. expect { subject.perform }.to change { User.exists?(old_unconfirmed_user.id) }.from(true).to(false)
  18. end
  19. it "deletes the old unconfirmed user's account" do
  20. expect { subject.perform }.to change { Account.exists?(old_unconfirmed_user.account_id) }.from(true).to(false)
  21. end
  22. it 'does not delete the new unconfirmed user or their account' do
  23. subject.perform
  24. expect(User.exists?(new_unconfirmed_user.id)).to be true
  25. expect(Account.exists?(new_unconfirmed_user.account_id)).to be true
  26. end
  27. it 'does not delete the confirmed user or their account' do
  28. subject.perform
  29. expect(User.exists?(confirmed_user.id)).to be true
  30. expect(Account.exists?(confirmed_user.account_id)).to be true
  31. end
  32. end
  33. end