2023-04-04 10:24:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe DiscourseAi::Summarization::SummaryController do
|
|
|
|
describe "#chat_channel" 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
|
|
|
|
|
|
|
|
context "when the user can see the channel" do
|
|
|
|
before { channel_group.add(user) }
|
|
|
|
|
|
|
|
describe "validating inputs" do
|
|
|
|
it "returns a 404 if there is no chat channel" do
|
|
|
|
post "/discourse-ai/summarization/chat-channel", params: { chat_channel_id: 99, since: 3 }
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a 400 if the since param is invalid" do
|
|
|
|
post "/discourse-ai/summarization/chat-channel",
|
|
|
|
params: {
|
|
|
|
chat_channel_id: chat_channel.id,
|
|
|
|
since: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(400)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a 404 when the module is disabled" do
|
|
|
|
SiteSetting.ai_summarization_enabled = false
|
|
|
|
|
|
|
|
post "/discourse-ai/summarization/chat-channel",
|
|
|
|
params: {
|
|
|
|
chat_channel_id: chat_channel.id,
|
|
|
|
since: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2023-04-04 10:24:09 -04:00
|
|
|
end
|
|
|
|
|
2023-04-06 08:07:31 -04:00
|
|
|
context "when the user can't see the channel" do
|
|
|
|
before { channel_group.remove(user) }
|
2023-04-04 10:24:09 -04:00
|
|
|
|
2023-04-06 08:07:31 -04:00
|
|
|
it "returns a 403 if the user can't see the chat channel" do
|
|
|
|
post "/discourse-ai/summarization/chat-channel",
|
|
|
|
params: {
|
|
|
|
chat_channel_id: chat_channel.id,
|
|
|
|
since: 1,
|
|
|
|
}
|
2023-04-04 10:24:09 -04:00
|
|
|
|
2023-04-06 08:07:31 -04:00
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
2023-04-04 10:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|