2023-02-24 11:25:02 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
require_relative "../../../support/toxicity_inference_stubs"
|
|
|
|
|
|
|
|
describe DiscourseAI::Toxicity::ToxicityClassification do
|
2023-02-27 14:21:40 -05:00
|
|
|
fab!(:target) { Fabricate(:post) }
|
2023-02-24 11:25:02 -05:00
|
|
|
|
2023-02-27 14:21:40 -05:00
|
|
|
describe "#request" do
|
2023-02-24 11:25:02 -05:00
|
|
|
it "returns the classification and the model used for it" do
|
|
|
|
ToxicityInferenceStubs.stub_post_classification(target, toxic: false)
|
|
|
|
|
|
|
|
result = subject.request(target)
|
|
|
|
|
|
|
|
expect(result[SiteSetting.ai_toxicity_inference_service_api_model]).to eq(
|
|
|
|
ToxicityInferenceStubs.civilized_response,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#should_flag_based_on?" do
|
|
|
|
before { SiteSetting.ai_toxicity_flag_automatically = true }
|
|
|
|
|
2023-03-07 13:39:28 -05:00
|
|
|
let(:toxic_verdict) { { SiteSetting.ai_toxicity_inference_service_api_model => true } }
|
2023-02-24 11:25:02 -05:00
|
|
|
|
|
|
|
it "returns false when toxicity flaggin is disabled" do
|
|
|
|
SiteSetting.ai_toxicity_flag_automatically = false
|
|
|
|
|
2023-03-07 13:39:28 -05:00
|
|
|
should_flag = subject.should_flag_based_on?(toxic_verdict)
|
2023-02-24 11:25:02 -05:00
|
|
|
|
|
|
|
expect(should_flag).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true if the response is toxic based on our thresholds" do
|
2023-03-07 13:39:28 -05:00
|
|
|
should_flag = subject.should_flag_based_on?(toxic_verdict)
|
2023-02-24 11:25:02 -05:00
|
|
|
|
|
|
|
expect(should_flag).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if the response is civilized based on our thresholds" do
|
2023-03-07 13:39:28 -05:00
|
|
|
civilized_verdict = { SiteSetting.ai_toxicity_inference_service_api_model => false }
|
2023-02-24 11:25:02 -05:00
|
|
|
|
2023-03-07 13:39:28 -05:00
|
|
|
should_flag = subject.should_flag_based_on?(civilized_verdict)
|
2023-02-24 11:25:02 -05:00
|
|
|
|
|
|
|
expect(should_flag).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|