discourse/spec/jobs/send_system_message_spec.rb

39 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe Jobs::SendSystemMessage do
2013-02-05 13:16:51 -06:00
it "raises an error without a user_id" do
expect { Jobs::SendSystemMessage.new.execute(message_type: "welcome_invite") }.to raise_error(
Discourse::InvalidParameters,
)
2013-02-05 13:16:51 -06:00
end
it "raises an error without a message_type" do
expect { Jobs::SendSystemMessage.new.execute(user_id: 1234) }.to raise_error(
Discourse::InvalidParameters,
)
2013-02-05 13:16:51 -06:00
end
context "with valid parameters" do
fab!(:user) { Fabricate(:user) }
2013-02-05 13:16:51 -06:00
2013-02-25 10:42:20 -06:00
it "should call SystemMessage.create" do
SystemMessage.any_instance.expects(:create).with("welcome_invite", {})
Jobs::SendSystemMessage.new.execute(user_id: user.id, message_type: "welcome_invite")
2013-02-05 13:16:51 -06:00
end
it "can send message parameters" do
options = {
url: "/t/no-spammers-please/123",
edit_delay: 5,
flag_reason: "Flagged by community",
}
SystemMessage.any_instance.expects(:create).with("post_hidden", options)
Jobs::SendSystemMessage.new.execute(
user_id: user.id,
message_type: "post_hidden",
message_options: options,
)
end
2013-02-05 13:16:51 -06:00
end
end