discourse-ai/spec/requests/sentiment/sentiment_controller_spec.rb

38 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe DiscourseAi::Sentiment::SentimentController do
describe "#posts" do
fab!(:admin)
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:post) { Fabricate(:post, user: admin, topic: topic) }
fab!(:post_2) { Fabricate(:post, user: admin, topic: topic) }
fab!(:classification_result) { Fabricate(:classification_result, target: post) }
before do
SiteSetting.ai_sentiment_enabled = true
sign_in(admin)
end
it "returns a posts based on params" do
post.reload
classification_result.reload
get "/discourse-ai/sentiment/posts",
params: {
group_by: "category",
group_value: category.name,
threshold: 0.0,
}
expect(response).to be_successful
posts = JSON.parse(response.body)
posts.each do |post|
expect(post).to have_key("sentiment")
expect(post["sentiment"]).to match(/positive|negative|neutral/)
end
end
end
end