diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rb new file mode 100644 index 0000000..69c5c77 --- /dev/null +++ b/spec/lib/topic_query_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'topic_view' + +describe TopicQuery do + fab!(:user) { Fabricate(:user) } + fab!(:admin) { Fabricate(:admin) } + fab!(:other_admin) { Fabricate(:admin) } + + fab!(:user_pm) { Fabricate(:private_message_topic, user: user) } + fab!(:admin_pm) { Fabricate(:private_message_topic, user: admin) } + fab!(:other_admin_pm) { Fabricate(:private_message_topic, user: other_admin) } + + fab!(:group) { Fabricate(:group) } + + describe '#list_group_topics_assigned' do + before do + SiteSetting.assign_enabled = true + + [user, admin, other_admin].each do |user| + group.add(user) + end + + [user_pm, admin_pm, other_admin_pm].each do |topic| + Fabricate(:post, topic: topic) + end + + Assigner.new(user_pm, Discourse.system_user).assign(admin) + Assigner.new(admin_pm, Discourse.system_user).assign(admin) + Assigner.new(other_admin_pm, Discourse.system_user).assign(other_admin) + end + + it "includes PMs from all users" do + expect(TopicQuery.new(user).list_group_topics_assigned(group).topics).to contain_exactly(user_pm) + expect(TopicQuery.new(admin).list_group_topics_assigned(group).topics).to contain_exactly(user_pm, admin_pm, other_admin_pm) + expect(TopicQuery.new(other_admin).list_group_topics_assigned(group).topics).to contain_exactly(user_pm, admin_pm, other_admin_pm) + end + end +end