diff --git a/app/drops/contact_drop.rb b/app/drops/contact_drop.rb index d716b71b8..140e37e4c 100644 --- a/app/drops/contact_drop.rb +++ b/app/drops/contact_drop.rb @@ -6,4 +6,12 @@ class ContactDrop < BaseDrop def phone_number @obj.try(:phone_number) end + + def first_name + @obj.try(:name).try(:split, ' ').try(:first) + end + + def last_name + @obj.try(:name).try(:split, ' ').try(:last) if @obj.try(:name).try(:split, ' ').try(:size) > 1 + end end diff --git a/spec/models/concerns/liquidable_shared.rb b/spec/models/concerns/liquidable_shared.rb index d11b7e559..178be99e1 100644 --- a/spec/models/concerns/liquidable_shared.rb +++ b/spec/models/concerns/liquidable_shared.rb @@ -41,6 +41,26 @@ shared_examples_for 'liqudable' do message.save! expect(message.content).to eq 'hey john how are you? ``` code: {{contact.name}} ``` ``` code: {{contact.name}} ``` test' end + + it 'will extract first name from contact name' do + message.content = 'hey {{contact.first_name}} how are you?' + message.save! + expect(message.content).to eq 'hey john how are you?' + end + + it 'return empty last name when value is not available' do + message.content = 'hey {{contact.last_name}} how are you?' + message.save! + expect(message.content).to eq 'hey how are you?' + end + + it 'will extract first name and last name from contact name' do + contact.name = 'john doe' + contact.save! + message.content = 'hey {{contact.first_name}} {{contact.last_name}} how are you?' + message.save! + expect(message.content).to eq 'hey john doe how are you?' + end end end end