docbrown/spec/requests/admin/chat_channel_spec.rb
rhymes cc8bfcb5c0
Enable Rubocop 0.89 cops and fix Lint/ violations (#9709)
* Enable new Lint/ cops and run rubocop -a

* Fixing last remaining things with rubocop -a

* Enable and fix Style/ExplicitBlockArgument and Style/GlobalStdStream

* Forgot parenthesis
2020-08-10 16:57:12 +02:00

48 lines
1.8 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin/chat_channels", type: :request do
let(:user) { create(:user) }
let(:chat_channel) { create(:chat_channel) }
describe "POST /chat_channels" do
around { |example| perform_enqueued_jobs(&example) }
it "creates chat_channel for with users as moderator" do
user.add_role(:super_admin)
sign_in user
expect do
post "/admin/chat_channels",
params: { chat_channel: { channel_name: "Hello Channel", usernames_string: user.username } },
headers: { HTTP_ACCEPT: "application/json" }
end.to change(ActionMailer::Base.deliveries, :length)
expect(ChatChannel.last.channel_name).to eq("Hello Channel")
expect(ChatChannel.last.pending_users).to include(user)
end
end
describe "PATCH /chat_channels" do
it "adds the user as a member to the chat channel" do
user.add_role(:super_admin)
second_user = create(:user)
sign_in user
patch "/admin/chat_channels/#{chat_channel.id}",
params: { chat_channel: { usernames_string: second_user.username } },
headers: { HTTP_ACCEPT: "application/json" }
expect(second_user.chat_channel_memberships.last).not_to be_blank
expect(second_user.chat_channel_memberships.last.role).to eq "member"
end
end
describe "DELETE /admin/chat_channels/remove_user/:id" do
it "removes the user from the chat channel" do
user.add_role(:super_admin)
sign_in user
chat_channel.invite_users(users: user)
delete "/admin/chat_channels/#{chat_channel.id}/remove_user",
params: { chat_channel: { username_string: user.username } }
expect(user.chat_channel_memberships.count).to eq 0
expect(chat_channel.users.count).to eq 0
end
end
end