2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-07 01:14:44 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe Scheduler::UserCleanupScheduler do
|
2023-02-07 01:14:44 +01:00
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
let!(:new_unconfirmed_user) { Fabricate(:user) }
|
|
|
|
let!(:old_unconfirmed_user) { Fabricate(:user) }
|
|
|
|
let!(:confirmed_user) { Fabricate(:user) }
|
|
|
|
let!(:moderation_note) { Fabricate(:account_moderation_note, account: Fabricate(:account), target_account: old_unconfirmed_user.account) }
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
before do
|
2024-07-25 16:18:24 +02:00
|
|
|
# Update already-existing users because initialization overrides `confirmation_sent_at`
|
2023-02-07 01:14:44 +01:00
|
|
|
new_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: Time.now.utc)
|
2024-05-15 10:27:34 +02:00
|
|
|
old_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: 10.days.ago)
|
2023-02-07 01:14:44 +01:00
|
|
|
confirmed_user.update!(confirmed_at: 1.day.ago)
|
|
|
|
end
|
|
|
|
|
2024-07-25 16:18:24 +02:00
|
|
|
it 'deletes the old unconfirmed user and metadata while preserving confirmed user and newer unconfirmed user' do
|
2023-12-21 15:23:53 +01:00
|
|
|
expect { subject.perform }
|
2024-07-25 16:18:24 +02:00
|
|
|
.to change { User.exists?(old_unconfirmed_user.id) }
|
|
|
|
.from(true).to(false)
|
|
|
|
.and change { Account.exists?(old_unconfirmed_user.account_id) }
|
|
|
|
.from(true).to(false)
|
|
|
|
expect { moderation_note.reload }
|
|
|
|
.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect_preservation_of(new_unconfirmed_user)
|
|
|
|
expect_preservation_of(confirmed_user)
|
2023-02-07 01:14:44 +01:00
|
|
|
end
|
|
|
|
|
2024-07-25 16:18:24 +02:00
|
|
|
private
|
2023-02-07 01:14:44 +01:00
|
|
|
|
2024-07-25 16:18:24 +02:00
|
|
|
def expect_preservation_of(user)
|
|
|
|
expect(User.exists?(user.id))
|
|
|
|
.to be true
|
|
|
|
expect(Account.exists?(user.account_id))
|
|
|
|
.to be true
|
2023-02-07 01:14:44 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|