Ignore case from input email (#424)

This commit is contained in:
Pranav Raj S 2020-01-13 14:25:23 +05:30 committed by Sojan Jose
parent 7cf19e0b52
commit 18bf1a9e62
2 changed files with 23 additions and 4 deletions

View file

@ -15,8 +15,8 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
end end
def update def update
@message.update!(input_submitted_email: permitted_params[:contact][:email]) @message.update!(input_submitted_email: contact_email)
update_contact(permitted_params[:contact][:email]) update_contact(contact_email)
head :no_content head :no_content
rescue StandardError => e rescue StandardError => e
render json: { error: @contact.errors, message: e.message }.to_json, status: 500 render json: { error: @contact.errors, message: e.message }.to_json, status: 500
@ -88,14 +88,18 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
::ContactMergeAction.new(account: @account, base_contact: contact_with_email, mergee_contact: @contact).perform ::ContactMergeAction.new(account: @account, base_contact: contact_with_email, mergee_contact: @contact).perform
else else
@contact.update!( @contact.update!(
email: permitted_params[:contact][:email], email: email,
name: contact_name name: contact_name
) )
end end
end end
def contact_email
permitted_params[:contact][:email].downcase
end
def contact_name def contact_name
permitted_params[:contact][:email].split('@')[0] contact_email.split('@')[0]
end end
def permitted_params def permitted_params

View file

@ -79,6 +79,21 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
message.reload message.reload
expect { contact.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { contact.reload }.to raise_error(ActiveRecord::RecordNotFound)
end end
it 'ignores the casing of email, updates message in conversation and deletes the current contact' do
message = create(:message, account: account, inbox: web_widget.inbox, conversation: conversation)
email = Faker::Internet.email
create(:contact, account: account, email: email)
contact_params = { email: email.upcase }
put api_v1_widget_message_url(message.id),
params: { website_token: web_widget.website_token, contact: contact_params },
headers: { 'X-Auth-Token' => token },
as: :json
expect(response).to have_http_status(:success)
message.reload
expect { contact.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end end
end end
end end