Skip to content

Commit

Permalink
fix: Migrate notes when merging the contacts (#8749)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavrajs committed Jan 20, 2024
1 parent 8e15ada commit a8f0539
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/actions/contact_merge_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def perform
merge_conversations
merge_messages
merge_contact_inboxes
merge_contact_notes
merge_and_remove_mergee_contact
end
@base_contact
Expand All @@ -33,6 +34,10 @@ def merge_conversations
Conversation.where(contact_id: @mergee_contact.id).update(contact_id: @base_contact.id)
end

def merge_contact_notes
Note.where(contact_id: @mergee_contact.id, account_id: @mergee_contact.account_id).update(contact_id: @base_contact.id)
end

def merge_messages
Message.where(sender: @mergee_contact).update(sender: @base_contact)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/actions/contact_merge_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
create(:conversation, contact: base_contact)
create(:conversation, contact: mergee_contact)
create(:message, sender: mergee_contact)
create(:note, contact: mergee_contact, account: mergee_contact.account)
end
end

Expand Down Expand Up @@ -68,6 +69,17 @@
end
end

context 'when mergee contact has notes' do
it 'moves the notes to base contact' do
expect(base_contact.notes.count).to be 0
expect(mergee_contact.notes.count).to be 2

contact_merge

expect(base_contact.reload.notes.count).to be 2
end
end

context 'when contacts belong to a different account' do
it 'throws an exception' do
new_account = create(:account)
Expand Down

0 comments on commit a8f0539

Please sign in to comment.