2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::SendSystemMessage do
|
2013-02-06 03:16:51 +08:00
|
|
|
it "raises an error without a user_id" do
|
2014-12-31 22:55:03 +08:00
|
|
|
expect { Jobs::SendSystemMessage.new.execute(message_type: "welcome_invite") }.to raise_error(
|
|
|
|
Discourse::InvalidParameters,
|
|
|
|
)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error without a message_type" do
|
2014-12-31 22:55:03 +08:00
|
|
|
expect { Jobs::SendSystemMessage.new.execute(user_id: 1234) }.to raise_error(
|
|
|
|
Discourse::InvalidParameters,
|
|
|
|
)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid parameters" do
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:user)
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it "should call SystemMessage.create" do
|
2017-09-13 03:43:03 +08:00
|
|
|
SystemMessage.any_instance.expects(:create).with("welcome_invite", {})
|
2013-02-26 00:42:20 +08:00
|
|
|
Jobs::SendSystemMessage.new.execute(user_id: user.id, message_type: "welcome_invite")
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2017-09-13 03:43:03 +08:00
|
|
|
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-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|