* Fix typo * Add SMTP configs to Settings::General * Expand Settings's show page * Expand Settings::General's constants * Move smtp_enabled? logic to ApplicationMailer * Apply suggestions from code review Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com> * Add missing descriptions and placeholders * Remove production guard clause * Change delivery_method to a callback * Create Settings::SMTP * Run migration * Move constants * Remove SMTP from Settings::General * Create SMTPSettingsController * Add back guard clause * Change which perform_deliveries configuration to use from * Update config/environments/production.rb * Rename migration to singular * Run migration again * Fix name * Alphabetize and add validation for authentication * Move settings and enabled? logic to Settings::SMTP * Change after_action to before_action * Fix broken spec * Fix broken spec * Create SMTP specs * Provide default for port * Create spec for ApplicationMailer * Fix broken spec * Move smtp_enabled? * Search and replace Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
59 lines
2.2 KiB
Ruby
59 lines
2.2 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
|
|
allow(ForemInstance).to receive(:smtp_enabled?).and_return(true)
|
|
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
|