mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 12:03:41 +08:00
384a8b17a1
In other kind of channels we will only unfollow but for group channels we don't want people to keep appearing in members list. This commit also creates appropriate services: - `Chat::LeaveChannel` - `Chat::UnfollowChannel` And dedicated endpoint for unfollow: `DELETE /chat/api/channels/:id/memberships/me/follows`
48 lines
1.3 KiB
Ruby
48 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Chat::UnfollowChannel 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) }
|
|
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
|
|
let(:guardian) { Guardian.new(current_user) }
|
|
let(:channel_id) { channel_1.id }
|
|
|
|
before { SiteSetting.direct_message_enabled_groups = Group::AUTO_GROUPS[:everyone] }
|
|
|
|
let(:params) { { guardian: guardian, channel_id: channel_id } }
|
|
|
|
context "when all steps pass" do
|
|
context "with existing membership" do
|
|
before { channel_1.add(current_user) }
|
|
|
|
it "unfollows the channel" do
|
|
membership = channel_1.membership_for(current_user)
|
|
|
|
expect { result }.to change { membership.reload.following }.from(true).to(false)
|
|
end
|
|
end
|
|
|
|
context "with no existing membership" do
|
|
it "does nothing" do
|
|
expect { result }.to_not change { Chat::UserChatChannelMembership }
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when channel is not found" do
|
|
before { params[:channel_id] = -999 }
|
|
|
|
it { is_expected.to fail_to_find_a_model(:channel) }
|
|
end
|
|
end
|
|
end
|