mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +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:
53
plugins/chat/spec/services/chat/start_reply_spec.rb
Normal file
53
plugins/chat/spec/services/chat/start_reply_spec.rb
Normal file
@ -0,0 +1,53 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Chat::StartReply do
|
||||
describe described_class::Contract, type: :model do
|
||||
subject(:contract) { described_class.new }
|
||||
|
||||
it { is_expected.to validate_presence_of :channel_id }
|
||||
end
|
||||
|
||||
describe ".call" do
|
||||
subject(:result) { described_class.call(params:, **dependencies) }
|
||||
|
||||
fab!(:user)
|
||||
fab!(:channel) { Fabricate(:chat_channel, threading_enabled: true) }
|
||||
fab!(:thread) { Fabricate(:chat_thread, channel: channel) }
|
||||
|
||||
let(:guardian) { user.guardian }
|
||||
let(:params) { { channel_id: channel.id, thread_id: thread.id } }
|
||||
let(:dependencies) { { guardian: } }
|
||||
|
||||
before { channel.add(guardian.user) }
|
||||
|
||||
context "when the channel is not found" do
|
||||
before { params[:channel_id] = 999 }
|
||||
|
||||
it { is_expected.to fail_to_find_a_model(:presence_channel) }
|
||||
end
|
||||
|
||||
context "when the thread is not found" do
|
||||
before { params[:thread_id] = 999 }
|
||||
|
||||
it { is_expected.to fail_to_find_a_model(:presence_channel) }
|
||||
end
|
||||
|
||||
it "generates a client id" do
|
||||
expect(result.client_id).to be_present
|
||||
end
|
||||
|
||||
it "joins the presence channel" do
|
||||
expect { result }.to change {
|
||||
PresenceChannel.new("/chat-reply/#{channel.id}/thread/#{thread.id}").count
|
||||
}.by(1)
|
||||
end
|
||||
|
||||
context "when the user is not part of the channel" do
|
||||
fab!(:channel) { Fabricate(:private_category_channel, threading_enabled: true) }
|
||||
|
||||
before { params[:thread_id] = nil }
|
||||
|
||||
it { is_expected.to fail_a_step(:join_chat_reply_presence_channel) }
|
||||
end
|
||||
end
|
||||
end
|
51
plugins/chat/spec/services/chat/stop_reply_spec.rb
Normal file
51
plugins/chat/spec/services/chat/stop_reply_spec.rb
Normal file
@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Chat::StopReply do
|
||||
describe described_class::Contract, type: :model do
|
||||
subject(:contract) { described_class.new }
|
||||
|
||||
it { is_expected.to validate_presence_of :channel_id }
|
||||
it { is_expected.to validate_presence_of :client_id }
|
||||
end
|
||||
|
||||
describe ".call" do
|
||||
subject(:result) { described_class.call(params:, **dependencies) }
|
||||
|
||||
fab!(:user)
|
||||
fab!(:channel) { Fabricate(:chat_channel, threading_enabled: true) }
|
||||
fab!(:thread) { Fabricate(:chat_thread, channel: channel) }
|
||||
fab!(:client_id) do
|
||||
Chat::StartReply.call(
|
||||
params: {
|
||||
channel_id: channel.id,
|
||||
thread_id: thread.id,
|
||||
},
|
||||
guardian: user.guardian,
|
||||
).client_id
|
||||
end
|
||||
|
||||
let(:guardian) { user.guardian }
|
||||
let(:params) { { client_id: client_id, channel_id: channel.id, thread_id: thread.id } }
|
||||
let(:dependencies) { { guardian: } }
|
||||
|
||||
before { channel.add(guardian.user) }
|
||||
|
||||
context "when the channel is not found" do
|
||||
before { params[:channel_id] = 999 }
|
||||
|
||||
it { is_expected.to fail_to_find_a_model(:presence_channel) }
|
||||
end
|
||||
|
||||
context "when the thread is not found" do
|
||||
before { params[:thread_id] = 999 }
|
||||
|
||||
it { is_expected.to fail_to_find_a_model(:presence_channel) }
|
||||
end
|
||||
|
||||
it "leaves the presence channel" do
|
||||
presence_channel = PresenceChannel.new("/chat-reply/#{channel.id}/thread/#{thread.id}")
|
||||
|
||||
expect { result }.to change { presence_channel.count }.by(-1)
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user