Merge branch 'feature/cw-7513' into feature/cw-7513-specs

This commit is contained in:
Tanmay Deep Sharma
2026-07-15 12:42:54 +05:30
117 changed files with 8802 additions and 151 deletions
@@ -15,7 +15,7 @@ RSpec.describe 'Agent Bot API', type: :request do
end
end
context 'when it is an authenticated user' do
context 'when it is an authenticated agent' do
it 'returns all the agent_bots in account along with global agent bots' do
global_bot = create(:agent_bot)
get "/api/v1/accounts/#{account.id}/agent_bots",
@@ -25,7 +25,7 @@ RSpec.describe 'Agent Bot API', type: :request do
expect(response).to have_http_status(:success)
expect(response.body).to include(agent_bot.name)
expect(response.body).to include(global_bot.name)
expect(response.body).to include(agent_bot.access_token.token)
expect(response.body).not_to include(agent_bot.access_token.token)
expect(response.body).not_to include(global_bot.access_token.token)
end
@@ -54,6 +54,17 @@ RSpec.describe 'Agent Bot API', type: :request do
expect(account_bot_response).to include('thumbnail')
end
end
context 'when it is an authenticated administrator' do
it 'returns the account bot access token' do
get "/api/v1/accounts/#{account.id}/agent_bots",
headers: admin.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(response.body).to include(agent_bot.access_token.token)
end
end
end
describe 'GET /api/v1/accounts/{account.id}/agent_bots/:id' do
@@ -65,7 +76,7 @@ RSpec.describe 'Agent Bot API', type: :request do
end
end
context 'when it is an authenticated user' do
context 'when it is an authenticated agent' do
it 'shows the agent bot' do
get "/api/v1/accounts/#{account.id}/agent_bots/#{agent_bot.id}",
headers: agent.create_new_auth_token,
@@ -73,7 +84,7 @@ RSpec.describe 'Agent Bot API', type: :request do
expect(response).to have_http_status(:success)
expect(response.body).to include(agent_bot.name)
expect(response.body).to include(agent_bot.access_token.token)
expect(response.body).not_to include(agent_bot.access_token.token)
end
it 'will show a global agent bot' do
@@ -91,6 +102,17 @@ RSpec.describe 'Agent Bot API', type: :request do
expect(response.parsed_body).not_to include('outgoing_url')
end
end
context 'when it is an authenticated administrator' do
it 'returns the account bot access token' do
get "/api/v1/accounts/#{account.id}/agent_bots/#{agent_bot.id}",
headers: admin.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(response.body).to include(agent_bot.access_token.token)
end
end
end
describe 'POST /api/v1/accounts/{account.id}/agent_bots' do
@@ -70,8 +70,8 @@ RSpec.describe 'DashboardAppsController', type: :request do
end
end
context 'when it is an authenticated user' do
let(:user) { create(:user, account: account) }
context 'when it is an authenticated administrator' do
let(:user) { create(:user, account: account, role: :administrator) }
it 'creates the dashboard app' do
expect do
@@ -130,11 +130,26 @@ RSpec.describe 'DashboardAppsController', type: :request do
expect(response).to have_http_status(:unprocessable_entity)
end
end
context 'when it is an authenticated agent' do
let(:agent) { create(:user, account: account, role: :agent) }
it 'does not create account-wide dashboard apps' do
expect do
post "/api/v1/accounts/#{account.id}/dashboard_apps",
headers: agent.create_new_auth_token,
params: payload,
as: :json
end.not_to change(DashboardApp, :count)
expect(response).to have_http_status(:unauthorized)
end
end
end
describe 'PATCH /api/v1/accounts/{account.id}/dashboard_apps/:id' do
let(:payload) { { dashboard_app: { title: 'CRM Dashboard', content: [{ type: 'frame', url: 'https://link.com' }] } } }
let(:user) { create(:user, account: account) }
let(:user) { create(:user, account: account, role: :administrator) }
let!(:dashboard_app) { create(:dashboard_app, user: user, account: account) }
context 'when it is an unauthenticated user' do
@@ -160,10 +175,24 @@ RSpec.describe 'DashboardAppsController', type: :request do
expect(json_response['content'][0]['type']).to eq payload[:dashboard_app][:content][0][:type]
end
end
context 'when it is an authenticated agent' do
let(:agent) { create(:user, account: account, role: :agent) }
it 'does not update account-wide dashboard apps' do
patch "/api/v1/accounts/#{account.id}/dashboard_apps/#{dashboard_app.id}",
headers: agent.create_new_auth_token,
params: payload,
as: :json
expect(response).to have_http_status(:unauthorized)
expect(dashboard_app.reload.title).not_to eq('CRM Dashboard')
end
end
end
describe 'DELETE /api/v1/accounts/{account.id}/dashboard_apps/:id' do
let(:user) { create(:user, account: account) }
let(:user) { create(:user, account: account, role: :administrator) }
let!(:dashboard_app) { create(:dashboard_app, user: user, account: account) }
context 'when it is an unauthenticated user' do
@@ -182,5 +211,18 @@ RSpec.describe 'DashboardAppsController', type: :request do
expect(user.dashboard_apps.count).to be 0
end
end
context 'when it is an authenticated agent' do
let(:agent) { create(:user, account: account, role: :agent) }
it 'does not delete account-wide dashboard apps' do
delete "/api/v1/accounts/#{account.id}/dashboard_apps/#{dashboard_app.id}",
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:unauthorized)
expect(DashboardApp.exists?(dashboard_app.id)).to be(true)
end
end
end
end