discourse-ai/spec/requests/topic_spec.rb
Sam 0d80d9ec49
FEATURE: allow limiting results in related topics section (#30)
Also:

- Normalizes behavior between logged in and anon,
 we only show related topics in the related topic section

- Renames "suggested" to "related" given this only exists in related section
- Adds a spec section to ensure anon does not regress
- Adds `ai_embeddings_semantic_related_topics` to limit related topics

Renamed settings:

ai_embeddings_semantic_suggested_model -> ai_embeddings_semantic_related_model
ai_embeddings_semantic_suggested_topics_enabled -> ai_embeddings_semantic_related_topics_enabled

Plugins is still in an experimental phase and not much is overidden hence
avoiding adding site setting migrations.


Co-authored-by: Krzysztof Kotlarek <kotlarek.krzysztof@gmail.com>
2023-03-31 11:04:34 +11:00

42 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
Discourse.cache.clear
SiteSetting.ai_embeddings_semantic_related_topics_enabled = true
SiteSetting.ai_embeddings_semantic_related_topics = 2
end
after { Discourse.cache.clear }
context "when a user is logged on" do
it "includes related topics in payload when configured" do
DiscourseAi::Embeddings::SemanticRelated.stubs(:search_suggestions).returns(
[topic1.id, topic2.id, topic3.id],
)
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)
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