Chatwoot/spec/actions/contact_merge_action_spec.rb
Sojan Jose 722f540b03 [Feature] Email collect message hooks (#331)
- Add email collect hook on creating conversation
- Merge contact if it already exist
2020-01-09 13:06:40 +05:30

45 lines
1.5 KiB
Ruby

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(:conversation, 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