2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::NotifyReviewable do
|
2022-08-03 13:57:59 +08:00
|
|
|
describe "#execute" do
|
2022-09-01 02:15:01 +08:00
|
|
|
fab!(:admin) { Fabricate(:admin, moderator: true) }
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:moderator)
|
|
|
|
fab!(:group_user)
|
2022-08-03 13:57:59 +08:00
|
|
|
fab!(:group) { group_user.group }
|
2022-09-01 02:15:01 +08:00
|
|
|
fab!(:user) { group_user.user }
|
2022-08-03 13:57:59 +08:00
|
|
|
|
2023-05-18 00:16:42 +08:00
|
|
|
it "will notify users of new reviewable content for the user menu" do
|
2022-12-08 09:44:29 +08:00
|
|
|
SiteSetting.navigation_menu = "sidebar"
|
2022-09-01 02:15:01 +08:00
|
|
|
SiteSetting.enable_category_group_moderation = true
|
2022-08-03 13:57:59 +08:00
|
|
|
|
2022-09-01 02:15:01 +08: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 13:57:59 +08:00
|
|
|
|
2022-09-01 02:15:01 +08: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 13:57:59 +08:00
|
|
|
end
|
|
|
|
|
2019-04-18 05:12:32 +08:00
|
|
|
it "won't notify a group when disabled" do
|
2020-07-15 00:36:19 +08:00
|
|
|
SiteSetting.enable_category_group_moderation = false
|
2019-04-18 05:12:32 +08:00
|
|
|
|
2022-09-01 02:15:01 +08:00
|
|
|
GroupUser.create!(group_id: group.id, user_id: moderator.id)
|
|
|
|
reviewable = Fabricate(:reviewable, reviewable_by_moderator: true, reviewable_by_group: group)
|
|
|
|
|
2019-04-18 05:12:32 +08:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/reviewable_counts") do
|
2022-09-01 02:15:01 +08:00
|
|
|
described_class.new.execute(reviewable_id: reviewable.id)
|
2019-04-18 05:12:32 +08:00
|
|
|
end
|
2022-09-01 02:15:01 +08:00
|
|
|
|
|
|
|
group_user_message = messages.find { |m| m.user_ids.include?(user.id) }
|
|
|
|
|
|
|
|
expect(group_user_message).to be_blank
|
2019-04-18 05:12:32 +08:00
|
|
|
end
|
2020-04-28 01:51:25 +08:00
|
|
|
end
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|