require "rails_helper" RSpec.describe "ChatChannels", type: :request do let(:user) { create(:user) } let(:user_open_inbox) do u = create(:user) u.setting.update(inbox_type: "open") u end let(:user_closed_inbox) { create(:user) } let(:test_subject) { create(:user) } let(:chat_channel) { create(:chat_channel) } let(:invite_channel) { create(:chat_channel, channel_type: "invite_only") } let(:direct_channel) do create(:chat_channel, channel_type: "direct", slug: "hello/#{user.username}") end before do sign_in user chat_channel.add_users([user]) chat_channel.chat_channel_memberships.update(status: "active") end describe "GET /connect" do context "when logged in" do before do get "/connect" end it "has proper content" do expect(response.body).to include("chat-page-wrapper") end end context "when logged in and visiting existing channel" do before do invite_channel.add_users [user] sign_in user get "/connect/#{invite_channel.slug}" end it "has proper content" do expect(response.body).to include("chat-page-wrapper") end end context "when active membership is pending" do before do invite_channel.add_users [user] invite_channel.chat_channel_memberships.last.update(status: "pending") sign_in user get "/connect/#{invite_channel.slug}" end it "have no active channel" do expect(response).not_to(redirect_to(connect_path(invite_channel.slug))) # The slug will be rendered by the mobile runtime banner because the # request is made directly to "/connect/#{invite_channel.slug}", that's # why we can't simply check that the slug isn't included in # `response.body`. We can check using a regex to make sure the channel # doesn't exist within the chat (after chat DOM element appears but also # before the runtime banner starts). expect(response.body).not_to match(/