Chore: APIs for agent bots (#676)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -138,4 +138,62 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/inboxes/:id/set_agent_bot' do
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:agent_bot) { create(:agent_bot) }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/set_agent_bot"
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:valid_params) { { agent_bot: agent_bot.id } }
|
||||
|
||||
it 'sets the agent bot' do
|
||||
post "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/set_agent_bot",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: valid_params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(inbox.reload.agent_bot.id).to eq agent_bot.id
|
||||
end
|
||||
|
||||
it 'throw error when invalid agent bot id' do
|
||||
post "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/set_agent_bot",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { agent_bot: 0 },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
||||
it 'disconnects the agent bot' do
|
||||
post "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/set_agent_bot",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { agent_bot: nil },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(inbox.reload.agent_bot).to be_falsey
|
||||
end
|
||||
|
||||
it 'will not update agent bot when its an agent' do
|
||||
agent = create(:user, account: account, role: :agent)
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/set_agent_bot",
|
||||
headers: agent.create_new_auth_token,
|
||||
params: valid_params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
17
spec/controllers/api/v1/agent_bots_controller_spec.rb
Normal file
17
spec/controllers/api/v1/agent_bots_controller_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Profile API', type: :request do
|
||||
let!(:agent_bot1) { create(:agent_bot) }
|
||||
let!(:agent_bot2) { create(:agent_bot) }
|
||||
|
||||
describe 'GET /api/v1/agent_bots' do
|
||||
it 'returns all the agent bots in the system' do
|
||||
get '/api/v1/agent_bots',
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(agent_bot1.name)
|
||||
expect(response.body).to include(agent_bot2.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@ RSpec.describe InboxPolicy, type: :policy do
|
||||
let(:agent) { create(:user, account: account) }
|
||||
let(:inbox) { create(:inbox) }
|
||||
|
||||
permissions :create?, :destroy? do
|
||||
permissions :create?, :destroy?, :update?, :set_agent_bot? do
|
||||
context 'when administrator' do
|
||||
it { expect(inbox_policy).to permit(administrator, inbox) }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user