fix: Resolve name only if assignee exists during unassignment (#1649)

This commit is contained in:
Pranav Raj S 2021-01-14 14:21:41 +05:30 committed by GitHub
parent dad737021f
commit 75c2a7cb2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -231,7 +231,7 @@ class Conversation < ApplicationRecord
def create_assignee_change(user_name) def create_assignee_change(user_name)
return unless user_name return unless user_name
params = { assignee_name: assignee.name, user_name: user_name }.compact params = { assignee_name: assignee&.name, user_name: user_name }.compact
key = assignee_id ? 'assigned' : 'removed' key = assignee_id ? 'assigned' : 'removed'
key = 'self_assigned' if self_assign? assignee_id key = 'self_assigned' if self_assign? assignee_id
content = I18n.t("conversations.activity.assignee.#{key}", **params) content = I18n.t("conversations.activity.assignee.#{key}", **params)

View file

@ -29,5 +29,25 @@ RSpec.describe 'Conversation Assignment API', type: :request do
expect(conversation.reload.assignee).to eq(agent) expect(conversation.reload.assignee).to eq(agent)
end end
end end
context 'when conversation already has an assignee' do
let(:agent) { create(:user, account: account, role: :agent) }
before do
conversation.update!(assignee: agent)
end
it 'unassigns a user 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,
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(conversation.reload.assignee).to eq(nil)
expect(conversation.messages.last.content).to eq("Conversation unassigned by #{agent.name}")
end
end
end end
end end