From 005e80f74da5339da4ef004d5c26adde251a09ab Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 30 May 2025 11:32:03 -0700 Subject: [PATCH 1/2] FIX: Exporting overall sentiment fails --- lib/sentiment/sentiment_dashboard_report.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/sentiment/sentiment_dashboard_report.rb b/lib/sentiment/sentiment_dashboard_report.rb index 19d04eb0c..124e14b8b 100644 --- a/lib/sentiment/sentiment_dashboard_report.rb +++ b/lib/sentiment/sentiment_dashboard_report.rb @@ -42,15 +42,17 @@ def self.register!(plugin) return report if grouped_sentiments.empty? - report.data = { - req: "overall_sentiment", - color: report.colors[:lime], - label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment"), - data: - grouped_sentiments.map do |gs| - { x: gs.posted_at, y: gs.public_send("sentiment_count") } - end, - } + report.data = [ + { + req: "overall_sentiment", + color: report.colors[:lime], + label: I18n.t("discourse_ai.sentiment.reports.overall_sentiment"), + data: + grouped_sentiments.map do |gs| + { x: gs.posted_at, y: gs.public_send("sentiment_count") } + end, + }, + ] end end end From 1cbf9a3c228065630a68193f5df643e734ad7e8a Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 30 May 2025 11:49:48 -0700 Subject: [PATCH 2/2] FIX: and add export spec --- spec/lib/modules/sentiment/entry_point_spec.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/lib/modules/sentiment/entry_point_spec.rb b/spec/lib/modules/sentiment/entry_point_spec.rb index 871ce01e4..3a212063d 100644 --- a/spec/lib/modules/sentiment/entry_point_spec.rb +++ b/spec/lib/modules/sentiment/entry_point_spec.rb @@ -55,9 +55,23 @@ def sentiment_classification(post, classification) sentiment_classification(pm, positive_classification) report = Report.find("overall_sentiment") - overall_sentiment = report.data[:data][0][:y].to_i + overall_sentiment = report.data[0][:data][0][:y].to_i expect(overall_sentiment).to eq(0) end + + it "exports the report without any errors" do + sentiment_classification(post_1, positive_classification) + sentiment_classification(post_2, negative_classification) + sentiment_classification(pm, positive_classification) + + exporter = Jobs::ExportCsvFile.new + exporter.entity = "report" + exporter.extra = HashWithIndifferentAccess.new(name: "overall_sentiment") + exported_csv = [] + exporter.report_export { |entry| exported_csv << entry } + expect(exported_csv[0]).to eq(["Day", "Overall sentiment (Positive - Negative)"]) + expect(exported_csv[1]).to eq([post_1.created_at.to_date.to_s, "0"]) + end end describe "post_emotion report" do