discourse/plugins/chat/spec/system/invite_users_to_channel_spec.rb
Joffrey JAFFEUX 5fec841c19
FIX: ensures users can open channel invites (#24067)
We were incorrectly generating URLs with message id even when it was not provided, resulting in a route ending with "undefined", which was causing an error.

This commit also uses this opportunity to:
- move `invite_users` into a proper controller inside the API namespace
- refactors the code into a service: `Chat::InviteUsersToChannel`
2023-10-24 18:51:33 +02:00

57 lines
1.5 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Invite users to channel", type: :system do
fab!(:user_1) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:category_channel) }
let(:user_menu) { PageObjects::Components::UserMenu.new }
let(:chat_drawer_page) { PageObjects::Pages::ChatDrawer.new }
before do
chat_system_bootstrap
channel_1.add(user_1)
sign_in(user_1)
end
context "when user clicks the invitation" do
context "when the invitation is linking to a channel" do
before do
Chat::InviteUsersToChannel.call(
channel_id: channel_1.id,
user_ids: [user_1.id],
guardian: Guardian.new(Fabricate(:admin)),
)
end
it "loads the channel" do
visit("/")
user_menu.open
find("[title='#{I18n.t("js.notifications.titles.chat_invitation")}']").click
expect(chat_drawer_page).to have_open_channel(channel_1)
end
end
context "when the invitation is linking to a message" do
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }
before do
Chat::InviteUsersToChannel.call(
channel_id: channel_1.id,
user_ids: [user_1.id],
guardian: Guardian.new(Fabricate(:admin)),
message_id: message_1.id,
)
end
it "loads the channel" do
visit("/")
user_menu.open
find("[title='#{I18n.t("js.notifications.titles.chat_invitation")}']").click
expect(chat_drawer_page).to have_open_channel(channel_1)
end
end
end
end