From 81b4d7abfc94c5334d0673236d427656ca704d16 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 26 Jun 2026 14:35:28 -0700 Subject: [PATCH] feat: update status on agent bot assignment --- app/services/conversations/assignment_service.rb | 2 ++ .../conversations/assignments_controller_spec.rb | 7 ++++++- spec/services/conversations/assignment_service_spec.rb | 10 ++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/services/conversations/assignment_service.rb b/app/services/conversations/assignment_service.rb index adca34f06..54084fb40 100644 --- a/app/services/conversations/assignment_service.rb +++ b/app/services/conversations/assignment_service.rb @@ -16,6 +16,7 @@ class Conversations::AssignmentService def assign_agent conversation.assignee = assignee conversation.assignee_agent_bot = nil + conversation.status = :open if assignee conversation.save! assignee end @@ -25,6 +26,7 @@ class Conversations::AssignmentService conversation.assignee = nil conversation.assignee_agent_bot = agent_bot + conversation.status = :pending conversation.save! agent_bot end diff --git a/spec/controllers/api/v1/accounts/conversations/assignments_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations/assignments_controller_spec.rb index 18c652c0a..260e1ab46 100644 --- a/spec/controllers/api/v1/accounts/conversations/assignments_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations/assignments_controller_spec.rb @@ -44,6 +44,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do end it 'assigns a user to the conversation' do + conversation.update!(status: :pending) params = { assignee_id: agent.id } post api_v1_account_conversation_assignments_url(account_id: account.id, conversation_id: conversation.display_id), @@ -52,10 +53,13 @@ RSpec.describe 'Conversation Assignment API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.assignee).to eq(agent) + conversation.reload + expect(conversation.assignee).to eq(agent) + expect(conversation.status).to eq('open') end it 'assigns an agent bot to the conversation' do + conversation.update!(status: :open) params = { assignee_id: agent_bot.id, assignee_type: 'AgentBot' } expect(Conversations::AssignmentService).to receive(:new) @@ -72,6 +76,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do conversation.reload expect(conversation.assignee_agent_bot).to eq(agent_bot) expect(conversation.assignee).to be_nil + expect(conversation.status).to eq('pending') end it 'assigns a team to the conversation' do diff --git a/spec/services/conversations/assignment_service_spec.rb b/spec/services/conversations/assignment_service_spec.rb index 899236e1d..0cb3cda7e 100644 --- a/spec/services/conversations/assignment_service_spec.rb +++ b/spec/services/conversations/assignment_service_spec.rb @@ -23,16 +23,17 @@ describe Conversations::AssignmentService do context 'when assigning a user' do before do - conversation.update!(assignee_agent_bot: agent_bot, assignee: nil) + conversation.update!(assignee_agent_bot: agent_bot, assignee: nil, status: :pending) end - it 'sets the agent and clears agent bot' do + it 'sets the agent, clears agent bot and opens the conversation' do result = described_class.new(conversation: conversation, assignee_id: agent.id).perform conversation.reload expect(result).to eq(agent) expect(conversation.assignee_id).to eq(agent.id) expect(conversation.assignee_agent_bot_id).to be_nil + expect(conversation.status).to eq('open') end end @@ -45,8 +46,8 @@ describe Conversations::AssignmentService do ) end - it 'sets the agent bot and clears human assignee' do - conversation.update!(assignee: agent, assignee_agent_bot: nil) + it 'sets the agent bot, clears human assignee and marks the conversation pending' do + conversation.update!(assignee: agent, assignee_agent_bot: nil, status: :open) result = service.perform @@ -54,6 +55,7 @@ describe Conversations::AssignmentService do expect(result).to eq(agent_bot) expect(conversation.assignee_agent_bot_id).to eq(agent_bot.id) expect(conversation.assignee_id).to be_nil + expect(conversation.status).to eq('pending') end end end