Chatwoot/spec/controllers/api/v1/accounts/labels_controller_spec.rb
Sojan Jose 19ab0fe108
Chore: Scope URLs with account_id (#601)
* Chore: Enable Users to create multiple accounts

Addresses: #402
- migrations to split roles and other attributes from users table
- make changes in code to accommodate this change

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
2020-03-09 23:27:10 +05:30

59 lines
1.8 KiB
Ruby

require 'rails_helper'
RSpec.describe 'Label API', type: :request do
let(:account) { create(:account) }
let(:conversation) { create(:conversation, account: account) }
before do
conversation.update_labels('label1, label2')
end
describe 'GET /api/v1/accounts/{account.id}/labels' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
get "/api/v1/accounts/#{account.id}/labels"
expect(response).to have_http_status(:unauthorized)
end
end
context 'when it is an authenticated user' do
let(:agent) { create(:user, account: account, role: :agent) }
it 'returns all the labels in account' do
get "/api/v1/accounts/#{account.id}/labels",
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(response.body).to include('label1')
expect(response.body).to include('label2')
end
end
end
describe 'GET /api/v1/accounts/{account.id}/labels/most_used' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
get "/api/v1/accounts/#{account.id}/labels"
expect(response).to have_http_status(:unauthorized)
end
end
context 'when it is an authenticated user' do
let(:agent) { create(:user, account: account, role: :agent) }
it 'returns most used labels' do
get "/api/v1/accounts/#{account.id}/labels/most_used",
headers: agent.create_new_auth_token,
params: { count: 1 },
as: :json
expect(response).to have_http_status(:success)
expect(response.body).to include('label1')
expect(response.body).not_to include('label2')
end
end
end
end