2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Jobs::NotifyReviewable do
|
2022-08-03 01:57:59 -04:00
|
|
|
# remove all the legacy stuff here when redesigned_user_menu_enabled is
|
|
|
|
# removed
|
|
|
|
describe "#execute" do
|
2022-08-31 14:15:01 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin, moderator: true) }
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:group_user) { Fabricate(:group_user) }
|
2022-08-03 01:57:59 -04:00
|
|
|
fab!(:group) { group_user.group }
|
2022-08-31 14:15:01 -04:00
|
|
|
fab!(:user) { group_user.user }
|
2022-08-03 01:57:59 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
it "will notify users of new reviewable content for the new user menu" do
|
2022-12-07 20:44:29 -05:00
|
|
|
SiteSetting.navigation_menu = "sidebar"
|
2022-08-31 14:15:01 -04:00
|
|
|
SiteSetting.enable_category_group_moderation = true
|
2022-08-03 01:57:59 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
GroupUser.create!(group_id: group.id, user_id: moderator.id)
|
|
|
|
|
|
|
|
# Content for admins only
|
|
|
|
admin_reviewable = Fabricate(:reviewable, reviewable_by_moderator: false)
|
|
|
|
admin.update!(last_seen_reviewable_id: admin_reviewable.id)
|
|
|
|
|
|
|
|
messages =
|
|
|
|
MessageBus.track_publish { described_class.new.execute(reviewable_id: admin_reviewable.id) }
|
|
|
|
|
|
|
|
expect(messages.size).to eq(1)
|
|
|
|
|
|
|
|
admin_message = messages.first
|
|
|
|
|
|
|
|
expect(admin_message.channel).to eq("/reviewable_counts/#{admin.id}")
|
|
|
|
expect(admin_message.user_ids).to eq([admin.id])
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(admin_message.data[:unseen_reviewable_count]).to eq(0)
|
|
|
|
|
|
|
|
# Content for moderators
|
|
|
|
moderator_reviewable = Fabricate(:reviewable, reviewable_by_moderator: true)
|
|
|
|
|
|
|
|
messages =
|
|
|
|
MessageBus.track_publish do
|
|
|
|
described_class.new.execute(reviewable_id: moderator_reviewable.id)
|
|
|
|
end
|
|
|
|
expect(messages.size).to eq(2)
|
|
|
|
|
|
|
|
admin_message = messages.find { |m| m.user_ids == [admin.id] }
|
|
|
|
|
|
|
|
expect(admin_message.channel).to eq("/reviewable_counts/#{admin.id}")
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(2)
|
|
|
|
expect(admin_message.data[:unseen_reviewable_count]).to eq(1)
|
|
|
|
|
|
|
|
moderator_message = messages.find { |m| m.user_ids == [moderator.id] }
|
|
|
|
|
|
|
|
expect(moderator_message.channel).to eq("/reviewable_counts/#{moderator.id}")
|
|
|
|
expect(moderator_message.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(moderator_message.data[:unseen_reviewable_count]).to eq(1)
|
|
|
|
|
|
|
|
moderator.update!(last_seen_reviewable_id: moderator_reviewable.id)
|
|
|
|
|
|
|
|
# Content for a group
|
|
|
|
group_reviewable =
|
|
|
|
Fabricate(:reviewable, reviewable_by_moderator: true, reviewable_by_group: group)
|
|
|
|
|
|
|
|
messages =
|
|
|
|
MessageBus.track_publish { described_class.new.execute(reviewable_id: group_reviewable.id) }
|
|
|
|
|
|
|
|
expect(messages.size).to eq(3)
|
|
|
|
|
|
|
|
admin_message = messages.find { |m| m.user_ids == [admin.id] }
|
2022-08-03 01:57:59 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
expect(admin_message.channel).to eq("/reviewable_counts/#{admin.id}")
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(3)
|
|
|
|
expect(admin_message.data[:unseen_reviewable_count]).to eq(2)
|
|
|
|
|
|
|
|
moderator_message = messages.find { |m| m.user_ids == [moderator.id] }
|
|
|
|
|
|
|
|
expect(moderator_message.channel).to eq("/reviewable_counts/#{moderator.id}")
|
|
|
|
expect(moderator_message.data[:reviewable_count]).to eq(2)
|
|
|
|
expect(moderator_message.data[:unseen_reviewable_count]).to eq(1)
|
|
|
|
|
|
|
|
group_user_message = messages.find { |m| m.user_ids == [user.id] }
|
|
|
|
|
|
|
|
expect(group_user_message.channel).to eq("/reviewable_counts/#{user.id}")
|
|
|
|
expect(group_user_message.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(group_user_message.data[:unseen_reviewable_count]).to eq(1)
|
2022-08-03 01:57:59 -04:00
|
|
|
end
|
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
it "will notify users of new reviewable content for the old user menu" do
|
2022-12-07 20:44:29 -05:00
|
|
|
SiteSetting.navigation_menu = "legacy"
|
2020-07-14 12:36:19 -04:00
|
|
|
SiteSetting.enable_category_group_moderation = true
|
2019-04-17 17:12:32 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
GroupUser.create!(group_id: group.id, user_id: moderator.id)
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
# Content for admins only
|
2022-08-03 01:57:59 -04:00
|
|
|
admin_reviewable = Fabricate(:reviewable, reviewable_by_moderator: false)
|
2022-08-31 14:15:01 -04:00
|
|
|
admin.update!(last_seen_reviewable_id: admin_reviewable.id)
|
|
|
|
|
2022-08-03 01:57:59 -04:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish { described_class.new.execute(reviewable_id: admin_reviewable.id) }
|
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
expect(messages.size).to eq(1)
|
2022-08-03 01:57:59 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
admin_message = messages.first
|
|
|
|
|
|
|
|
expect(admin_message.channel).to eq("/reviewable_counts")
|
|
|
|
expect(admin_message.user_ids).to eq([admin.id])
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(admin_message.data.has_key?(:unseen_reviewable_count)).to eq(false)
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
# Content for moderators
|
2022-08-31 14:15:01 -04:00
|
|
|
moderator_reviewable = Fabricate(:reviewable, reviewable_by_moderator: true)
|
|
|
|
|
2022-08-03 01:57:59 -04:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish do
|
2022-08-31 14:15:01 -04:00
|
|
|
described_class.new.execute(reviewable_id: moderator_reviewable.id)
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
2022-08-03 01:57:59 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
expect(messages.size).to eq(2)
|
2022-08-03 01:57:59 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
admin_message = messages.find { |m| m.user_ids == [admin.id] }
|
|
|
|
expect(admin_message.channel).to eq("/reviewable_counts")
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(2)
|
|
|
|
expect(admin_message.data.has_key?(:unseen_reviewable_count)).to eq(false)
|
2022-08-03 01:57:59 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
moderator_message = messages.find { |m| m.user_ids == [moderator.id] }
|
|
|
|
expect(moderator_message.channel).to eq("/reviewable_counts")
|
|
|
|
expect(moderator_message.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(moderator_message.data.key?(:unseen_reviewable_count)).to eq(false)
|
2022-08-03 01:57:59 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
moderator.update!(last_seen_reviewable_id: moderator_reviewable.id)
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
# Content for a group
|
2022-08-03 01:57:59 -04:00
|
|
|
group_reviewable =
|
|
|
|
Fabricate(:reviewable, reviewable_by_moderator: true, reviewable_by_group: group)
|
2022-08-31 14:15:01 -04:00
|
|
|
|
2022-08-03 01:57:59 -04:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish { described_class.new.execute(reviewable_id: group_reviewable.id) }
|
2022-08-31 14:15:01 -04:00
|
|
|
|
|
|
|
expect(messages.size).to eq(3)
|
|
|
|
|
|
|
|
admin_message = messages.find { |m| m.user_ids == [admin.id] }
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(3)
|
|
|
|
expect(admin_message.channel).to eq("/reviewable_counts")
|
|
|
|
expect(admin_message.data.key?(:unseen_reviewable_count)).to eq(false)
|
|
|
|
|
|
|
|
moderator_message = messages.find { |m| m.user_ids == [moderator.id] }
|
|
|
|
expect(moderator_message.data[:reviewable_count]).to eq(2)
|
|
|
|
expect(moderator_message.channel).to eq("/reviewable_counts")
|
|
|
|
expect(moderator_message.data.key?(:unseen_reviewable_count)).to eq(false)
|
|
|
|
|
|
|
|
group_user_message = messages.find { |m| m.user_ids == [user.id] }
|
|
|
|
expect(group_user_message.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(group_user_message.channel).to eq("/reviewable_counts")
|
|
|
|
expect(group_user_message.data.key?(:unseen_reviewable_count)).to eq(false)
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
|
|
|
|
2019-04-17 17:12:32 -04:00
|
|
|
it "won't notify a group when disabled" do
|
2020-07-14 12:36:19 -04:00
|
|
|
SiteSetting.enable_category_group_moderation = false
|
2019-04-17 17:12:32 -04:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
GroupUser.create!(group_id: group.id, user_id: moderator.id)
|
|
|
|
reviewable = Fabricate(:reviewable, reviewable_by_moderator: true, reviewable_by_group: group)
|
|
|
|
|
2019-04-17 17:12:32 -04:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/reviewable_counts") do
|
2022-08-31 14:15:01 -04:00
|
|
|
described_class.new.execute(reviewable_id: reviewable.id)
|
2019-04-17 17:12:32 -04:00
|
|
|
end
|
2022-08-31 14:15:01 -04:00
|
|
|
|
|
|
|
group_user_message = messages.find { |m| m.user_ids.include?(user.id) }
|
|
|
|
|
|
|
|
expect(group_user_message).to be_blank
|
2019-04-17 17:12:32 -04:00
|
|
|
end
|
|
|
|
|
2022-08-03 01:57:59 -04:00
|
|
|
it "respects priority" do
|
2022-12-13 19:25:19 -05:00
|
|
|
SiteSetting.navigation_menu = "legacy"
|
2020-07-14 12:36:19 -04:00
|
|
|
SiteSetting.enable_category_group_moderation = true
|
2019-05-07 13:25:11 -04:00
|
|
|
Reviewable.set_priorities(medium: 2.0)
|
|
|
|
SiteSetting.reviewable_default_visibility = "medium"
|
2019-01-03 12:03:01 -05:00
|
|
|
|
2022-08-31 14:15:01 -04:00
|
|
|
GroupUser.create!(group_id: group.id, user_id: moderator.id)
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
# Content for admins only
|
2022-08-31 14:15:01 -04:00
|
|
|
admin_reviewable = Fabricate(:reviewable, reviewable_by_moderator: false)
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/reviewable_counts") do
|
2022-08-31 14:15:01 -04:00
|
|
|
described_class.new.execute(reviewable_id: admin_reviewable.id)
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
2022-08-31 14:15:01 -04:00
|
|
|
|
|
|
|
admin_message = messages.find { |m| m.user_ids.include?(admin.id) }
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(0)
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
# Content for moderators
|
2022-08-31 14:15:01 -04:00
|
|
|
moderator_reviewable = Fabricate(:reviewable, reviewable_by_moderator: true)
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/reviewable_counts") do
|
2022-08-31 14:15:01 -04:00
|
|
|
described_class.new.execute(reviewable_id: moderator_reviewable.id)
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
2022-08-31 14:15:01 -04:00
|
|
|
|
|
|
|
admin_message = messages.find { |m| m.user_ids.include?(admin.id) }
|
|
|
|
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(0)
|
|
|
|
|
|
|
|
moderator_message = messages.find { |m| m.user_ids.include?(moderator.id) }
|
|
|
|
expect(moderator_message.data[:reviewable_count]).to eq(0)
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
# Content for a group
|
2022-08-31 14:15:01 -04:00
|
|
|
group_reviewable =
|
|
|
|
Fabricate(:reviewable, reviewable_by_moderator: true, reviewable_by_group: group)
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/reviewable_counts") do
|
2022-08-31 14:15:01 -04:00
|
|
|
described_class.new.execute(reviewable_id: group_reviewable.id)
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
2022-08-31 14:15:01 -04:00
|
|
|
|
|
|
|
admin_message = messages.find { |m| m.user_ids.include?(admin.id) }
|
|
|
|
expect(admin_message.data[:reviewable_count]).to eq(0)
|
|
|
|
|
|
|
|
moderator_messages = messages.select { |m| m.user_ids.include?(moderator.id) }
|
|
|
|
expect(moderator_messages.size).to eq(1)
|
|
|
|
expect(moderator_messages[0].data[:reviewable_count]).to eq(0)
|
|
|
|
|
|
|
|
group_user_message = messages.find { |m| m.user_ids.include?(user.id) }
|
|
|
|
expect(group_user_message.data[:reviewable_count]).to eq(0)
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
|
|
|
end
|
2020-04-27 13:51:25 -04:00
|
|
|
|
|
|
|
it "skips sending notifications if user_ids is empty" do
|
|
|
|
reviewable = Fabricate(:reviewable, reviewable_by_moderator: true)
|
|
|
|
regular_user = Fabricate(:user)
|
|
|
|
|
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/reviewable_counts") do
|
|
|
|
described_class.new.execute(reviewable_id: reviewable.id)
|
|
|
|
end
|
|
|
|
|
2020-08-07 12:13:02 -04:00
|
|
|
expect(messages.size).to eq(0)
|
2020-04-27 13:51:25 -04:00
|
|
|
end
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|