Feature: API to get most used labels (#447)
* Add most-used labels API * Filter conversation by labels * Move match_all to any query Co-authored-by: Pranav Raj S <pranavrajs@gmail.com>
This commit is contained in:
@@ -31,4 +31,29 @@ RSpec.describe 'Label API', type: :request do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/labels/most_used' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
get '/api/v1/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/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
|
||||
|
||||
@@ -36,6 +36,18 @@ describe ::ConversationFinder do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with labels' do
|
||||
let(:params) { { labels: ['resolved'] } }
|
||||
|
||||
it 'filter conversations by labels' do
|
||||
conversation = inbox.conversations.first
|
||||
conversation.update_labels('resolved')
|
||||
|
||||
result = conversation_finder.perform
|
||||
expect(result[:conversations].count).to be 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'with pagination' do
|
||||
let(:params) { { status: 'open', assignee_type_id: 0, page: 1 } }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user