This updates macros and automations so agents can explicitly remove assigned agents or teams, while keeping the existing `Assign -> None` flow working for backward compatibility. Fixes: #7551 Closes: #7551 ## Why The original macro change exposed unassignment only through `Assign -> None`, which made macros behave differently from automations and left the explicit remove actions inconsistent across the product. This keeps the lower-risk compatibility path and adds the explicit remove actions requested in review. ## What this change does - Adds `Remove Assigned Agent` and `Remove Assigned Team` as explicit actions in macros. - Adds the same explicit remove actions in automations. - Keeps `Assign Agent -> None` and `Assign Team -> None` working for existing behavior and stored payloads. - Preserves backward compatibility for existing macro and automation execution payloads. - Downmerges the latest `develop` and resolves the conflicts while keeping both the new remove actions and current `develop` behavior. ## Validation - Verified both remove actions are available and selectable in the macro editor. - Verified both remove actions are available and selectable in the automation builder. - Applied a disposable macro with `Remove Assigned Agent` and `Remove Assigned Team` on a real conversation and confirmed both fields were cleared. - Applied a disposable macro with `Assign Agent -> None` and `Assign Team -> None` on a real conversation and confirmed both fields were still cleared.
127 lines
4.4 KiB
Ruby
127 lines
4.4 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe ActionService do
|
|
let(:account) { create(:account) }
|
|
|
|
describe '#resolve_conversation' do
|
|
let(:conversation) { create(:conversation) }
|
|
let(:action_service) { described_class.new(conversation) }
|
|
|
|
it 'resolves the conversation' do
|
|
expect(conversation.status).to eq('open')
|
|
action_service.resolve_conversation(nil)
|
|
expect(conversation.reload.status).to eq('resolved')
|
|
end
|
|
end
|
|
|
|
describe '#open_conversation' do
|
|
let(:conversation) { create(:conversation, status: :resolved) }
|
|
let(:action_service) { described_class.new(conversation) }
|
|
|
|
it 'opens the conversation' do
|
|
expect(conversation.status).to eq('resolved')
|
|
action_service.open_conversation(nil)
|
|
expect(conversation.reload.status).to eq('open')
|
|
end
|
|
end
|
|
|
|
describe '#change_priority' do
|
|
let(:conversation) { create(:conversation) }
|
|
let(:action_service) { described_class.new(conversation) }
|
|
|
|
it 'changes the priority of the conversation to medium' do
|
|
action_service.change_priority(['medium'])
|
|
expect(conversation.reload.priority).to eq('medium')
|
|
end
|
|
|
|
it 'changes the priority of the conversation to nil' do
|
|
action_service.change_priority(['nil'])
|
|
expect(conversation.reload.priority).to be_nil
|
|
end
|
|
end
|
|
|
|
describe '#assign_agent' do
|
|
let(:agent) { create(:user, account: account, role: :agent) }
|
|
let(:inbox_member) { create(:inbox_member, inbox: conversation.inbox, user: agent) }
|
|
let(:conversation) { create(:conversation, :with_assignee, account: account) }
|
|
let(:action_service) { described_class.new(conversation) }
|
|
|
|
it 'unassigns the conversation if agent id is nil' do
|
|
action_service.assign_agent(['nil'])
|
|
expect(conversation.reload.assignee).to be_nil
|
|
end
|
|
|
|
context 'when agent is confirmed' do
|
|
it 'assigns the agent to the conversation' do
|
|
inbox_member
|
|
action_service.assign_agent([agent.id])
|
|
expect(conversation.reload.assignee).to eq(agent)
|
|
end
|
|
end
|
|
|
|
context 'when agent is unconfirmed' do
|
|
let(:unconfirmed_agent) { create(:user, account: account, role: :agent, skip_confirmation: false) }
|
|
let(:unconfirmed_inbox_member) { create(:inbox_member, inbox: conversation.inbox, user: unconfirmed_agent) }
|
|
|
|
it 'does not assign unconfirmed agent to the conversation' do
|
|
unconfirmed_inbox_member
|
|
original_assignee = conversation.assignee
|
|
action_service.assign_agent([unconfirmed_agent.id])
|
|
expect(conversation.reload.assignee).to eq(original_assignee)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#assign_team' do
|
|
let(:agent) { create(:user, account: account, role: :agent) }
|
|
let(:inbox_member) { create(:inbox_member, inbox: conversation.inbox, user: agent) }
|
|
let(:team) { create(:team, name: 'ConversationTeam', account: account) }
|
|
let(:conversation) { create(:conversation, :with_team, account: account) }
|
|
let(:action_service) { described_class.new(conversation) }
|
|
|
|
context 'when team_id is not present' do
|
|
it 'unassign the if team_id is "nil"' do
|
|
expect do
|
|
action_service.assign_team(['nil'])
|
|
end.not_to raise_error
|
|
expect(conversation.reload.team).to be_nil
|
|
end
|
|
|
|
it 'unassign the if team_id is 0' do
|
|
expect do
|
|
action_service.assign_team([0])
|
|
end.not_to raise_error
|
|
expect(conversation.reload.team).to be_nil
|
|
end
|
|
end
|
|
|
|
context 'when team_id is present' do
|
|
it 'assign the team if the team is part of the account' do
|
|
original_team = conversation.team
|
|
expect do
|
|
action_service.assign_team([team.id])
|
|
end.to change { conversation.reload.team }.from(original_team)
|
|
end
|
|
|
|
it 'does not assign the team if the team is part of the account' do
|
|
original_team = conversation.team
|
|
invalid_team_id = 999_999_999
|
|
expect do
|
|
action_service.assign_team([invalid_team_id])
|
|
end.not_to change { conversation.reload.team }.from(original_team)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#remove_assigned_agent' do
|
|
let(:conversation) { create(:conversation, :with_assignee, account: account) }
|
|
let(:action_service) { described_class.new(conversation) }
|
|
|
|
it 'unassigns the conversation' do
|
|
expect(conversation.reload.assignee).to be_present
|
|
action_service.remove_assigned_agent(nil)
|
|
expect(conversation.reload.assignee).to be_nil
|
|
end
|
|
end
|
|
end
|