2024-04-03 23:20:43 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe "TopicRequiredWords" do
|
|
|
|
fab!(:user)
|
|
|
|
fab!(:topic)
|
|
|
|
fab!(:automation) do
|
|
|
|
Fabricate(
|
|
|
|
:automation,
|
|
|
|
script: DiscourseAutomation::Scripts::TOPIC_REQUIRED_WORDS,
|
|
|
|
trigger: DiscourseAutomation::Triggers::TOPIC,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when updating trigger" do
|
|
|
|
it "updates the custom field" do
|
|
|
|
automation.upsert_field!("restricted_topic", "text", { value: topic.id }, target: "trigger")
|
2024-05-10 23:47:12 +08:00
|
|
|
expect(topic.custom_fields[DiscourseAutomation::AUTOMATION_IDS_CUSTOM_FIELD]).to eq(
|
|
|
|
[automation.id],
|
|
|
|
)
|
2024-04-03 23:20:43 +08:00
|
|
|
|
|
|
|
new_topic = create_topic
|
|
|
|
automation.upsert_field!(
|
|
|
|
"restricted_topic",
|
|
|
|
"text",
|
|
|
|
{ value: new_topic.id },
|
|
|
|
target: "trigger",
|
|
|
|
)
|
2024-05-10 23:47:12 +08:00
|
|
|
expect(new_topic.custom_fields[DiscourseAutomation::AUTOMATION_IDS_CUSTOM_FIELD]).to eq(
|
|
|
|
[automation.id],
|
|
|
|
)
|
2024-04-03 23:20:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|