feat: Add last_name and first name in widget end point
This commit is contained in:
@@ -9,7 +9,7 @@ class ContactIdentifyAction
|
||||
pattr_initialize [:contact!, :params!, { retain_original_contact_name: false, discard_invalid_attrs: false }]
|
||||
|
||||
def perform
|
||||
@attributes_to_update = [:identifier, :name, :email, :phone_number]
|
||||
@attributes_to_update = [:identifier, :name, :email, :phone_number, :middle_name, :last_name]
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
merge_if_existing_identified_contact
|
||||
|
||||
@@ -70,7 +70,7 @@ class Api::V1::Widget::ContactsController < Api::V1::Widget::BaseController
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:website_token, :identifier, :identifier_hash, :email, :name, :avatar_url, :phone_number, custom_attributes: {},
|
||||
additional_attributes: {})
|
||||
params.permit(:website_token, :identifier, :identifier_hash, :email, :name, :middle_name, :last_name, :avatar_url, :phone_number, custom_attributes: {},
|
||||
additional_attributes: {})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,3 +3,5 @@ json.name @contact.name
|
||||
json.email @contact.email
|
||||
json.phone_number @contact.phone_number
|
||||
json.identifier @contact.identifier
|
||||
json.middle_name @contact.middle_name
|
||||
json.last_name @contact.last_name
|
||||
|
||||
@@ -2,3 +2,5 @@ json.id @contact.id
|
||||
json.name @contact.name
|
||||
json.email @contact.email
|
||||
json.phone_number @contact.phone_number
|
||||
json.middle_name @contact.middle_name
|
||||
json.last_name @contact.last_name
|
||||
|
||||
@@ -3,7 +3,10 @@ require 'rails_helper'
|
||||
RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:web_widget) { create(:channel_widget, account: account) }
|
||||
let(:contact) { create(:contact, account: account, email: 'test@test.com', phone_number: '+745623239') }
|
||||
let(:contact) do
|
||||
create(:contact, account: account, email: 'test@test.com', phone_number: '+745623239', name: 'emiley', middle_name: 'grace',
|
||||
last_name: 'thompson')
|
||||
end
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
@@ -81,6 +84,16 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
expect(body['email']).to eq('test-1@test.com')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'update last name if valid last name passed' do
|
||||
patch '/api/v1/widget/contact',
|
||||
params: params.merge({ last_name: 'thompson-1' }),
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = response.parsed_body
|
||||
expect(body['last_name']).to eq('thompson-1')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user