2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-18 23:25:15 +08:00
|
|
|
RSpec.describe Jobs::CleanUpInactiveUsers do
|
2019-03-19 09:53:18 +08:00
|
|
|
it "should clean up new users that have been inactive" do
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 0
|
2019-03-18 23:25:15 +08:00
|
|
|
|
2023-05-23 16:11:23 +08:00
|
|
|
user =
|
|
|
|
Fabricate(
|
|
|
|
:user,
|
|
|
|
created_at: 5.days.ago,
|
|
|
|
last_seen_at: 5.days.ago,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
)
|
2019-03-18 23:25:15 +08:00
|
|
|
|
2019-03-19 09:53:18 +08:00
|
|
|
Fabricate(:active_user)
|
|
|
|
|
|
|
|
Fabricate(
|
|
|
|
:post,
|
2023-05-23 16:11:23 +08:00
|
|
|
user:
|
|
|
|
Fabricate(
|
|
|
|
:user,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
created_at: 5.days.ago,
|
|
|
|
last_seen_at: 5.days.ago,
|
|
|
|
),
|
2019-03-19 09:53:18 +08:00
|
|
|
).user
|
|
|
|
|
2023-05-23 16:11:23 +08:00
|
|
|
Fabricate(
|
|
|
|
:user,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
created_at: 5.days.ago,
|
|
|
|
last_seen_at: 2.days.ago,
|
|
|
|
)
|
2019-03-19 09:53:18 +08:00
|
|
|
|
2023-05-23 16:11:23 +08:00
|
|
|
Fabricate(:user, trust_level: TrustLevel.levels[:basic], created_at: 5.days.ago)
|
2019-03-19 09:53:18 +08:00
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to_not change { User.count }
|
2019-03-18 23:25:15 +08:00
|
|
|
|
2019-03-19 09:53:18 +08:00
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 4
|
2019-03-18 23:25:15 +08:00
|
|
|
|
2019-03-19 09:53:18 +08:00
|
|
|
expect { described_class.new.execute({}) }.to change { User.count }.by(-1)
|
2019-03-18 23:25:15 +08:00
|
|
|
|
2019-03-19 09:53:18 +08:00
|
|
|
expect(User.exists?(id: user.id)).to eq(false)
|
2019-03-18 23:25:15 +08:00
|
|
|
end
|
2019-04-25 17:59:31 +08:00
|
|
|
|
|
|
|
it "doesn't delete inactive admins" do
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 4
|
2023-05-23 16:11:23 +08:00
|
|
|
admin =
|
|
|
|
Fabricate(
|
|
|
|
:admin,
|
|
|
|
created_at: 5.days.ago,
|
|
|
|
last_seen_at: 5.days.ago,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
)
|
2019-04-25 17:59:31 +08:00
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to_not change { User.count }
|
|
|
|
expect(User.exists?(admin.id)).to eq(true)
|
|
|
|
end
|
2019-05-14 03:44:03 +08:00
|
|
|
|
|
|
|
it "doesn't delete inactive mods" do
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 4
|
|
|
|
moderator =
|
2023-05-23 16:11:23 +08:00
|
|
|
Fabricate(
|
|
|
|
:moderator,
|
|
|
|
created_at: 5.days.ago,
|
|
|
|
last_seen_at: 5.days.ago,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
)
|
2019-05-14 03:44:03 +08:00
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to_not change { User.count }
|
|
|
|
expect(User.exists?(moderator.id)).to eq(true)
|
|
|
|
end
|
2023-05-23 02:56:24 +08:00
|
|
|
|
|
|
|
it "should clean up a user that has a deleted post" do
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 1
|
|
|
|
|
|
|
|
Fabricate(:active_user)
|
|
|
|
|
|
|
|
Fabricate(
|
|
|
|
:post,
|
2023-05-23 16:11:23 +08:00
|
|
|
user:
|
|
|
|
Fabricate(
|
|
|
|
:user,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
created_at: 5.days.ago,
|
|
|
|
last_seen_at: 2.days.ago,
|
|
|
|
),
|
2023-05-23 02:56:24 +08:00
|
|
|
# ensuring that topic author is a different user as the topic is non-deleted
|
|
|
|
topic: Fabricate(:topic, user: Fabricate(:user)),
|
|
|
|
deleted_at: Time.now,
|
|
|
|
).user
|
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to change { User.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should clean up user that has a deleted topic" do
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 1
|
|
|
|
|
|
|
|
Fabricate(:active_user)
|
|
|
|
|
|
|
|
Fabricate(
|
|
|
|
:topic,
|
2023-05-23 16:11:23 +08:00
|
|
|
user:
|
|
|
|
Fabricate(
|
|
|
|
:user,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
created_at: 2.days.ago,
|
|
|
|
last_seen_at: 2.days.ago,
|
|
|
|
),
|
2023-05-23 02:56:24 +08:00
|
|
|
deleted_at: Time.now,
|
|
|
|
).user
|
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to change { User.count }.by(-1)
|
|
|
|
end
|
2019-03-18 23:25:15 +08:00
|
|
|
end
|