discourse/plugins/automation/spec/triggers/user_removed_from_group_spe...

39 lines
1013 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
describe "UserRemovedFromGroup" do
fab!(:user)
fab!(:group)
fab!(:automation) do
Fabricate(:automation, trigger: DiscourseAutomation::Triggers::USER_REMOVED_FROM_GROUP)
end
before do
SiteSetting.discourse_automation_enabled = true
group.add(user)
end
context "when group is tracked" do
before do
automation.upsert_field!("left_group", "group", { value: group.id }, target: "trigger")
end
it "fires the trigger" do
list = capture_contexts { group.remove(user) }
expect(list.length).to eq(1)
expect(list[0]["kind"]).to eq(DiscourseAutomation::Triggers::USER_REMOVED_FROM_GROUP)
expect(list[0]["user"]).to eq(user)
expect(list[0]["group"]).to eq(group)
expect(list[0]["usernames"]).to eq([user.username])
end
end
context "when group is not tracked" do
it "doesnt fire the trigger" do
list = capture_contexts { group.remove(user) }
expect(list).to eq([])
end
end
end