fix: assignee_changed callback not getting triggered during conversation creation (#9334)
The reload method in our callback was refreshing the object and hence the saved_change_to_assignee_id? Method wasn't working in the following callbacks. This impacted the listeners subscribing to the event `ASSIGNEE_CHANGE`, `TEAM_CHANGE` etc
This commit is contained in:
@@ -21,7 +21,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
|
||||
describe '#perform - SLA misses' do
|
||||
context 'when first response SLA is missed' do
|
||||
before { sla_policy.update(first_response_time_threshold: 1.hour) }
|
||||
before { applied_sla.sla_policy.update(first_response_time_threshold: 1.hour) }
|
||||
|
||||
it 'updates the SLA status to missed and logs a warning' do
|
||||
allow(Rails.logger).to receive(:warn)
|
||||
@@ -42,7 +42,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
|
||||
context 'when next response SLA is missed' do
|
||||
before do
|
||||
sla_policy.update(next_response_time_threshold: 1.hour)
|
||||
applied_sla.sla_policy.update(next_response_time_threshold: 1.hour)
|
||||
conversation.update(first_reply_created_at: 5.hours.ago, waiting_since: 5.hours.ago)
|
||||
end
|
||||
|
||||
@@ -64,7 +64,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
end
|
||||
|
||||
context 'when resolution time SLA is missed' do
|
||||
before { sla_policy.update(resolution_time_threshold: 1.hour) }
|
||||
before { applied_sla.sla_policy.update(resolution_time_threshold: 1.hour) }
|
||||
|
||||
it 'updates the SLA status to missed and logs a warning' do
|
||||
allow(Rails.logger).to receive(:warn)
|
||||
@@ -89,7 +89,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
context 'when resolved conversation with resolution time SLA is missed' do
|
||||
before do
|
||||
conversation.resolved!
|
||||
sla_policy.update(resolution_time_threshold: 1.hour)
|
||||
applied_sla.sla_policy.update(resolution_time_threshold: 1.hour)
|
||||
end
|
||||
|
||||
it 'does not update the SLA status to missed' do
|
||||
@@ -100,7 +100,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
|
||||
context 'when multiple SLAs are missed' do
|
||||
before do
|
||||
sla_policy.update(first_response_time_threshold: 1.hour, next_response_time_threshold: 1.hour, resolution_time_threshold: 1.hour)
|
||||
applied_sla.sla_policy.update(first_response_time_threshold: 1.hour, next_response_time_threshold: 1.hour, resolution_time_threshold: 1.hour)
|
||||
conversation.update(first_reply_created_at: 5.hours.ago, waiting_since: 5.hours.ago)
|
||||
end
|
||||
|
||||
@@ -119,7 +119,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
describe '#perform - SLA hits' do
|
||||
context 'when first response SLA is hit' do
|
||||
before do
|
||||
sla_policy.update(first_response_time_threshold: 6.hours)
|
||||
applied_sla.sla_policy.update(first_response_time_threshold: 6.hours)
|
||||
conversation.update(first_reply_created_at: 30.minutes.ago)
|
||||
end
|
||||
|
||||
@@ -142,7 +142,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
|
||||
context 'when next response SLA is hit' do
|
||||
before do
|
||||
sla_policy.update(next_response_time_threshold: 6.hours)
|
||||
applied_sla.sla_policy.update(next_response_time_threshold: 6.hours)
|
||||
conversation.update(first_reply_created_at: 30.minutes.ago, waiting_since: nil)
|
||||
end
|
||||
|
||||
@@ -164,7 +164,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
|
||||
context 'when resolution time SLA is hit' do
|
||||
before do
|
||||
sla_policy.update(resolution_time_threshold: 8.hours)
|
||||
applied_sla.sla_policy.update(resolution_time_threshold: 8.hours)
|
||||
conversation.resolved!
|
||||
end
|
||||
|
||||
@@ -182,7 +182,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
describe 'SLA evaluation with frt hit, multiple nrt misses and rt miss' do
|
||||
before do
|
||||
# Setup SLA Policy thresholds
|
||||
sla_policy.update(
|
||||
applied_sla.sla_policy.update(
|
||||
first_response_time_threshold: 2.hours, # Hit frt
|
||||
next_response_time_threshold: 1.hour, # Miss nrt multiple times
|
||||
resolution_time_threshold: 4.hours # Miss rt
|
||||
|
||||
26
spec/listeners/participation_listener_spec.rb
Normal file
26
spec/listeners/participation_listener_spec.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
require 'rails_helper'
|
||||
describe ParticipationListener do
|
||||
let(:listener) { described_class.instance }
|
||||
let!(:account) { create(:account) }
|
||||
let!(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:inbox) { create(:inbox, account: account) }
|
||||
let!(:agent) { create(:user, account: account, role: :agent) }
|
||||
let!(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: agent) }
|
||||
|
||||
before do
|
||||
create(:inbox_member, inbox: inbox, user: agent)
|
||||
Current.user = nil
|
||||
Current.account = nil
|
||||
end
|
||||
|
||||
describe '#assignee_changed' do
|
||||
let(:event_name) { :assignee_changed }
|
||||
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation) }
|
||||
|
||||
it 'adds the assignee as a participant to the conversation' do
|
||||
expect(conversation.conversation_participants.map(&:user_id)).not_to include(admin.id)
|
||||
listener.assignee_changed(event)
|
||||
expect(conversation.conversation_participants.map(&:user_id)).to include(agent.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -26,10 +26,6 @@ shared_examples_for 'auto_assignment_handler' do
|
||||
expect(conversation.reload.assignee).to eq(agent)
|
||||
end
|
||||
|
||||
it 'adds assignee to conversation participants' do
|
||||
expect(conversation.conversation_participants.map(&:user)).to include(agent)
|
||||
end
|
||||
|
||||
it 'will not auto assign agent if enable_auto_assignment is false' do
|
||||
inbox.update(enable_auto_assignment: false)
|
||||
|
||||
|
||||
@@ -107,7 +107,11 @@ RSpec.describe Message do
|
||||
end
|
||||
|
||||
describe 'message create event' do
|
||||
let(:conversation) { create(:conversation) }
|
||||
let!(:conversation) { create(:conversation) }
|
||||
|
||||
before do
|
||||
conversation.reload
|
||||
end
|
||||
|
||||
it 'updates the conversation first reply created at if it is the first outgoing message' do
|
||||
expect(conversation.first_reply_created_at).to be_nil
|
||||
|
||||
Reference in New Issue
Block a user