feat: Add additional attributes in setUser method (#3958)

This commit is contained in:
Muhsin Keloth
2022-02-28 12:10:55 +05:30
committed by GitHub
parent 9b615f11f1
commit 46c1734ba1
4 changed files with 55 additions and 10 deletions

View File

@@ -6,7 +6,10 @@ describe ::ContactIdentifyAction do
let!(:account) { create(:account) }
let(:custom_attributes) { { test: 'test', test1: 'test1' } }
let!(:contact) { create(:contact, account: account, custom_attributes: custom_attributes) }
let(:params) { { name: 'test', identifier: 'test_id', custom_attributes: { test: 'new test', test2: 'test2' } } }
let(:params) do
{ name: 'test', identifier: 'test_id', additional_attributes: { location: 'Bengaulru', company_name: 'Meta' },
custom_attributes: { test: 'new test', test2: 'test2' } }
end
describe '#perform' do
it 'updates the contact' do
@@ -15,9 +18,18 @@ describe ::ContactIdentifyAction do
expect(contact.reload.name).to eq 'test'
# custom attributes are merged properly without overwriting existing ones
expect(contact.custom_attributes).to eq({ 'test' => 'new test', 'test1' => 'test1', 'test2' => 'test2' })
expect(contact.additional_attributes).to eq({ 'company_name' => 'Meta', 'location' => 'Bengaulru' })
expect(contact.reload.identifier).to eq 'test_id'
end
it 'merge deeply nested additional attributes' do
create(:contact, account: account, identifier: '', email: 'test@test.com',
additional_attributes: { location: 'Bengaulru', company_name: 'Meta', social_profiles: { linkedin: 'saras' } })
params = { email: 'test@test.com', additional_attributes: { social_profiles: { twitter: 'saras' } } }
result = described_class.new(contact: contact, params: params).perform
expect(result.additional_attributes['social_profiles']).to eq({ 'linkedin' => 'saras', 'twitter' => 'saras' })
end
it 'enques avatar job when avatar url parameter is passed' do
params = { name: 'test', avatar_url: 'https://chatwoot-assets.local/sample.png' }
expect(ContactAvatarJob).to receive(:perform_later).with(contact, params[:avatar_url]).once