Feature: Contact Merge Action (#378)

This commit is contained in:
Sojan Jose
2019-12-24 13:27:25 +05:30
committed by Pranav Raj S
parent 32efe8676f
commit 7d85f2e046
13 changed files with 198 additions and 35 deletions

View File

@@ -0,0 +1,47 @@
require 'rails_helper'
describe ::ContactMergeAction do
subject(:contact_merge) { described_class.new(account: account, base_contact: base_contact, mergee_contact: mergee_contact).perform }
let!(:account) { create(:account) }
let!(:base_contact) { create(:contact, account: account) }
let!(:mergee_contact) { create(:contact, account: account) }
before do
2.times.each { create(:conversation, contact: base_contact) }
2.times.each { create(:contact_inbox, contact: base_contact) }
2.times.each { create(:conversation, contact: mergee_contact) }
2.times.each { create(:contact_inbox, contact: mergee_contact) }
end
describe '#perform' do
it 'deletes mergee_contact' do
contact_merge
expect { mergee_contact.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
context 'when mergee contact has conversations' do
it 'moves the conversations to base contact' do
contact_merge
expect(base_contact.conversations.count).to be 4
end
end
context 'when mergee contact has contact inboxes' do
it 'moves the contact inboxes to base contact' do
contact_merge
expect(base_contact.contact_inboxes.count).to be 4
end
end
context 'when contacts belong to a different account' do
it 'throws an exception' do
new_account = create(:account)
expect do
described_class.new(account: new_account, base_contact: base_contact,
mergee_contact: mergee_contact).perform
end .to raise_error('contact does not belong to the account')
end
end
end
end