Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
94 lines
3.2 KiB
Ruby
94 lines
3.2 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) do
|
|
create(:contact, identifier: 'base_contact', email: 'old@old.com', phone_number: '', custom_attributes: { val_test: 'old', val_empty_old: '' },
|
|
account: account)
|
|
end
|
|
let!(:mergee_contact) do
|
|
create(:contact, identifier: '', email: 'new@new.com', phone_number: '+12212345',
|
|
custom_attributes: { val_test: 'new', val_new: 'new', val_empty_new: '' }, account: account)
|
|
end
|
|
|
|
before do
|
|
2.times.each do
|
|
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
|
|
|
|
describe '#perform' do
|
|
it 'deletes mergee_contact' do
|
|
contact_merge
|
|
expect { mergee_contact.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
end
|
|
|
|
it 'copies information from mergee contact to base contact' do
|
|
contact_merge
|
|
base_contact.reload
|
|
expect(base_contact.identifier).to eq('base_contact')
|
|
expect(base_contact.email).to eq('old@old.com')
|
|
expect(base_contact.phone_number).to eq('+12212345')
|
|
expect(base_contact.custom_attributes['val_test']).to eq('old')
|
|
expect(base_contact.custom_attributes['val_new']).to eq('new')
|
|
expect(base_contact.custom_attributes['val_empty_old']).to eq('')
|
|
expect(base_contact.custom_attributes['val_empty_new']).to eq('')
|
|
end
|
|
|
|
context 'when base contact and merge contact are same' do
|
|
it 'does not delete contact' do
|
|
mergee_contact = base_contact
|
|
contact_merge
|
|
expect(mergee_contact.reload).not_to be_nil
|
|
end
|
|
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 mergee contact has messages' do
|
|
it 'moves the messages to base contact' do
|
|
contact_merge
|
|
expect(base_contact.messages.count).to be 2
|
|
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)
|
|
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
|