2019-12-24 10:01:10 +00:00
|
|
|
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
|
|
|
|
|
2020-03-09 17:57:10 +00:00
|
|
|
describe 'GET /api/v1/accounts/{account.id}/labels' do
|
2019-12-24 10:01:10 +00:00
|
|
|
context 'when it is an unauthenticated user' do
|
|
|
|
it 'returns unauthorized' do
|
2020-03-09 17:57:10 +00:00
|
|
|
get "/api/v1/accounts/#{account.id}/labels"
|
2019-12-24 10:01:10 +00:00
|
|
|
|
|
|
|
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
|
2020-03-09 17:57:10 +00:00
|
|
|
get "/api/v1/accounts/#{account.id}/labels",
|
2019-12-24 10:01:10 +00:00
|
|
|
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
|
2020-02-02 10:59:18 +00:00
|
|
|
|
2020-03-09 17:57:10 +00:00
|
|
|
describe 'GET /api/v1/accounts/{account.id}/labels/most_used' do
|
2020-02-02 10:59:18 +00:00
|
|
|
context 'when it is an unauthenticated user' do
|
|
|
|
it 'returns unauthorized' do
|
2020-03-09 17:57:10 +00:00
|
|
|
get "/api/v1/accounts/#{account.id}/labels"
|
2020-02-02 10:59:18 +00:00
|
|
|
|
|
|
|
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
|
2020-03-09 17:57:10 +00:00
|
|
|
get "/api/v1/accounts/#{account.id}/labels/most_used",
|
2020-02-02 10:59:18 +00:00
|
|
|
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
|
2019-12-24 10:01:10 +00:00
|
|
|
end
|