DEV: Add categories_and_hot Route (#29948)

This PR adds a route to categories_and_hot and methods in categories_controller.
This commit is contained in:
Guhyoun Nam
2024-11-27 11:11:33 -06:00
committed by GitHub
parent b4406861ae
commit f186e3e80b
3 changed files with 48 additions and 1 deletions

View File

@@ -1053,6 +1053,17 @@ RSpec.describe CategoriesController do
expect(response.parsed_body["topic_list"]["more_topics_url"]).to start_with("/top")
end
it "includes more_topics_url in the response to /categories_and_hot" do
SiteSetting.categories_topics = 5
Fabricate.times(10, :topic, category: category, like_count: 1000, posts_count: 100)
TopicHotScore.update_scores
get "/categories_and_hot.json"
expect(response.status).to eq(200)
expect(response.parsed_body["topic_list"]["more_topics_url"]).to start_with("/hot")
end
describe "Showing top topics from private categories" do
it "returns the top topic from the private category when the user is a member" do
restricted_group = Fabricate(:group)
@@ -1072,6 +1083,26 @@ RSpec.describe CategoriesController do
expect(parsed_topic).to be_present
end
end
describe "Showing hot topics from private categories" do
it "returns the hot topic from the private category when the user is a member" do
restricted_group = Fabricate(:group)
private_cat = Fabricate(:private_category, group: restricted_group)
private_topic = Fabricate(:topic, category: private_cat, like_count: 1000, posts_count: 100)
TopicHotScore.update_scores
restricted_group.add(user)
sign_in(user)
get "/categories_and_hot.json"
parsed_topic =
response
.parsed_body
.dig("topic_list", "topics")
.detect { |t| t.dig("id") == private_topic.id }
expect(parsed_topic).to be_present
end
end
end
describe "#visible_groups" do