DEV: reorganize the specs in context blocks

This commit is contained in:
Gabriel Grubba 2024-12-19 18:41:57 -03:00
parent 4af5591985
commit 678b645145
No known key found for this signature in database
GPG Key ID: 5FE41764F62D556C
1 changed files with 60 additions and 56 deletions

View File

@ -329,74 +329,78 @@ describe DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED do
expect(list.length).to eq(1)
end
it "should only fire if tag is added if TAGS_ADDED is set" do
automation.upsert_field!(
"trigger_on",
"choices",
{ value: DiscourseAutomation::Triggers::TopicTagsChanged::TriggerOn::TAGS_ADDED },
target: "trigger",
)
context "with TAGS_ADDED set in trigger_on field" do
it "should fire if tag is added" do
automation.upsert_field!(
"trigger_on",
"choices",
{ value: DiscourseAutomation::Triggers::TopicTagsChanged::TriggerOn::TAGS_ADDED },
target: "trigger",
)
topic_0 = Fabricate(:topic, user: user, tags: [])
topic_0 = Fabricate(:topic, user: user, tags: [])
list =
capture_contexts do
DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), [cool_tag.name])
end
list =
capture_contexts do
DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), [cool_tag.name])
end
expect(list.length).to eq(1)
expect(list[0]["kind"]).to eq(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED)
expect(list.length).to eq(1)
expect(list[0]["kind"]).to eq(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED)
end
it "should not fire if tag is removed" do
automation.upsert_field!(
"trigger_on",
"choices",
{ value: DiscourseAutomation::Triggers::TopicTagsChanged::TriggerOn::TAGS_ADDED },
target: "trigger",
)
topic_0 = Fabricate(:topic, user: user, tags: [cool_tag])
list =
capture_contexts { DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), []) }
expect(list.length).to eq(0)
end
end
it "should only fire if tag is removed if TAGS_REMOVED is set" do
automation.upsert_field!(
"trigger_on",
"choices",
{ value: DiscourseAutomation::Triggers::TopicTagsChanged::TriggerOn::TAGS_REMOVED },
target: "trigger",
)
context "with TAGS_REMOVED set in trigger_on field" do
it "should fire if tag is removed" do
automation.upsert_field!(
"trigger_on",
"choices",
{ value: DiscourseAutomation::Triggers::TopicTagsChanged::TriggerOn::TAGS_REMOVED },
target: "trigger",
)
topic_0 = Fabricate(:topic, user: user, tags: [cool_tag])
topic_0 = Fabricate(:topic, user: user, tags: [cool_tag])
list =
capture_contexts { DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), []) }
list =
capture_contexts { DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), []) }
expect(list.length).to eq(1)
expect(list[0]["kind"]).to eq(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED)
end
expect(list.length).to eq(1)
expect(list[0]["kind"]).to eq(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED)
end
it "should not fire if tag is removed and TAGS_ADDED is set" do
automation.upsert_field!(
"trigger_on",
"choices",
{ value: DiscourseAutomation::Triggers::TopicTagsChanged::TriggerOn::TAGS_ADDED },
target: "trigger",
)
it "should not fire if tag is added" do
automation.upsert_field!(
"trigger_on",
"choices",
{ value: DiscourseAutomation::Triggers::TopicTagsChanged::TriggerOn::TAGS_REMOVED },
target: "trigger",
)
topic_0 = Fabricate(:topic, user: user, tags: [cool_tag])
topic_0 = Fabricate(:topic, user: user, tags: [])
list =
capture_contexts { DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), []) }
list =
capture_contexts do
DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), [cool_tag.name])
end
expect(list.length).to eq(0)
end
it "should not fire if tag is added and TAGS_REMOVED is set" do
automation.upsert_field!(
"trigger_on",
"choices",
{ value: DiscourseAutomation::Triggers::TopicTagsChanged::TriggerOn::TAGS_REMOVED },
target: "trigger",
)
topic_0 = Fabricate(:topic, user: user, tags: [])
list =
capture_contexts do
DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), [cool_tag.name])
end
expect(list.length).to eq(0)
expect(list.length).to eq(0)
end
end
end
end