docbrown/spec/requests/admin/chat_channel_spec.rb
Ridhwana 3a4da2dd5a
RFC 50: Remove hardcoded paths and use path_helpers instead (in the specs) (#13549)
* feat: update the paths in the spec files

* feat: update hardcoded paths with path helpers

* chore: update hardcoded paths to path helpers

* chore: hardcode describe blocks

* chore: oops

* feat: update some more hardcoded to use link_to's

* fix broken tests

* chore: admin_articles path

* chore: oops remove rails helper

* feat: add starting /

* chore: more pre slashes

* chore: add pre slashes

* chore: some small typos

* fix: oops
2021-04-28 21:32:51 +02:00

58 lines
2.1 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin/apps/chat_channels", type: :request do
let(:user) { create(:user) }
let(:chat_channel) { create(:chat_channel) }
describe "POST /admin/apps/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_path,
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 admin/apps/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_channel_path(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/apps/chat_channels/:id/remove_user" 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 remove_user_admin_chat_channel_path(chat_channel.id),
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
describe "DELETE /admin/apps/chat_channels/:id" do
it "deletes the chat channel when it has no users" do
user.add_role(:super_admin)
sign_in user
delete admin_chat_channel_path(chat_channel.id)
expect { ChatChannel.find(chat_channel.id) }.to raise_exception(ActiveRecord::RecordNotFound)
end
end
end