feat: add assignee check before composing conversation
This commit is contained in:
@@ -31,8 +31,11 @@ class NotificationListener < BaseListener
|
||||
conversation, account = extract_conversation_and_account(event)
|
||||
assignee = conversation.assignee
|
||||
return if event.data[:notifiable_assignee_change].blank?
|
||||
|
||||
return if conversation.pending?
|
||||
|
||||
return if assignee.blank?
|
||||
|
||||
NotificationBuilder.new(
|
||||
notification_type: 'conversation_assignment',
|
||||
user: assignee,
|
||||
|
||||
@@ -155,4 +155,53 @@ describe NotificationListener do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'assignee_changed' do
|
||||
let(:event_name) { :'conversation.assignee_changed' }
|
||||
|
||||
context 'when assignee is changed' do
|
||||
it 'creates notifications for inbox members who have notifications turned on' do
|
||||
notification_setting = first_agent.notification_settings.first
|
||||
notification_setting.selected_email_flags = [:email_conversation_assignment]
|
||||
notification_setting.selected_push_flags = []
|
||||
notification_setting.save!
|
||||
|
||||
create(:inbox_member, user: first_agent, inbox: inbox)
|
||||
conversation.reload
|
||||
|
||||
event = Events::Base.new(event_name, Time.zone.now, conversation: conversation, notifiable_assignee_change: true)
|
||||
|
||||
listener.assignee_changed(event)
|
||||
expect(user.notifications.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'does not create notification for inbox members who have notifications turned off' do
|
||||
notification_setting = agent_with_out_notification.notification_settings.first
|
||||
notification_setting.unselect_all_email_flags
|
||||
notification_setting.unselect_all_push_flags
|
||||
notification_setting.save!
|
||||
|
||||
create(:inbox_member, user: agent_with_out_notification, inbox: inbox)
|
||||
conversation.reload
|
||||
|
||||
event = Events::Base.new(event_name, Time.zone.now, conversation: conversation)
|
||||
|
||||
listener.assignee_changed(event)
|
||||
expect(notification_setting.user.notifications.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'does not create notification when assignee is nil' do
|
||||
create(:inbox_member, user: first_agent, inbox: inbox)
|
||||
conversation.reload
|
||||
|
||||
conversation.assignee = nil
|
||||
conversation.save!
|
||||
|
||||
event = Events::Base.new(event_name, Time.zone.now, conversation: conversation, notifiable_assignee_change: true, assignee: nil)
|
||||
|
||||
listener.assignee_changed(event)
|
||||
expect(user.notifications.count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user