From a35269d275ffc12371cc6273559720bf0221cbce Mon Sep 17 00:00:00 2001 From: "Aswin Dev P.S" Date: Mon, 11 Oct 2021 15:17:30 +0530 Subject: [PATCH] chore: Create conversation API should accept assignee & team (#3166) --- .../api/v1/accounts/conversations_controller.rb | 4 +++- .../v1/accounts/conversations_controller_spec.rb | 14 ++++++++++++++ swagger/paths/application/conversation/index.yml | 6 ++++++ swagger/swagger.json | 8 ++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/accounts/conversations_controller.rb b/app/controllers/api/v1/accounts/conversations_controller.rb index 5e7c7d433..89d48e544 100644 --- a/app/controllers/api/v1/accounts/conversations_controller.rb +++ b/app/controllers/api/v1/accounts/conversations_controller.rb @@ -130,7 +130,9 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro contact_inbox_id: @contact_inbox.id, additional_attributes: additional_attributes, custom_attributes: custom_attributes, - snoozed_until: params[:snoozed_until] + snoozed_until: params[:snoozed_until], + assignee_id: params[:assignee_id], + team_id: params[:team_id] }.merge(status) end diff --git a/spec/controllers/api/v1/accounts/conversations_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations_controller_spec.rb index fdb8e51d5..2918a47d5 100644 --- a/spec/controllers/api/v1/accounts/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations_controller_spec.rb @@ -170,6 +170,7 @@ RSpec.describe 'Conversations 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 'will not create a new conversation if agent does not have access to inbox' do allow(Rails.configuration.dispatcher).to receive(:dispatch) @@ -250,6 +251,19 @@ RSpec.describe 'Conversations API', type: :request do params: { contact_id: contact.id, inbox_id: inbox.id }, as: :json end + + it 'creates a new conversation with assignee and team' do + allow(Rails.configuration.dispatcher).to receive(:dispatch) + post "/api/v1/accounts/#{account.id}/conversations", + headers: agent.create_new_auth_token, + params: { source_id: contact_inbox.source_id, contact_id: contact.id, inbox_id: inbox.id, assignee_id: agent.id, team_id: team.id }, + as: :json + + expect(response).to have_http_status(:success) + response_data = JSON.parse(response.body, symbolize_names: true) + expect(response_data[:meta][:assignee][:name]).to eq(agent.name) + expect(response_data[:meta][:team][:name]).to eq(team.name) + end end end end diff --git a/swagger/paths/application/conversation/index.yml b/swagger/paths/application/conversation/index.yml index 7871908f8..022fe7911 100644 --- a/swagger/paths/application/conversation/index.yml +++ b/swagger/paths/application/conversation/index.yml @@ -73,6 +73,12 @@ post: type: string enum: ['open', 'resolved', 'pending'] description: Specify the conversation whether it's pending, open, closed + assignee_id: + type: string + description: Agent Id for assigning a conversation to an agent + team_id: + type: string + description: Team Id for assigning a conversation to a team responses: 200: diff --git a/swagger/swagger.json b/swagger/swagger.json index 0d8570d99..996f2ad2f 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -1796,6 +1796,14 @@ "pending" ], "description": "Specify the conversation whether it's pending, open, closed" + }, + "assignee_id": { + "type": "string", + "description": "Agent Id for assigning a conversation to an agent" + }, + "team_id": { + "type": "string", + "description": "Team Id for assigning a conversation to a team" } } }