fix: unassign team activity message (#5969)
This commit is contained in:
@@ -73,7 +73,8 @@ module ActivityMessageHandler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generate_team_change_activity_key
|
def generate_team_change_activity_key
|
||||||
key = team_id ? 'assigned' : 'removed'
|
team = Team.find_by(id: team_id)
|
||||||
|
key = team.present? ? 'assigned' : 'removed'
|
||||||
key += '_with_assignee' if key == 'assigned' && saved_change_to_assignee_id? && assignee
|
key += '_with_assignee' if key == 'assigned' && saved_change_to_assignee_id? && assignee
|
||||||
key
|
key
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ RSpec.describe 'Api::V1::Accounts::BulkActionsController', type: :request do
|
|||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
let(:agent_1) { create(:user, account: account, role: :agent) }
|
let(:agent_1) { create(:user, account: account, role: :agent) }
|
||||||
let(:agent_2) { create(:user, account: account, role: :agent) }
|
let(:agent_2) { create(:user, account: account, role: :agent) }
|
||||||
|
let(:team_1) { create(:team, account: account) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(:conversation, account_id: account.id, status: :open)
|
create(:conversation, account_id: account.id, status: :open, team_id: team_1.id)
|
||||||
create(:conversation, account_id: account.id, status: :open)
|
create(:conversation, account_id: account.id, status: :open, team_id: team_1.id)
|
||||||
create(:conversation, account_id: account.id, status: :open)
|
create(:conversation, account_id: account.id, status: :open)
|
||||||
create(:conversation, account_id: account.id, status: :open)
|
create(:conversation, account_id: account.id, status: :open)
|
||||||
end
|
end
|
||||||
@@ -55,6 +56,44 @@ RSpec.describe 'Api::V1::Accounts::BulkActionsController', type: :request do
|
|||||||
expect(Conversation.first.assignee_id).to be_nil
|
expect(Conversation.first.assignee_id).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'Bulk update conversation team id to none' do
|
||||||
|
params = { type: 'Conversation', fields: { team_id: 0 }, ids: Conversation.first(1).pluck(:display_id) }
|
||||||
|
expect(Conversation.first.team).not_to be_nil
|
||||||
|
|
||||||
|
perform_enqueued_jobs do
|
||||||
|
post "/api/v1/accounts/#{account.id}/bulk_actions",
|
||||||
|
headers: agent.create_new_auth_token,
|
||||||
|
params: params
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Conversation.first.team).to be_nil
|
||||||
|
|
||||||
|
last_activity_message = Conversation.first.messages.activity.last
|
||||||
|
|
||||||
|
expect(last_activity_message.content).to eq("Unassigned from #{team_1.name} by #{agent.name}")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'Bulk update conversation team id to team' do
|
||||||
|
params = { type: 'Conversation', fields: { team_id: team_1.id }, ids: Conversation.last(2).pluck(:display_id) }
|
||||||
|
expect(Conversation.last.team_id).to be_nil
|
||||||
|
|
||||||
|
perform_enqueued_jobs do
|
||||||
|
post "/api/v1/accounts/#{account.id}/bulk_actions",
|
||||||
|
headers: agent.create_new_auth_token,
|
||||||
|
params: params
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Conversation.last.team).to eq(team_1)
|
||||||
|
|
||||||
|
last_activity_message = Conversation.last.messages.activity.last
|
||||||
|
|
||||||
|
expect(last_activity_message.content).to eq("Assigned to #{team_1.name} by #{agent.name}")
|
||||||
|
end
|
||||||
|
|
||||||
it 'Bulk update conversation assignee id' do
|
it 'Bulk update conversation assignee id' do
|
||||||
params = { type: 'Conversation', fields: { assignee_id: agent_1.id }, ids: Conversation.first(3).pluck(:display_id) }
|
params = { type: 'Conversation', fields: { assignee_id: agent_1.id }, ids: Conversation.first(3).pluck(:display_id) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user