chore: add particpants when assigned

This commit is contained in:
Sojan 2022-12-05 19:49:22 +03:00
parent 82bf1b5316
commit 0b5974da2a
2 changed files with 15 additions and 1 deletions

View file

@ -4,7 +4,7 @@ module AssignmentHandler
included do
before_save :ensure_assignee_is_from_team
after_commit :notify_assignment_change, :process_assignment_activities
after_commit :notify_assignment_change, :process_assignment_changes
end
private
@ -36,6 +36,11 @@ module AssignmentHandler
end
end
def process_assignment_changes
process_assignment_activities
process_participant_assignment
end
def process_assignment_activities
user_name = Current.user.name if Current.user.present?
if saved_change_to_team_id?
@ -44,4 +49,9 @@ module AssignmentHandler
create_assignee_change_activity(user_name)
end
end
def process_participant_assignment
return unless saved_change_to_assignee_id? && assignee_id.present?
self.conversation_participants.find_or_create_by!(user_id: assignee_id)
end
end

View file

@ -85,6 +85,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