feat: Add team assignment & filter APIs (#1712)

This commit is contained in:
Sojan Jose
2021-01-31 12:40:02 +05:30
committed by GitHub
parent b0563a666e
commit 0ff81e3b53
4 changed files with 70 additions and 5 deletions

View File

@@ -16,6 +16,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do
context 'when it is an authenticated user' do
let(:agent) { create(:user, account: account, role: :agent) }
let(:team) { create(:team, account: account) }
it 'assigns a user to the conversation' do
params = { assignee_id: agent.id }
@@ -28,6 +29,18 @@ RSpec.describe 'Conversation Assignment API', type: :request do
expect(response).to have_http_status(:success)
expect(conversation.reload.assignee).to eq(agent)
end
it 'assigns a team to the conversation' do
params = { team_id: team.id }
post api_v1_account_conversation_assignments_url(account_id: account.id, conversation_id: conversation.display_id),
params: params,
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(conversation.reload.team).to eq(team)
end
end
context 'when conversation already has an assignee' do
@@ -37,7 +50,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do
conversation.update!(assignee: agent)
end
it 'unassigns a user from the conversation' do
it 'unassigns the assignee from the conversation' do
params = { assignee_id: 0 }
post api_v1_account_conversation_assignments_url(account_id: account.id, conversation_id: conversation.display_id),
params: params,
@@ -49,5 +62,25 @@ RSpec.describe 'Conversation Assignment API', type: :request do
expect(conversation.messages.last.content).to eq("Conversation unassigned by #{agent.name}")
end
end
context 'when conversation already has a team' do
let(:agent) { create(:user, account: account, role: :agent) }
let(:team) { create(:team, account: account) }
before do
conversation.update!(team: team)
end
it 'unassigns the team from the conversation' do
params = { team_id: 0 }
post api_v1_account_conversation_assignments_url(account_id: account.id, conversation_id: conversation.display_id),
params: params,
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(conversation.reload.team).to eq(nil)
end
end
end
end

View File

@@ -37,6 +37,17 @@ describe ::ConversationFinder do
end
end
context 'with team' do
let(:team) { create(:team, account: account) }
let(:params) { { team_id: team.id } }
it 'filter conversations by team' do
create(:conversation, account: account, inbox: inbox, team: team)
result = conversation_finder.perform
expect(result[:conversations].count).to be 1
end
end
context 'with labels' do
let(:params) { { labels: ['resolved'] } }