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:
Pranav Raj S
2023-02-15 16:33:31 -08:00
committed by GitHub
parent 949ddf68ba
commit 7044eda281
34 changed files with 546 additions and 63 deletions

View File

@@ -73,6 +73,10 @@ shared_examples_for 'assignment_handler' do
end
let(:assignment_mailer) { instance_double(AgentNotifications::ConversationNotificationsMailer, deliver: true) }
before do
create(:inbox_member, user: agent, inbox: conversation.inbox)
end
it 'assigns the agent to conversation' do
expect(update_assignee).to be(true)
expect(conversation.reload.assignee).to eq(agent)
@@ -85,6 +89,10 @@ shared_examples_for 'assignment_handler' do
expect(update_assignee).to be(true)
end
it 'adds assignee to conversation participants' do
expect { update_assignee }.to change { conversation.conversation_participants.count }.by(1)
end
context 'when agent is current user' do
before do
Current.user = agent

View File

@@ -0,0 +1,32 @@
require 'rails_helper'
RSpec.describe ConversationParticipant, type: :model do
context 'with validations' do
it { is_expected.to validate_presence_of(:account_id) }
it { is_expected.to validate_presence_of(:conversation_id) }
it { is_expected.to validate_presence_of(:user_id) }
end
describe 'associations' do
it { is_expected.to belong_to(:account) }
it { is_expected.to belong_to(:conversation) }
it { is_expected.to belong_to(:user) }
end
describe 'validations' do
it 'ensure account is present' do
conversation = create(:conversation)
conversation_participant = build(:conversation_participant, conversation: conversation, account_id: nil)
conversation_participant.valid?
expect(conversation_participant.account_id).to eq(conversation.account_id)
end
it 'throws error if inbox member does not belongs to account' do
conversation = create(:conversation)
user = create(:user, account: conversation.account)
participant = build(:conversation_participant, user: user, conversation: conversation)
expect { participant.save! }.to raise_error(ActiveRecord::RecordInvalid)
expect(participant.errors.messages[:user]).to eq(['must have inbox access'])
end
end
end

View File

@@ -105,6 +105,8 @@ RSpec.describe Conversation, type: :model do
let(:label) { create(:label, account: account) }
before do
create(:inbox_member, user: old_assignee, inbox: conversation.inbox)
create(:inbox_member, user: new_assignee, inbox: conversation.inbox)
allow(Rails.configuration.dispatcher).to receive(:dispatch)
Current.user = old_assignee
end

View File

@@ -51,6 +51,14 @@ RSpec.describe Notification do
expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} "
end
it 'returns appropriate title suited for the notification type participating_conversation_new_message' do
message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2))
notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: message)
expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} \
#{message.content.truncate_words(10)}"
end
it 'returns appropriate title suited for the notification type conversation_mention' do
message = create(:message, sender: create(:user), content: 'Hey [@John](mention://user/1/john), can you check this ticket?')
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message, secondary_actor: message.sender)