2023-03-30 20:04:34 -04:00
|
|
|
# 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) }
|
2023-05-09 14:30:50 -04:00
|
|
|
fab!(:closed_topic) { Fabricate(:topic, closed: true) }
|
2023-03-30 20:04:34 -04:00
|
|
|
|
|
|
|
before { SiteSetting.ai_embeddings_semantic_related_topics_enabled = true }
|
|
|
|
|
|
|
|
describe "#candidates_for" do
|
|
|
|
before do
|
|
|
|
Discourse.cache.clear
|
2023-03-31 14:29:56 -04:00
|
|
|
DiscourseAi::Embeddings::Topic
|
|
|
|
.any_instance
|
|
|
|
.expects(:symmetric_semantic_search)
|
2023-05-09 14:30:50 -04:00
|
|
|
.returns(Topic.unscoped.order(id: :desc).limit(100).pluck(:id))
|
2023-03-30 20:04:34 -04:00
|
|
|
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)
|
2023-05-09 14:30:50 -04:00
|
|
|
expect(results).to include(closed_topic)
|
2023-03-30 21:04:17 -04:00
|
|
|
expect(results).to_not include(target)
|
2023-03-30 20:04:34 -04:00
|
|
|
expect(results).to_not include(unlisted_topic)
|
|
|
|
expect(results).to_not include(private_topic)
|
|
|
|
expect(results).to_not include(secured_category_topic)
|
|
|
|
end
|
2023-05-09 14:30:50 -04:00
|
|
|
|
|
|
|
context "when ai_embeddings_semantic_related_include_closed_topics is false" do
|
|
|
|
before { SiteSetting.ai_embeddings_semantic_related_include_closed_topics = false }
|
|
|
|
it "do not return closed topics" do
|
|
|
|
results = described_class.candidates_for(target).to_a
|
|
|
|
expect(results).to_not include(closed_topic)
|
|
|
|
end
|
|
|
|
end
|
2023-03-30 20:04:34 -04:00
|
|
|
end
|
|
|
|
end
|