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
|
|
|
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
|
|
|
|
2023-05-17 12:16:42 -04:00
|
|
|
it "will notify users of new reviewable content for the 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
|
|
|
|
|
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
|
2020-04-27 13:51:25 -04:00
|
|
|
end
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|