mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
DEV: start/stop reply implementation (#29542)
* DEV: join/leave presence chat-reply when streaming This commit ensures that starting/stopping a chat message with the streaming option will automatically make the creator of the message as present in the chat-reply channel. * implements start/stop reply * not needed
This commit is contained in:
@ -38,4 +38,90 @@ describe ChatSDK::Channel do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".start_reply" do
|
||||
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
|
||||
fab!(:thread_1) { Fabricate(:chat_thread, channel: channel_1) }
|
||||
|
||||
let(:params) do
|
||||
{ channel_id: channel_1.id, thread_id: thread_1.id, guardian: Discourse.system_user.guardian }
|
||||
end
|
||||
|
||||
it "starts a reply" do
|
||||
client_id = nil
|
||||
expect { client_id = described_class.start_reply(**params) }.to change {
|
||||
PresenceChannel.new("/chat-reply/#{channel_1.id}/thread/#{thread_1.id}").count
|
||||
}.by(1)
|
||||
|
||||
expect(client_id).to be_present
|
||||
end
|
||||
|
||||
context "when the channel doesn't exist" do
|
||||
it "fails" do
|
||||
params[:channel_id] = -999
|
||||
|
||||
expect { described_class.start_reply(**params) }.to raise_error(
|
||||
"Chat::Channel or Chat::Thread not found.",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the thread doesn't exist" do
|
||||
it "fails" do
|
||||
params[:thread_id] = -999
|
||||
|
||||
expect { described_class.start_reply(**params) }.to raise_error(
|
||||
"Chat::Channel or Chat::Thread not found.",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".stop_reply" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
|
||||
fab!(:thread_1) { Fabricate(:chat_thread, channel: channel_1) }
|
||||
fab!(:client_id) do
|
||||
described_class.start_reply(
|
||||
channel_id: channel_1.id,
|
||||
thread_id: thread_1.id,
|
||||
guardian: user.guardian,
|
||||
)
|
||||
end
|
||||
|
||||
let(:params) do
|
||||
{
|
||||
channel_id: channel_1.id,
|
||||
thread_id: thread_1.id,
|
||||
client_id: client_id,
|
||||
guardian: user.guardian,
|
||||
}
|
||||
end
|
||||
|
||||
it "stops a reply" do
|
||||
expect { described_class.stop_reply(**params) }.to change {
|
||||
PresenceChannel.new("/chat-reply/#{channel_1.id}/thread/#{thread_1.id}").count
|
||||
}.by(-1)
|
||||
end
|
||||
|
||||
context "when the channel doesn't exist" do
|
||||
it "fails" do
|
||||
params[:channel_id] = -999
|
||||
|
||||
expect { described_class.stop_reply(**params) }.to raise_error(
|
||||
"Chat::Channel or Chat::Thread not found.",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the thread doesn't exist" do
|
||||
it "fails" do
|
||||
params[:thread_id] = -999
|
||||
|
||||
expect { described_class.stop_reply(**params) }.to raise_error(
|
||||
"Chat::Channel or Chat::Thread not found.",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user