discourse/plugins/chat/spec/support/examples/channel_access_example.rb

40 lines
1.2 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
RSpec.shared_examples "channel access example" do |verb, endpoint|
endpoint ||= ".json"
context "when channel is not found" do
before { sign_in(Fabricate(:admin)) }
it "returns a 404" do
public_send(verb, "/chat/api/chat_channels/-999#{endpoint}")
expect(response.status).to eq(404)
end
end
context "with anonymous user" do
fab!(:chat_channel) { Fabricate(:category_channel) }
it "returns a 403" do
public_send(verb, "/chat/api/chat_channels/#{chat_channel.id}#{endpoint}")
expect(response.status).to eq(403)
end
end
context "when channel cant be seen by current user" do
fab!(:chatable) { Fabricate(:private_category, group: Fabricate(:group)) }
fab!(:chat_channel) { Fabricate(:category_channel, chatable: chatable) }
fab!(:user) { Fabricate(:user) }
fab!(:membership) do
Fabricate(:user_chat_channel_membership, user: user, chat_channel: chat_channel)
end
before { sign_in(user) }
it "returns a 403" do
public_send(verb, "/chat/api/chat_channels/#{chat_channel.id}#{endpoint}")
expect(response.status).to eq(403)
end
end
end