2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::PendingUsersReminder do
|
2022-07-28 00:14:14 +08:00
|
|
|
context "when must_approve_users is true" do
|
2013-08-27 04:15:59 +08:00
|
|
|
before do
|
2015-11-21 04:32:08 +08:00
|
|
|
SiteSetting.must_approve_users = true
|
|
|
|
Jobs::PendingUsersReminder.any_instance.stubs(:previous_newest_username).returns(nil)
|
2013-08-27 04:15:59 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't send a message to anyone when there are no pending users" do
|
2014-07-17 05:53:44 +08:00
|
|
|
PostCreator.expects(:create).never
|
2013-08-27 04:15:59 +08:00
|
|
|
Jobs::PendingUsersReminder.new.execute({})
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "when there are pending users" do
|
2015-11-21 05:05:57 +08:00
|
|
|
before do
|
|
|
|
Fabricate(:moderator, approved: true, approved_by_id: -1, approved_at: 1.week.ago)
|
|
|
|
Group.refresh_automatic_group!(:moderators)
|
|
|
|
end
|
|
|
|
|
2021-06-24 21:02:56 +08:00
|
|
|
it "sends a message if user was created more than pending_users_reminder_delay minutes ago" do
|
|
|
|
SiteSetting.pending_users_reminder_delay_minutes = 8
|
|
|
|
Fabricate(:user, created_at: 9.minutes.ago)
|
2015-11-21 05:05:57 +08:00
|
|
|
PostCreator.expects(:create).once
|
|
|
|
Jobs::PendingUsersReminder.new.execute({})
|
|
|
|
end
|
|
|
|
|
2021-06-24 21:02:56 +08:00
|
|
|
it "doesn't send a message if user was created less than pending_users_reminder_delay minutes ago" do
|
|
|
|
SiteSetting.pending_users_reminder_delay_minutes = 8
|
|
|
|
Fabricate(:user, created_at: 2.minutes.ago)
|
2015-11-21 05:05:57 +08:00
|
|
|
PostCreator.expects(:create).never
|
|
|
|
Jobs::PendingUsersReminder.new.execute({})
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't send a message if pending_users_reminder_delay is -1" do
|
2021-06-24 21:02:56 +08:00
|
|
|
SiteSetting.pending_users_reminder_delay_minutes = -1
|
|
|
|
Fabricate(:user, created_at: 24.hours.ago)
|
2015-11-21 05:05:57 +08:00
|
|
|
PostCreator.expects(:create).never
|
|
|
|
Jobs::PendingUsersReminder.new.execute({})
|
|
|
|
end
|
2017-12-14 10:48:46 +08:00
|
|
|
|
|
|
|
it "sets the correct pending user count in the notification" do
|
2021-06-24 21:02:56 +08:00
|
|
|
SiteSetting.pending_users_reminder_delay_minutes = 8
|
|
|
|
Fabricate(:user, created_at: 9.minutes.ago)
|
2017-12-14 10:48:46 +08:00
|
|
|
PostCreator.expects(:create).with(
|
|
|
|
Discourse.system_user,
|
|
|
|
has_entries(title: "1 user waiting for approval"),
|
|
|
|
)
|
|
|
|
Jobs::PendingUsersReminder.new.execute({})
|
|
|
|
end
|
2013-08-27 04:15:59 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "when must_approve_users is false" do
|
2017-07-07 14:09:14 +08:00
|
|
|
before { SiteSetting.must_approve_users = false }
|
2013-08-27 04:15:59 +08:00
|
|
|
|
|
|
|
it "doesn't send a message to anyone when there are pending users" do
|
|
|
|
AdminUserIndexQuery.any_instance.stubs(:find_users_query).returns(stub_everything(count: 1))
|
2014-07-17 05:53:44 +08:00
|
|
|
PostCreator.expects(:create).never
|
2013-08-27 04:15:59 +08:00
|
|
|
Jobs::PendingUsersReminder.new.execute({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|