2023-03-30 18:07:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe ::TopicsController do
|
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
|
|
fab!(:topic1) { Fabricate(:topic) }
|
|
|
|
fab!(:topic2) { Fabricate(:topic) }
|
2023-03-30 20:04:34 -04:00
|
|
|
fab!(:topic3) { Fabricate(:topic) }
|
2023-03-30 18:07:22 -04:00
|
|
|
fab!(:user) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Discourse.cache.clear
|
2023-03-30 20:04:34 -04:00
|
|
|
SiteSetting.ai_embeddings_semantic_related_topics_enabled = true
|
|
|
|
SiteSetting.ai_embeddings_semantic_related_topics = 2
|
2023-03-30 18:07:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after { Discourse.cache.clear }
|
|
|
|
|
|
|
|
context "when a user is logged on" do
|
|
|
|
it "includes related topics in payload when configured" do
|
2023-07-13 11:41:36 -04:00
|
|
|
DiscourseAi::Embeddings::SemanticRelated.expects(:symmetric_semantic_search).returns(
|
|
|
|
[topic1.id, topic2.id, topic3.id],
|
|
|
|
)
|
2023-03-30 20:04:34 -04:00
|
|
|
|
|
|
|
get("#{topic.relative_url}.json")
|
2023-05-23 17:57:52 -04:00
|
|
|
expect(response.status).to eq(200)
|
2023-03-30 20:04:34 -04:00
|
|
|
json = response.parsed_body
|
|
|
|
|
|
|
|
expect(json["suggested_topics"].length).to eq(0)
|
|
|
|
expect(json["related_topics"].length).to eq(2)
|
|
|
|
|
2023-03-30 18:07:22 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get("#{topic.relative_url}.json")
|
|
|
|
json = response.parsed_body
|
|
|
|
|
|
|
|
expect(json["suggested_topics"].length).to eq(0)
|
2023-03-30 20:04:34 -04:00
|
|
|
expect(json["related_topics"].length).to eq(2)
|
2023-03-30 18:07:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|