Fixes: https://linear.app/chatwoot/issue/CW-1365/allow-super-admin-to-delete-an-account Co-authored-by: Sojan Jose <sojan@pepalo.com>
52 lines
1.5 KiB
Ruby
52 lines
1.5 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe 'Super Admin accounts API', type: :request do
|
|
include ActiveJob::TestHelper
|
|
|
|
let!(:super_admin) { create(:super_admin) }
|
|
let!(:account) { create(:account) }
|
|
|
|
describe 'GET /super_admin/accounts' do
|
|
context 'when it is an unauthenticated user' do
|
|
it 'returns unauthorized' do
|
|
get '/super_admin/accounts'
|
|
expect(response).to have_http_status(:redirect)
|
|
end
|
|
end
|
|
|
|
context 'when it is an authenticated user' do
|
|
let!(:account) { create(:account) }
|
|
|
|
it 'shows the list of accounts' do
|
|
sign_in(super_admin, scope: :super_admin)
|
|
get '/super_admin/accounts'
|
|
expect(response).to have_http_status(:success)
|
|
expect(response.body).to include('New account')
|
|
expect(response.body).to include(account.name)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'DELETE /super_admin/accounts/{account_id}' do
|
|
context 'when it is an unauthenticated user' do
|
|
it 'returns unauthorized' do
|
|
delete "/super_admin/accounts/#{account.id}"
|
|
expect(response).to have_http_status(:redirect)
|
|
end
|
|
end
|
|
|
|
context 'when it is an authenticated user' do
|
|
it 'Deletes the account' do
|
|
total_accounts = Account.count
|
|
sign_in(super_admin, scope: :super_admin)
|
|
|
|
perform_enqueued_jobs(only: DeleteObjectJob) do
|
|
delete "/super_admin/accounts/#{account.id}"
|
|
end
|
|
|
|
expect(Account.count).to eq(total_accounts - 1)
|
|
end
|
|
end
|
|
end
|
|
end
|