discourse-ai/spec/lib/modules/embeddings/semantic_related_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

38 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
describe DiscourseAi::Embeddings::SemanticRelated do
fab!(:target) { Fabricate(:topic) }
fab!(:normal_topic_1) { Fabricate(:topic) }
fab!(:normal_topic_2) { Fabricate(:topic) }
fab!(:normal_topic_3) { Fabricate(:topic) }
fab!(:unlisted_topic) { Fabricate(:topic, visible: false) }
fab!(:private_topic) { Fabricate(:private_message_topic) }
fab!(:secured_category) { Fabricate(:category, read_restricted: true) }
fab!(:secured_category_topic) { Fabricate(:topic, category: secured_category) }
before { SiteSetting.ai_embeddings_semantic_related_topics_enabled = true }
describe "#candidates_for" do
before do
Discourse.cache.clear
described_class.stubs(:search_suggestions).returns(
Topic.unscoped.order(id: :desc).limit(10).pluck(:id),
)
end
after { Discourse.cache.clear }
it "returns the related topics without non public topics" do
results = described_class.candidates_for(target).to_a
expect(results).to include(normal_topic_1)
expect(results).to include(normal_topic_2)
expect(results).to include(normal_topic_3)
expect(results).to_not include(unlisted_topic)
expect(results).to_not include(private_topic)
expect(results).to_not include(secured_category_topic)
end
end
end