feat: add push notification when SLA missed (#9078)
* feat: add push notification when SLA missed * chore: sent notification only for inbox members * feat: add conv particpants+admins to SLA notification list * chore: add spec to ensure notification is created * chore: refactor to multiple alerts for SLA conditions * chore: add sla_policy as secondary_actor in notification
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
let!(:conversation) { create(:conversation, created_at: 6.hours.ago) }
|
||||
let!(:account) { create(:account) }
|
||||
let!(:user_1) { create(:user, account: account) }
|
||||
let!(:user_2) { create(:user, account: account) }
|
||||
let!(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:conversation) { create(:conversation, created_at: 6.hours.ago, assignee: user_1, account: account) }
|
||||
let!(:sla_policy) do
|
||||
create(:sla_policy, account: conversation.account,
|
||||
first_response_time_threshold: nil,
|
||||
@@ -20,6 +24,16 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
expect(Rails.logger).to have_received(:warn).with("SLA missed for conversation #{conversation.id} in account " \
|
||||
"#{applied_sla.account_id} for sla_policy #{sla_policy.id}")
|
||||
expect(applied_sla.reload.sla_status).to eq('missed')
|
||||
|
||||
expect(Notification.count).to eq(2)
|
||||
# check if notification type is sla_missed_first_response
|
||||
expect(Notification.where(notification_type: 'sla_missed_first_response').count).to eq(2)
|
||||
# Check if notification is created for the assignee
|
||||
expect(Notification.where(user_id: user_1.id).count).to eq(1)
|
||||
# Check if notification is created for the account admin
|
||||
expect(Notification.where(user_id: admin.id).count).to eq(1)
|
||||
# Check if no notification is created for other user
|
||||
expect(Notification.where(user_id: user_2.id).count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,6 +49,16 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
expect(Rails.logger).to have_received(:warn).with("SLA missed for conversation #{conversation.id} in account " \
|
||||
"#{applied_sla.account_id} for sla_policy #{sla_policy.id}")
|
||||
expect(applied_sla.reload.sla_status).to eq('missed')
|
||||
|
||||
expect(Notification.count).to eq(2)
|
||||
# check if notification type is sla_missed_first_response
|
||||
expect(Notification.where(notification_type: 'sla_missed_next_response').count).to eq(2)
|
||||
# Check if notification is created for the assignee
|
||||
expect(Notification.where(user_id: user_1.id).count).to eq(1)
|
||||
# Check if notification is created for the account admin
|
||||
expect(Notification.where(user_id: admin.id).count).to eq(1)
|
||||
# Check if no notification is created for other user
|
||||
expect(Notification.where(user_id: user_2.id).count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,6 +71,15 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
expect(Rails.logger).to have_received(:warn).with("SLA missed for conversation #{conversation.id} in account " \
|
||||
"#{applied_sla.account_id} for sla_policy #{sla_policy.id}")
|
||||
expect(applied_sla.reload.sla_status).to eq('missed')
|
||||
|
||||
expect(Notification.count).to eq(2)
|
||||
expect(Notification.where(notification_type: 'sla_missed_resolution').count).to eq(2)
|
||||
# Check if notification is created for the assignee
|
||||
expect(Notification.where(user_id: user_1.id).count).to eq(1)
|
||||
# Check if notification is created for the account admin
|
||||
expect(Notification.where(user_id: admin.id).count).to eq(1)
|
||||
# Check if no notification is created for other user
|
||||
expect(Notification.where(user_id: user_2.id).count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -76,6 +109,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
expect(Rails.logger).to have_received(:warn).with("SLA missed for conversation #{conversation.id} in account " \
|
||||
"#{applied_sla.account_id} for sla_policy #{sla_policy.id}").exactly(1).time
|
||||
expect(applied_sla.reload.sla_status).to eq('missed')
|
||||
expect(Notification.count).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -99,6 +133,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do
|
||||
expect(Rails.logger).to have_received(:info).with("SLA hit for conversation #{conversation.id} in account " \
|
||||
"#{applied_sla.account_id} for sla_policy #{sla_policy.id}")
|
||||
expect(applied_sla.reload.sla_status).to eq('hit')
|
||||
expect(Notification.count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user