mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 17:53:23 +08:00
0a5f548635
As part of this move, we are also renaming `discourse-chat` to `chat`.
53 lines
1.8 KiB
Ruby
53 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
require "rails_helper"
|
||
|
||
describe Jobs::ProcessChatMessage do
|
||
fab!(:chat_message) { Fabricate(:chat_message, message: "https://discourse.org/team") }
|
||
|
||
it "updates cooked with oneboxes" do
|
||
stub_request(:get, "https://discourse.org/team").to_return(
|
||
status: 200,
|
||
body: "<html><head><title>a</title></head></html>",
|
||
)
|
||
|
||
stub_request(:head, "https://discourse.org/team").to_return(status: 200)
|
||
|
||
described_class.new.execute(chat_message_id: chat_message.id)
|
||
expect(chat_message.reload.cooked).to eq(
|
||
"<p><a href=\"https://discourse.org/team\" class=\"onebox\" target=\"_blank\" rel=\"noopener nofollow ugc\">https://discourse.org/team</a></p>",
|
||
)
|
||
end
|
||
|
||
context "when is_dirty args is true" do
|
||
fab!(:chat_message) { Fabricate(:chat_message, message: "a very lovely cat") }
|
||
|
||
it "publishes the update" do
|
||
ChatPublisher.expects(:publish_processed!).once
|
||
described_class.new.execute(chat_message_id: chat_message.id, is_dirty: true)
|
||
end
|
||
end
|
||
|
||
context "when is_dirty args is not true" do
|
||
fab!(:chat_message) { Fabricate(:chat_message, message: "a very lovely cat") }
|
||
|
||
it "doesn’t publish the update" do
|
||
ChatPublisher.expects(:publish_processed!).never
|
||
described_class.new.execute(chat_message_id: chat_message.id)
|
||
end
|
||
|
||
context "when the cooked message changed" do
|
||
it "publishes the update" do
|
||
chat_message.update!(cooked: "another lovely cat")
|
||
ChatPublisher.expects(:publish_processed!).once
|
||
described_class.new.execute(chat_message_id: chat_message.id)
|
||
end
|
||
end
|
||
end
|
||
|
||
it "does not error when message is deleted" do
|
||
chat_message.destroy
|
||
expect { described_class.new.execute(chat_message_id: chat_message.id) }.not_to raise_exception
|
||
end
|
||
end
|