discourse-ai/spec/requests/topic_spec.rb
Roman Rizzi 58b96eda6c
REFACTOR: Build related topics using TopicQuery. (#124)
TopicQuery already provides a lot of safeguards and options for filtering topic, and enforcing permissions. It makes sense to rely on it as other plugins like discourse-assign do.

As a bonus, we now have access to the current_user while serializing these topics, so users will see things like unread posts count just like we do for the lists.
2023-08-02 16:58:09 -03:00

40 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
describe ::TopicsController do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic1) { Fabricate(:topic) }
fab!(:topic2) { Fabricate(:topic) }
fab!(:topic3) { Fabricate(:topic) }
fab!(:user) { Fabricate(:admin) }
before do
SiteSetting.ai_embeddings_semantic_related_topics_enabled = true
SiteSetting.ai_embeddings_semantic_related_topics = 2
end
context "when a user is logged on" do
it "includes related topics in payload when configured" do
DiscourseAi::Embeddings::SemanticRelated.stubs(:related_topic_ids_for).returns(
[topic1.id, topic2.id, topic3.id],
)
get("#{topic.relative_url}.json")
expect(response.status).to eq(200)
json = response.parsed_body
expect(json["suggested_topics"].length).to eq(0)
expect(json["related_topics"].length).to eq(2)
sign_in(user)
get("#{topic.relative_url}.json")
json = response.parsed_body
expect(json["suggested_topics"].length).to eq(0)
expect(json["related_topics"].length).to eq(2)
end
end
end