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
|
|
|
# remove all the legacy stuff here when redesigned_user_menu_enabled is
|
|
|
|
# removed
|
|
|
|
describe '#execute' do
|
|
|
|
fab!(:legacy_menu_admin) { Fabricate(:admin, moderator: true) }
|
|
|
|
fab!(:legacy_menu_mod) { Fabricate(:moderator) }
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:group_user) { Fabricate(:group_user) }
|
2022-08-03 13:57:59 +08:00
|
|
|
fab!(:legacy_menu_user) { group_user.user }
|
2019-01-04 01:03:01 +08:00
|
|
|
|
2022-08-03 13:57:59 +08:00
|
|
|
fab!(:group) { group_user.group }
|
|
|
|
|
|
|
|
fab!(:new_menu_admin) { Fabricate(:admin, moderator: true) }
|
|
|
|
fab!(:new_menu_mod) { Fabricate(:moderator) }
|
|
|
|
fab!(:new_menu_user) { Fabricate(:user, groups: [group]) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
[new_menu_admin, new_menu_mod, new_menu_user].each(&:enable_redesigned_user_menu)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
[new_menu_admin, new_menu_mod, new_menu_user].each(&:disable_redesigned_user_menu)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "will notify users of new reviewable content and respects backward compatibility for the legacy user menu" do
|
2020-07-15 00:36:19 +08:00
|
|
|
SiteSetting.enable_category_group_moderation = true
|
2019-04-18 05:12:32 +08:00
|
|
|
|
2022-08-03 13:57:59 +08:00
|
|
|
GroupUser.create!(group_id: group.id, user_id: legacy_menu_mod.id)
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
# Content for admins only
|
2022-08-03 13:57:59 +08:00
|
|
|
admin_reviewable = Fabricate(:reviewable, reviewable_by_moderator: false)
|
|
|
|
new_menu_admin.update!(last_seen_reviewable_id: admin_reviewable.id)
|
|
|
|
messages = MessageBus.track_publish do
|
|
|
|
described_class.new.execute(reviewable_id: admin_reviewable.id)
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|
2022-08-03 13:57:59 +08:00
|
|
|
expect(messages.size).to eq(2)
|
|
|
|
legacy_menu_admin_msg = messages.find { |m| m.user_ids.include?(legacy_menu_admin.id) }
|
|
|
|
expect(legacy_menu_admin_msg.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(legacy_menu_admin_msg.channel).to eq("/reviewable_counts")
|
|
|
|
expect(legacy_menu_admin_msg.data.key?(:unseen_reviewable_count)).to eq(false)
|
|
|
|
|
|
|
|
new_menu_admin_msg = messages.find { |m| m.user_ids == [new_menu_admin.id] }
|
|
|
|
expect(new_menu_admin_msg.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(new_menu_admin_msg.channel).to eq("/reviewable_counts/#{new_menu_admin.id}")
|
|
|
|
expect(new_menu_admin_msg.data[:unseen_reviewable_count]).to eq(0)
|
|
|
|
|
|
|
|
expect(messages.any? { |m| m.user_ids.include?(legacy_menu_mod.id) }).to eq(false)
|
|
|
|
expect(messages.any? { |m| m.user_ids.include?(legacy_menu_user.id) }).to eq(false)
|
|
|
|
expect(messages.any? { |m| m.user_ids.include?(new_menu_mod.id) }).to eq(false)
|
|
|
|
expect(messages.any? { |m| m.user_ids.include?(new_menu_user.id) }).to eq(false)
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
# Content for moderators
|
2022-08-03 13:57:59 +08:00
|
|
|
mod_reviewable = Fabricate(:reviewable, reviewable_by_moderator: true)
|
|
|
|
messages = MessageBus.track_publish do
|
|
|
|
described_class.new.execute(reviewable_id: mod_reviewable.id)
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|
2022-08-03 13:57:59 +08:00
|
|
|
expect(messages.size).to eq(4)
|
|
|
|
legacy_menu_admin_msg = messages.find { |m| m.user_ids == [legacy_menu_admin.id] }
|
|
|
|
expect(legacy_menu_admin_msg.data[:reviewable_count]).to eq(2)
|
|
|
|
expect(legacy_menu_admin_msg.channel).to eq("/reviewable_counts")
|
|
|
|
expect(legacy_menu_admin_msg.data.key?(:unseen_reviewable_count)).to eq(false)
|
|
|
|
|
|
|
|
new_menu_admin_msg = messages.find { |m| m.user_ids == [new_menu_admin.id] }
|
|
|
|
expect(new_menu_admin_msg.data[:reviewable_count]).to eq(2)
|
|
|
|
expect(new_menu_admin_msg.channel).to eq("/reviewable_counts/#{new_menu_admin.id}")
|
|
|
|
expect(new_menu_admin_msg.data[:unseen_reviewable_count]).to eq(1)
|
|
|
|
|
|
|
|
legacy_menu_mod_msg = messages.find { |m| m.user_ids == [legacy_menu_mod.id] }
|
|
|
|
expect(legacy_menu_mod_msg.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(legacy_menu_mod_msg.channel).to eq("/reviewable_counts")
|
|
|
|
expect(legacy_menu_mod_msg.data.key?(:unseen_reviewable_count)).to eq(false)
|
|
|
|
|
|
|
|
new_menu_mod_msg = messages.find { |m| m.user_ids == [new_menu_mod.id] }
|
|
|
|
expect(new_menu_mod_msg.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(new_menu_mod_msg.channel).to eq("/reviewable_counts/#{new_menu_mod.id}")
|
|
|
|
expect(new_menu_mod_msg.data[:unseen_reviewable_count]).to eq(1)
|
|
|
|
|
|
|
|
expect(messages.any? { |m| m.user_ids.include?(legacy_menu_user.id) }).to eq(false)
|
|
|
|
expect(messages.any? { |m| m.user_ids.include?(new_menu_user.id) }).to eq(false)
|
|
|
|
|
|
|
|
new_menu_mod.update!(last_seen_reviewable_id: mod_reviewable.id)
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
# Content for a group
|
2022-08-03 13:57:59 +08:00
|
|
|
group_reviewable = Fabricate(:reviewable, reviewable_by_moderator: true, reviewable_by_group: group)
|
|
|
|
messages = MessageBus.track_publish do
|
|
|
|
described_class.new.execute(reviewable_id: group_reviewable.id)
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|
2022-08-03 13:57:59 +08:00
|
|
|
expect(messages.size).to eq(6)
|
|
|
|
legacy_menu_admin_msg = messages.find { |m| m.user_ids == [legacy_menu_admin.id] }
|
|
|
|
expect(legacy_menu_admin_msg.data[:reviewable_count]).to eq(3)
|
|
|
|
expect(legacy_menu_admin_msg.channel).to eq("/reviewable_counts")
|
|
|
|
expect(legacy_menu_admin_msg.data.key?(:unseen_reviewable_count)).to eq(false)
|
|
|
|
|
|
|
|
new_menu_admin_msg = messages.find { |m| m.user_ids == [new_menu_admin.id] }
|
|
|
|
expect(new_menu_admin_msg.data[:reviewable_count]).to eq(3)
|
|
|
|
expect(new_menu_admin_msg.channel).to eq("/reviewable_counts/#{new_menu_admin.id}")
|
|
|
|
expect(new_menu_admin_msg.data[:unseen_reviewable_count]).to eq(2)
|
|
|
|
|
|
|
|
legacy_menu_mod_msg = messages.find { |m| m.user_ids == [legacy_menu_mod.id] }
|
|
|
|
expect(legacy_menu_mod_msg.data[:reviewable_count]).to eq(2)
|
|
|
|
expect(legacy_menu_mod_msg.channel).to eq("/reviewable_counts")
|
|
|
|
expect(legacy_menu_mod_msg.data.key?(:unseen_reviewable_count)).to eq(false)
|
|
|
|
|
|
|
|
new_menu_mod_msg = messages.find { |m| m.user_ids == [new_menu_mod.id] }
|
|
|
|
expect(new_menu_mod_msg.data[:reviewable_count]).to eq(2)
|
|
|
|
expect(new_menu_mod_msg.channel).to eq("/reviewable_counts/#{new_menu_mod.id}")
|
|
|
|
expect(new_menu_mod_msg.data[:unseen_reviewable_count]).to eq(1)
|
|
|
|
|
|
|
|
legacy_menu_user_msg = messages.find { |m| m.user_ids == [legacy_menu_user.id] }
|
|
|
|
expect(legacy_menu_user_msg.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(legacy_menu_user_msg.channel).to eq("/reviewable_counts")
|
|
|
|
expect(legacy_menu_user_msg.data.key?(:unseen_reviewable_count)).to eq(false)
|
|
|
|
|
|
|
|
new_menu_user_msg = messages.find { |m| m.user_ids == [new_menu_user.id] }
|
|
|
|
expect(new_menu_user_msg.data[:reviewable_count]).to eq(1)
|
|
|
|
expect(new_menu_user_msg.channel).to eq("/reviewable_counts/#{new_menu_user.id}")
|
|
|
|
expect(new_menu_user_msg.data[:unseen_reviewable_count]).to eq(1)
|
2019-01-04 01:03:01 +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-08-03 13:57:59 +08:00
|
|
|
GroupUser.create!(group_id: group.id, user_id: legacy_menu_mod.id)
|
|
|
|
GroupUser.create!(group_id: group.id, user_id: new_menu_mod.id)
|
2019-04-18 05:12:32 +08:00
|
|
|
r3 = Fabricate(:reviewable, reviewable_by_moderator: true, reviewable_by_group: group)
|
|
|
|
messages = MessageBus.track_publish("/reviewable_counts") do
|
|
|
|
described_class.new.execute(reviewable_id: r3.id)
|
|
|
|
end
|
2022-08-03 13:57:59 +08:00
|
|
|
group_msg = messages.find { |m| m.user_ids.include?(legacy_menu_user.id) }
|
|
|
|
expect(group_msg).to be_blank
|
|
|
|
group_msg = messages.find { |m| m.user_ids.include?(new_menu_user.id) }
|
2019-04-18 05:12:32 +08:00
|
|
|
expect(group_msg).to be_blank
|
|
|
|
end
|
|
|
|
|
2022-08-03 13:57:59 +08:00
|
|
|
it "respects priority" do
|
2020-07-15 00:36:19 +08:00
|
|
|
SiteSetting.enable_category_group_moderation = true
|
2019-05-08 01:25:11 +08:00
|
|
|
Reviewable.set_priorities(medium: 2.0)
|
|
|
|
SiteSetting.reviewable_default_visibility = 'medium'
|
2019-01-04 01:03:01 +08:00
|
|
|
|
2022-08-03 13:57:59 +08:00
|
|
|
GroupUser.create!(group_id: group.id, user_id: legacy_menu_mod.id)
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
# Content for admins only
|
|
|
|
r1 = Fabricate(:reviewable, reviewable_by_moderator: false)
|
|
|
|
messages = MessageBus.track_publish("/reviewable_counts") do
|
|
|
|
described_class.new.execute(reviewable_id: r1.id)
|
|
|
|
end
|
2022-08-03 13:57:59 +08:00
|
|
|
legacy_menu_admin_msg = messages.find { |m| m.user_ids.include?(legacy_menu_admin.id) }
|
|
|
|
expect(legacy_menu_admin_msg.data[:reviewable_count]).to eq(0)
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
# Content for moderators
|
|
|
|
r2 = Fabricate(:reviewable, reviewable_by_moderator: true)
|
|
|
|
messages = MessageBus.track_publish("/reviewable_counts") do
|
|
|
|
described_class.new.execute(reviewable_id: r2.id)
|
|
|
|
end
|
2022-08-03 13:57:59 +08:00
|
|
|
legacy_menu_admin_msg = messages.find { |m| m.user_ids.include?(legacy_menu_admin.id) }
|
|
|
|
expect(legacy_menu_admin_msg.data[:reviewable_count]).to eq(0)
|
|
|
|
legacy_menu_mod_msg = messages.find { |m| m.user_ids.include?(legacy_menu_mod.id) }
|
|
|
|
expect(legacy_menu_mod_msg.data[:reviewable_count]).to eq(0)
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
# Content for a group
|
|
|
|
r3 = Fabricate(:reviewable, reviewable_by_moderator: true, reviewable_by_group: group)
|
|
|
|
messages = MessageBus.track_publish("/reviewable_counts") do
|
|
|
|
described_class.new.execute(reviewable_id: r3.id)
|
|
|
|
end
|
2022-08-03 13:57:59 +08:00
|
|
|
legacy_menu_admin_msg = messages.find { |m| m.user_ids.include?(legacy_menu_admin.id) }
|
|
|
|
expect(legacy_menu_admin_msg.data[:reviewable_count]).to eq(0)
|
|
|
|
mod_messages = messages.select { |m| m.user_ids.include?(legacy_menu_mod.id) }
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(mod_messages.size).to eq(1)
|
|
|
|
expect(mod_messages[0].data[:reviewable_count]).to eq(0)
|
2022-08-03 13:57:59 +08:00
|
|
|
group_msg = messages.find { |m| m.user_ids.include?(legacy_menu_user.id) }
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(group_msg.data[:reviewable_count]).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
2020-04-28 01:51:25 +08: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-08 00:13:02 +08:00
|
|
|
expect(messages.size).to eq(0)
|
2020-04-28 01:51:25 +08:00
|
|
|
end
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|