-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Add script to post report results in a topic regularly
This script is similar to the existing one that schedules report results to to be sent to a PM on a regular basis, but instead takes a topic ID and posts to that. This way people can have report results sent to a public topic regularly too and not have to deal with PM recipients and so on.
- Loading branch information
1 parent
d306466
commit ee727c7
Showing
7 changed files
with
221 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
spec/automation/recurring_data_explorer_result_topic_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe "recurring data explorer result topic" do | ||
fab!(:admin) | ||
|
||
fab!(:user) | ||
fab!(:another_user) { Fabricate(:user) } | ||
fab!(:group_user) { Fabricate(:user) } | ||
fab!(:not_allowed_user) { Fabricate(:user) } | ||
fab!(:topic) | ||
|
||
fab!(:group) { Fabricate(:group, users: [user, another_user]) } | ||
fab!(:another_group) { Fabricate(:group, users: [group_user]) } | ||
|
||
fab!(:automation) do | ||
Fabricate(:automation, script: "recurring_data_explorer_result_topic", trigger: "recurring") | ||
end | ||
fab!(:query) | ||
fab!(:query_group) { Fabricate(:query_group, query: query, group: group) } | ||
fab!(:query_group) { Fabricate(:query_group, query: query, group: another_group) } | ||
|
||
before do | ||
SiteSetting.data_explorer_enabled = true | ||
SiteSetting.discourse_automation_enabled = true | ||
|
||
automation.upsert_field!("query_id", "choices", { value: query.id }) | ||
automation.upsert_field!("topic_id", "text", { value: topic.id }) | ||
automation.upsert_field!( | ||
"query_params", | ||
"key-value", | ||
{ value: [%w[from_days_ago 0], %w[duration_days 15]] }, | ||
) | ||
automation.upsert_field!( | ||
"recurrence", | ||
"period", | ||
{ value: { interval: 1, frequency: "day" } }, | ||
target: "trigger", | ||
) | ||
automation.upsert_field!("start_date", "date_time", { value: 2.minutes.ago }, target: "trigger") | ||
end | ||
|
||
context "when using recurring trigger" do | ||
it "sends the post at recurring date_date" do | ||
freeze_time 1.day.from_now do | ||
expect { Jobs::DiscourseAutomation::Tracker.new.execute }.to change { | ||
topic.reload.posts.count | ||
}.by(1) | ||
|
||
expect(topic.posts.last.raw).to include("Scheduled Report for #{query.name}") | ||
end | ||
end | ||
|
||
it "has appropriate content from the report generator" do | ||
automation.update(last_updated_by_id: admin.id) | ||
automation.trigger! | ||
|
||
expect(topic.reload.posts.last.raw).to include("Query Name:\n#{query.name}") | ||
end | ||
|
||
it "does not create the post if skip_empty" do | ||
automation.upsert_field!("skip_empty", "boolean", { value: true }) | ||
|
||
automation.update(last_updated_by_id: admin.id) | ||
|
||
expect { automation.trigger! }.to_not change { Post.count } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters