2023-03-23 16:28:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe DiscourseAi::Embeddings::EntryPoint do
|
2023-12-13 22:07:28 -05:00
|
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
2023-03-23 16:28:01 -04:00
|
|
|
|
|
|
|
describe "registering event callbacks" do
|
|
|
|
context "when creating a topic" do
|
|
|
|
let(:creator) do
|
|
|
|
PostCreator.new(
|
|
|
|
user,
|
|
|
|
raw: "this is the new content for my topic",
|
|
|
|
title: "this is my new topic title",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "queues a job on create if embeddings is enabled" do
|
|
|
|
SiteSetting.ai_embeddings_enabled = true
|
|
|
|
|
2024-01-23 20:09:27 -05:00
|
|
|
expect { creator.create }.to change(Jobs::GenerateEmbeddings.jobs, :size).by(1) # topic_created
|
2023-03-23 16:28:01 -04:00
|
|
|
end
|
|
|
|
|
2024-01-23 20:09:27 -05:00
|
|
|
it "queues two jobs on create if embeddings is enabled" do
|
|
|
|
SiteSetting.ai_embeddings_enabled = true
|
|
|
|
|
|
|
|
expect { creator.create }.to change(Jobs::GenerateEmbeddings.jobs, :size).by(1) # topic_created AND post_created
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing if embeddings analysis is disabled" do
|
2023-03-23 16:28:01 -04:00
|
|
|
SiteSetting.ai_embeddings_enabled = false
|
|
|
|
|
|
|
|
expect { creator.create }.not_to change(Jobs::GenerateEmbeddings.jobs, :size)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|