2023-02-24 05:53:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-03-14 15:03:50 -04:00
|
|
|
describe DiscourseAi::Toxicity::EntryPoint do
|
2023-12-13 22:07:28 -05:00
|
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
2023-02-24 05:53:43 -05:00
|
|
|
|
|
|
|
describe "registering event callbacks" do
|
|
|
|
before { SiteSetting.ai_toxicity_enabled = true }
|
|
|
|
|
|
|
|
context "when creating a post" 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 post creation" do
|
|
|
|
SiteSetting.ai_toxicity_enabled = true
|
|
|
|
|
|
|
|
expect { creator.create }.to change(Jobs::ToxicityClassifyPost.jobs, :size).by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when editing a post" do
|
|
|
|
fab!(:post) { Fabricate(:post, user: user) }
|
|
|
|
let(:revisor) { PostRevisor.new(post) }
|
|
|
|
|
|
|
|
it "queues a job on post update" do
|
|
|
|
expect { revisor.revise!(user, raw: "This is my new test") }.to change(
|
|
|
|
Jobs::ToxicityClassifyPost.jobs,
|
|
|
|
:size,
|
|
|
|
).by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when creating a chat message" do
|
2023-05-23 10:02:11 -04:00
|
|
|
fab!(:public_chat_channel) { Fabricate(:chat_channel) }
|
2023-02-24 05:53:43 -05:00
|
|
|
|
|
|
|
it "queues a job when creating a chat message" do
|
2023-08-24 10:07:16 -04:00
|
|
|
expect {
|
|
|
|
Fabricate(
|
|
|
|
:chat_message,
|
|
|
|
chat_channel: public_chat_channel,
|
|
|
|
user: user,
|
|
|
|
message: "This is my new test",
|
|
|
|
use_service: true,
|
|
|
|
)
|
|
|
|
}.to change(Jobs::ToxicityClassifyChatMessage.jobs, :size).by(1)
|
2023-02-24 05:53:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-23 05:50:25 -04:00
|
|
|
context "when editing a chat message" do
|
|
|
|
# This fabricator trigger events because it uses the UpdateMessage service.
|
2023-05-23 10:02:11 -04:00
|
|
|
# Using let makes the test fail.
|
|
|
|
fab!(:chat_message) { Fabricate(:chat_message) }
|
2023-02-24 05:53:43 -05:00
|
|
|
let(:updater) do
|
2023-10-23 05:50:25 -04:00
|
|
|
Chat::UpdateMessage.call(
|
2023-12-06 01:26:43 -05:00
|
|
|
guardian: Guardian.new(chat_message.user),
|
2023-10-23 05:50:25 -04:00
|
|
|
message_id: chat_message.id,
|
|
|
|
message: "This is my updated message",
|
2023-02-24 05:53:43 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-05-23 10:02:11 -04:00
|
|
|
it "queues a job on chat message update" do
|
2023-02-24 05:53:43 -05:00
|
|
|
expect { updater.update }.to change(Jobs::ToxicityClassifyChatMessage.jobs, :size).by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|