2019-12-24 10:01:10 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Conversation Label API', type: :request do
|
|
|
|
let(:account) { create(:account) }
|
|
|
|
|
2020-03-09 17:57:10 +00:00
|
|
|
describe 'GET /api/v1/accounts/{account.id}/conversations/<id>/labels' do
|
2019-12-24 10:01:10 +00:00
|
|
|
let(:conversation) { create(:conversation, account: account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
conversation.update_labels('label1, label2')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is an unauthenticated user' do
|
|
|
|
it 'returns unauthorized' do
|
2020-03-09 17:57:10 +00:00
|
|
|
get api_v1_account_conversation_labels_url(account_id: account.id, conversation_id: conversation.display_id)
|
2019-12-24 10:01:10 +00:00
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-11 06:14:31 +00:00
|
|
|
context 'when it is an authenticated user with access to the conversation' do
|
2019-12-24 10:01:10 +00:00
|
|
|
let(:agent) { create(:user, account: account, role: :agent) }
|
|
|
|
|
2021-06-11 06:14:31 +00:00
|
|
|
before do
|
|
|
|
create(:inbox_member, inbox: conversation.inbox, user: agent)
|
|
|
|
end
|
|
|
|
|
2019-12-24 10:01:10 +00:00
|
|
|
it 'returns all the labels for the conversation' do
|
2020-03-09 17:57:10 +00:00
|
|
|
get api_v1_account_conversation_labels_url(account_id: account.id, conversation_id: conversation.display_id),
|
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-03-09 17:57:10 +00:00
|
|
|
describe 'POST /api/v1/accounts/{account.id}/conversations/<id>/labels' do
|
2019-12-24 10:01:10 +00:00
|
|
|
let(:conversation) { create(:conversation, account: account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
conversation.update_labels('label1, label2')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is an unauthenticated user' do
|
|
|
|
it 'returns unauthorized' do
|
2020-03-09 17:57:10 +00:00
|
|
|
post api_v1_account_conversation_labels_url(account_id: account.id, conversation_id: conversation.display_id),
|
2021-01-13 06:45:11 +00:00
|
|
|
params: { labels: %w[label3 label4] },
|
2019-12-24 10:01:10 +00:00
|
|
|
as: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-11 06:14:31 +00:00
|
|
|
context 'when it is an authenticated user with access to the conversation' do
|
2019-12-24 10:01:10 +00:00
|
|
|
let(:agent) { create(:user, account: account, role: :agent) }
|
|
|
|
|
2021-06-11 06:14:31 +00:00
|
|
|
before do
|
|
|
|
conversation.update_labels('label1, label2')
|
|
|
|
create(:inbox_member, inbox: conversation.inbox, user: agent)
|
|
|
|
end
|
|
|
|
|
2019-12-24 10:01:10 +00:00
|
|
|
it 'creates labels for the conversation' do
|
2020-03-09 17:57:10 +00:00
|
|
|
post api_v1_account_conversation_labels_url(account_id: account.id, conversation_id: conversation.display_id),
|
2021-01-13 06:45:11 +00:00
|
|
|
params: { labels: %w[label3 label4] },
|
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('label3')
|
|
|
|
expect(response.body).to include('label4')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|