2023-06-14 01:21:46 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe Summarization::Base do
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:user)
|
|
|
|
fab!(:group)
|
|
|
|
fab!(:topic)
|
2023-07-12 22:21:51 +08:00
|
|
|
|
|
|
|
let(:plugin) { Plugin::Instance.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add(user)
|
|
|
|
|
2023-08-16 01:16:06 +08:00
|
|
|
strategy = DummyCustomSummarization.new({ summary: "dummy", chunks: [] })
|
2023-07-12 22:21:51 +08:00
|
|
|
plugin.register_summarization_strategy(strategy)
|
|
|
|
SiteSetting.summarization_strategy = strategy.model
|
|
|
|
end
|
|
|
|
|
2023-08-16 01:16:06 +08:00
|
|
|
after { DiscoursePluginRegistry.reset_register!(:summarization_strategies) }
|
|
|
|
|
2023-07-12 22:21:51 +08:00
|
|
|
describe "#can_see_summary?" do
|
|
|
|
context "when the user cannot generate a summary" do
|
|
|
|
before { SiteSetting.custom_summarization_allowed_groups = "" }
|
2023-06-14 01:21:46 +08:00
|
|
|
|
2023-07-12 22:21:51 +08:00
|
|
|
it "returns false" do
|
|
|
|
SiteSetting.custom_summarization_allowed_groups = ""
|
2023-06-14 01:21:46 +08:00
|
|
|
|
2023-07-12 22:21:51 +08:00
|
|
|
expect(described_class.can_see_summary?(topic, user)).to eq(false)
|
|
|
|
end
|
2023-06-14 01:21:46 +08:00
|
|
|
|
2023-07-12 22:21:51 +08:00
|
|
|
it "returns true if there is a cached summary" do
|
|
|
|
SummarySection.create!(
|
|
|
|
target: topic,
|
|
|
|
summarized_text: "test",
|
|
|
|
original_content_sha: "123",
|
|
|
|
algorithm: "test",
|
|
|
|
meta_section_id: nil,
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(described_class.can_see_summary?(topic, user)).to eq(true)
|
|
|
|
end
|
2023-06-14 01:21:46 +08:00
|
|
|
end
|
|
|
|
|
2023-07-12 22:21:51 +08:00
|
|
|
context "when the user can generate a summary" do
|
|
|
|
before { SiteSetting.custom_summarization_allowed_groups = group.id }
|
|
|
|
|
|
|
|
it "returns true if the user group is present in the custom_summarization_allowed_groups_map setting" do
|
|
|
|
expect(described_class.can_see_summary?(topic, user)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when there is no user" do
|
|
|
|
it "returns false for anons" do
|
|
|
|
expect(described_class.can_see_summary?(topic, nil)).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true for anons when there is a cached summary" do
|
|
|
|
SummarySection.create!(
|
|
|
|
target: topic,
|
|
|
|
summarized_text: "test",
|
|
|
|
original_content_sha: "123",
|
|
|
|
algorithm: "test",
|
|
|
|
meta_section_id: nil,
|
|
|
|
)
|
2023-06-14 01:21:46 +08:00
|
|
|
|
2023-07-12 22:21:51 +08:00
|
|
|
expect(described_class.can_see_summary?(topic, nil)).to eq(true)
|
|
|
|
end
|
2023-06-14 01:21:46 +08:00
|
|
|
end
|
2024-04-05 23:12:59 +08:00
|
|
|
|
|
|
|
context "when the topic is a PM" do
|
|
|
|
before { SiteSetting.custom_summarization_allowed_groups = group.id }
|
|
|
|
let(:pm) { Fabricate(:private_message_topic) }
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(described_class.can_see_summary?(pm, user)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2023-06-14 01:21:46 +08:00
|
|
|
end
|
|
|
|
end
|