DEV: Minor refactoring and improvements to TopicsFilter (#21068)

This commit is contained in:
Alan Guo Xiang Tan 2023-04-12 14:47:21 +08:00 committed by GitHub
parent 3cb9fd739a
commit 3b045a2016
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,6 +91,29 @@ RSpec.describe TopicsFilter do
end
end
describe "when query string is `in:bookmarked in:pinnned`" do
it "should return topics that are bookmarked and pinned" do
expect(
TopicsFilter
.new(guardian: Guardian.new(user))
.filter_from_query_string("in:bookmarked in:pinned")
.pluck(:id),
).to eq([])
BookmarkManager.new(user).create_for(
bookmarkable_id: pinned_topic.id,
bookmarkable_type: "Topic",
)
expect(
TopicsFilter
.new(guardian: Guardian.new(user))
.filter_from_query_string("in:bookmarked in:pinned")
.pluck(:id),
).to contain_exactly(pinned_topic.id)
end
end
TopicUser.notification_levels.keys.each do |notification_level|
describe "when query string is `in:#{notification_level}`" do
fab!("user_#{notification_level}_topic".to_sym) do
@ -584,6 +607,19 @@ RSpec.describe TopicsFilter do
.pluck(:id),
).not_to include(topic_in_private_category.id)
end
describe "when query string is `status:closed status:unlisted`" do
fab!(:closed_and_unlisted_topic) { Fabricate(:topic, closed: true, visible: false) }
it "should only return topics that have been closed and are not visible" do
expect(
TopicsFilter
.new(guardian: Guardian.new)
.filter_from_query_string("status:closed status:unlisted")
.pluck(:id),
).to contain_exactly(closed_and_unlisted_topic.id)
end
end
end
describe "when filtering by tags" do