mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
chore: Move agent availability to Account level (#3074)
- Move agent availability to the account level
This commit is contained in:
@@ -94,7 +94,7 @@ RSpec.describe 'Agents API', type: :request do
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
|
||||
it 'modifies an agent' do
|
||||
it 'modifies an agent name' do
|
||||
put "/api/v1/accounts/#{account.id}/agents/#{other_agent.id}",
|
||||
params: params,
|
||||
headers: admin.create_new_auth_token,
|
||||
@@ -103,6 +103,20 @@ RSpec.describe 'Agents API', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(other_agent.reload.name).to eq(params[:name])
|
||||
end
|
||||
|
||||
it 'modifies an agents account user attributes' do
|
||||
put "/api/v1/accounts/#{account.id}/agents/#{other_agent.id}",
|
||||
params: { role: 'administrator', availability: 'busy', auto_offline: false },
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
expect(response_data['role']).to eq('administrator')
|
||||
expect(response_data['availability_status']).to eq('busy')
|
||||
expect(response_data['auto_offline']).to eq(false)
|
||||
expect(other_agent.account_users.first.role).to eq('administrator')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -89,16 +89,6 @@ RSpec.describe 'Profile API', type: :request do
|
||||
expect(agent.avatar.attached?).to eq(true)
|
||||
end
|
||||
|
||||
it 'updates the availability status' do
|
||||
put '/api/v1/profile',
|
||||
params: { profile: { availability: 'offline' } },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(::OnlineStatusTracker.get_status(account.id, agent.id)).to eq('offline')
|
||||
end
|
||||
|
||||
it 'updates the ui settings' do
|
||||
put '/api/v1/profile',
|
||||
params: { profile: { ui_settings: { is_contact_sidebar_open: false } } },
|
||||
@@ -111,4 +101,28 @@ RSpec.describe 'Profile API', type: :request do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/profile/availability' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post '/api/v1/profile/availability'
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:agent) { create(:user, password: 'Test123!', account: account, role: :agent) }
|
||||
|
||||
it 'updates the availability status' do
|
||||
post '/api/v1/profile/availability',
|
||||
params: { profile: { availability: 'busy', account_id: account.id } },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(::OnlineStatusTracker.get_status(account.id, agent.id)).to eq('busy')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user