chore: Add controllers for conversation participants (#6462)
Co-authored-by: Aswin Dev P.S <aswindevps@gmail.com> Co-authored-by: Sojan Jose <sojan@chatwoot.com>
This commit is contained in:
@@ -16,6 +16,7 @@ RSpec.describe AutoAssignment::AgentAssignmentService do
|
||||
end
|
||||
|
||||
before do
|
||||
inbox_members.each { |inbox_member| create(:account_user, account: account, user: inbox_member.user) }
|
||||
allow(::OnlineStatusTracker).to receive(:get_available_users).and_return(online_users)
|
||||
end
|
||||
|
||||
|
||||
@@ -61,5 +61,10 @@ describe Messages::MentionService do
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
end
|
||||
|
||||
it 'add the users to the participants list' do
|
||||
described_class.new(message: message).perform
|
||||
expect(conversation.conversation_participants.map(&:user_id)).to match_array([first_agent.id, second_agent.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,13 +13,18 @@ describe Messages::NewMessageNotificationService do
|
||||
let(:account) { create(:account) }
|
||||
let(:assignee) { create(:user, account: account) }
|
||||
let(:participating_agent_1) { create(:user, account: account) }
|
||||
let(:participating_agent_2) { create(:user, account: account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: assignee) }
|
||||
let(:builder) { double }
|
||||
|
||||
before do
|
||||
create(:inbox_member, inbox: inbox, user: participating_agent_1)
|
||||
create(:inbox_member, inbox: inbox, user: participating_agent_2)
|
||||
create(:inbox_member, inbox: inbox, user: assignee)
|
||||
create(:conversation_participant, conversation: conversation, user: participating_agent_1)
|
||||
create(:conversation_participant, conversation: conversation, user: participating_agent_2)
|
||||
create(:conversation_participant, conversation: conversation, user: assignee)
|
||||
allow(NotificationBuilder).to receive(:new).and_return(builder)
|
||||
allow(builder).to receive(:perform)
|
||||
end
|
||||
@@ -31,12 +36,26 @@ describe Messages::NewMessageNotificationService do
|
||||
described_class.new(message: message).perform
|
||||
end
|
||||
|
||||
it 'creates notifications for other participating users' do
|
||||
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'participating_conversation_new_message',
|
||||
user: participating_agent_2,
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
end
|
||||
|
||||
it 'creates notifications for assignee' do
|
||||
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'assigned_conversation_new_message',
|
||||
user: assignee,
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
end
|
||||
|
||||
it 'will not create notifications for the user who created the message' do
|
||||
expect(NotificationBuilder).not_to have_received(:new).with(notification_type: 'participating_conversation_new_message',
|
||||
user: participating_agent_1,
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when message is created by a contact' do
|
||||
@@ -52,6 +71,34 @@ describe Messages::NewMessageNotificationService do
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
end
|
||||
|
||||
it 'creates notifications for all participating users' do
|
||||
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'participating_conversation_new_message',
|
||||
user: participating_agent_1,
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'participating_conversation_new_message',
|
||||
user: participating_agent_2,
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with multiple notifications are subscribed' do
|
||||
let(:message) { create(:message, conversation: conversation, account: account) }
|
||||
|
||||
before do
|
||||
assignee.notification_settings.find_by(account_id: account.id).update(selected_email_flags: %w[email_assigned_conversation_new_message
|
||||
email_participating_conversation_new_message])
|
||||
described_class.new(message: message).perform
|
||||
end
|
||||
|
||||
it 'will not create assignee notifications for the assignee if participating notification was send' do
|
||||
expect(NotificationBuilder).not_to have_received(:new).with(notification_type: 'assigned_conversation_new_message',
|
||||
user: assignee,
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when message is created by assignee' do
|
||||
@@ -62,6 +109,10 @@ describe Messages::NewMessageNotificationService do
|
||||
end
|
||||
|
||||
it 'will not create notifications for the user who created the message' do
|
||||
expect(NotificationBuilder).not_to have_received(:new).with(notification_type: 'participating_conversation_new_message',
|
||||
user: assignee,
|
||||
account: account,
|
||||
primary_actor: message)
|
||||
expect(NotificationBuilder).not_to have_received(:new).with(notification_type: 'assigned_conversation_new_message',
|
||||
user: assignee,
|
||||
account: account,
|
||||
|
||||
Reference in New Issue
Block a user