chore: Allow super admin to suspend an account (#5174)

This commit is contained in:
Pranav Raj S
2022-08-03 11:40:03 +05:30
committed by GitHub
parent 4152883f38
commit e0cebfaa1a
20 changed files with 259 additions and 23 deletions

View File

@@ -56,5 +56,17 @@ RSpec.describe 'API Base', type: :request do
expect(conversation.reload.status).to eq('open')
end
end
context 'when the account is suspended' do
it 'returns 401 unauthorized' do
account.update!(status: :suspended)
post "/api/v1/accounts/#{account.id}/canned_responses",
headers: { api_access_token: user.access_token.token },
as: :json
expect(response).to have_http_status(:unauthorized)
end
end
end
end

View File

@@ -47,6 +47,17 @@ RSpec.describe '/api/v1/widget/config', type: :request do
expect(response_data.keys).to include(*response_keys)
expect(response_data['contact']['pubsub_token']).to eq(contact_inbox.pubsub_token)
end
it 'returns 401 if account is suspended' do
account.update!(status: :suspended)
post '/api/v1/widget/config',
params: params,
headers: { 'X-Auth-Token' => token },
as: :json
expect(response).to have_http_status(:unauthorized)
end
end
context 'with correct website token and invalid X-Auth-Token' do

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
describe '/widget', type: :request do
let(:account) { create(:account) }
let(:web_widget) { create(:channel_widget) }
let(:web_widget) { create(:channel_widget, account: account) }
let(:contact) { create(:contact, account: account) }
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
@@ -25,5 +25,13 @@ describe '/widget', type: :request do
get widget_url
expect(response).to have_http_status(:not_found)
end
it 'returns 401 if the account is suspended' do
account.update!(status: :suspended)
get widget_url(website_token: web_widget.website_token)
expect(response).to have_http_status(:unauthorized)
expect(response.body).to include('Account is suspended')
end
end
end

View File

@@ -3,6 +3,7 @@
FactoryBot.define do
factory :account do
sequence(:name) { |n| "Account #{n}" }
status { 'active' }
custom_email_domain_enabled { false }
domain { 'test.com' }
support_email { 'support@test.com' }