2023-04-04 10:24:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe DiscourseAi::Summarization::SummaryController do
|
2023-04-19 16:57:31 -04:00
|
|
|
describe "#show" do
|
2023-04-06 08:07:31 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
let!(:channel_group) { Fabricate(:group) }
|
|
|
|
let!(:chat_channel) { Fabricate(:private_category_channel, group: channel_group) }
|
2023-04-04 10:24:09 -04:00
|
|
|
|
2023-04-06 08:07:31 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.ai_summarization_enabled = true
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
context "when summarizing a chat channel" do
|
|
|
|
context "if the user can see the channel" do
|
|
|
|
before { channel_group.add(user) }
|
2023-04-06 08:07:31 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
describe "validating inputs" do
|
|
|
|
it "returns a 404 if there is no chat channel" do
|
|
|
|
post "/discourse-ai/summarization/summary",
|
|
|
|
params: {
|
|
|
|
target_type: "chat_channel",
|
|
|
|
target_id: 99,
|
|
|
|
since: 3,
|
|
|
|
}
|
2023-04-06 08:07:31 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2023-04-06 08:07:31 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
it "returns a 400 if the since param is invalid" do
|
|
|
|
post "/discourse-ai/summarization/summary",
|
|
|
|
params: {
|
|
|
|
target_type: "chat_channel",
|
|
|
|
target_id: chat_channel.id,
|
|
|
|
since: 0,
|
|
|
|
}
|
2023-04-06 08:07:31 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
expect(response.status).to eq(400)
|
|
|
|
end
|
2023-04-06 08:07:31 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
it "returns a 404 when the module is disabled" do
|
|
|
|
SiteSetting.ai_summarization_enabled = false
|
2023-04-06 08:07:31 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
post "/discourse-ai/summarization/summary",
|
|
|
|
params: {
|
|
|
|
target_type: "chat_channel",
|
|
|
|
target_id: chat_channel.id,
|
|
|
|
since: 1,
|
|
|
|
}
|
2023-04-06 08:07:31 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2023-04-06 08:07:31 -04:00
|
|
|
end
|
2023-04-04 10:24:09 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
context "if the user can't see the channel" do
|
|
|
|
before { channel_group.remove(user) }
|
2023-04-04 10:24:09 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
it "returns a 403 if the user can't see the chat channel" do
|
|
|
|
post "/discourse-ai/summarization/summary",
|
|
|
|
params: {
|
|
|
|
target_type: "chat_channel",
|
|
|
|
target_id: chat_channel.id,
|
|
|
|
since: 1,
|
|
|
|
}
|
2023-04-04 10:24:09 -04:00
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
2023-04-06 08:07:31 -04:00
|
|
|
end
|
2023-04-04 10:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|